Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2ff9bab

Browse files
committed
fix: Fix format_args lowering passing incorrect parameters to rustc_parse_format
1 parent9f4b651 commit2ff9bab

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

‎src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use syntax::{
1717
self,ArrayExprKind,AstChildren,BlockExpr,HasArgList,HasAttrs,HasLoopBody,HasName,
1818
RangeItem,SlicePatComponents,
1919
},
20-
AstNode,AstPtr,SyntaxNodePtr,
20+
AstNode,AstPtr,AstTokenas _,SyntaxNodePtr,
2121
};
2222
use triomphe::Arc;
2323

@@ -1577,7 +1577,13 @@ impl ExprCollector<'_> {
15771577
});
15781578
});
15791579
let template = f.template();
1580-
let fmt_snippet = template.as_ref().map(ToString::to_string);
1580+
let fmt_snippet = template.as_ref().and_then(|it|match it{
1581+
ast::Expr::Literal(literal) =>match literal.kind(){
1582+
ast::LiteralKind::String(s) =>Some(s.text().to_owned()),
1583+
_ =>None,
1584+
},
1585+
_ =>None,
1586+
});
15811587
letmut mappings =vec![];
15821588
let fmt =match template.and_then(|it|self.expand_macros_to_string(it)){
15831589
Some((s, is_direct_literal)) => format_args::parse(

‎src/tools/rust-analyzer/crates/hir-def/src/body/tests.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fn desugar_builtin_format_args() {
150150
fn main() {
151151
let are = "are";
152152
let count = 10;
153-
builtin#format_args("hello {count:02} {} friends, we {are:?} {0}{last}", "fancy", last = "!");
153+
builtin#format_args("\u{1b}hello {count:02} {} friends, we {are:?} {0}{last}", "fancy", last = "!");
154154
}
155155
"#,
156156
);
@@ -161,7 +161,7 @@ fn main() {
161161
let count = 10;
162162
builtin#lang(Arguments::new_v1_formatted)(
163163
&[
164-
"hello ", " ", " friends, we ", " ", "",
164+
"\u{1b}hello ", " ", " friends, we ", " ", "",
165165
],
166166
&[
167167
builtin#lang(Argument::new_display)(

‎src/tools/rust-analyzer/crates/hir-def/src/hir/format_args.rs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,13 @@ pub(crate) fn parse(
175175
mutsynth:implFnMut(Name) ->ExprId,
176176
mutrecord_usage:implFnMut(Name,Option<TextRange>),
177177
) ->FormatArgs{
178-
let text = s.text_without_quotes();
178+
letOk(text) = s.value()else{
179+
returnFormatArgs{
180+
template:Default::default(),
181+
arguments: args.finish(),
182+
orphans:vec![],
183+
};
184+
};
179185
let str_style =match s.quote_offsets(){
180186
Some(offsets) =>{
181187
let raw = usize::from(offsets.quotes.0.len()) -1;
@@ -186,7 +192,7 @@ pub(crate) fn parse(
186192
};
187193

188194
letmut parser =
189-
parse::Parser::new(text, str_style, fmt_snippet,false, parse::ParseMode::Format);
195+
parse::Parser::new(&text, str_style, fmt_snippet,false, parse::ParseMode::Format);
190196

191197
letmut pieces =Vec::new();
192198
whileletSome(piece) = parser.next(){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp