mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-29 10:58:02 +00:00
fix: Use ROOT hygiene for args inside new format_args! expansion
This commit is contained in:
parent
ab9e7bdc83
commit
254c6ec8e1
3 changed files with 36 additions and 27 deletions
|
|
@ -2825,14 +2825,7 @@ impl ExprCollector<'_> {
|
||||||
let use_format_args_since_1_89_0 = fmt_args().is_some() && fmt_unsafe_arg().is_none();
|
let use_format_args_since_1_89_0 = fmt_args().is_some() && fmt_unsafe_arg().is_none();
|
||||||
|
|
||||||
let idx = if use_format_args_since_1_89_0 {
|
let idx = if use_format_args_since_1_89_0 {
|
||||||
self.collect_format_args_impl(
|
self.collect_format_args_impl(syntax_ptr, fmt, argmap, lit_pieces, format_options)
|
||||||
syntax_ptr,
|
|
||||||
fmt,
|
|
||||||
hygiene,
|
|
||||||
argmap,
|
|
||||||
lit_pieces,
|
|
||||||
format_options,
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
self.collect_format_args_before_1_89_0_impl(
|
self.collect_format_args_before_1_89_0_impl(
|
||||||
syntax_ptr,
|
syntax_ptr,
|
||||||
|
|
@ -2962,7 +2955,6 @@ impl ExprCollector<'_> {
|
||||||
&mut self,
|
&mut self,
|
||||||
syntax_ptr: AstPtr<ast::Expr>,
|
syntax_ptr: AstPtr<ast::Expr>,
|
||||||
fmt: FormatArgs,
|
fmt: FormatArgs,
|
||||||
hygiene: HygieneId,
|
|
||||||
argmap: FxIndexSet<(usize, ArgumentType)>,
|
argmap: FxIndexSet<(usize, ArgumentType)>,
|
||||||
lit_pieces: ExprId,
|
lit_pieces: ExprId,
|
||||||
format_options: ExprId,
|
format_options: ExprId,
|
||||||
|
|
@ -2997,8 +2989,11 @@ impl ExprCollector<'_> {
|
||||||
let args =
|
let args =
|
||||||
self.alloc_expr_desugared(Expr::Array(Array::ElementList { elements: args }));
|
self.alloc_expr_desugared(Expr::Array(Array::ElementList { elements: args }));
|
||||||
let args_name = Name::new_symbol_root(sym::args);
|
let args_name = Name::new_symbol_root(sym::args);
|
||||||
let args_binding =
|
let args_binding = self.alloc_binding(
|
||||||
self.alloc_binding(args_name.clone(), BindingAnnotation::Unannotated, hygiene);
|
args_name.clone(),
|
||||||
|
BindingAnnotation::Unannotated,
|
||||||
|
HygieneId::ROOT,
|
||||||
|
);
|
||||||
let args_pat = self.alloc_pat_desugared(Pat::Bind { id: args_binding, subpat: None });
|
let args_pat = self.alloc_pat_desugared(Pat::Bind { id: args_binding, subpat: None });
|
||||||
self.add_definition_to_binding(args_binding, args_pat);
|
self.add_definition_to_binding(args_binding, args_pat);
|
||||||
// TODO: We don't have `super let` yet.
|
// TODO: We don't have `super let` yet.
|
||||||
|
|
@ -3008,13 +3003,16 @@ impl ExprCollector<'_> {
|
||||||
initializer: Some(args),
|
initializer: Some(args),
|
||||||
else_branch: None,
|
else_branch: None,
|
||||||
};
|
};
|
||||||
(vec![let_stmt], self.alloc_expr_desugared(Expr::Path(Path::from(args_name))))
|
(vec![let_stmt], self.alloc_expr_desugared(Expr::Path(args_name.into())))
|
||||||
} else {
|
} else {
|
||||||
// Generate:
|
// Generate:
|
||||||
// super let args = (&arg0, &arg1, &...);
|
// super let args = (&arg0, &arg1, &...);
|
||||||
let args_name = Name::new_symbol_root(sym::args);
|
let args_name = Name::new_symbol_root(sym::args);
|
||||||
let args_binding =
|
let args_binding = self.alloc_binding(
|
||||||
self.alloc_binding(args_name.clone(), BindingAnnotation::Unannotated, hygiene);
|
args_name.clone(),
|
||||||
|
BindingAnnotation::Unannotated,
|
||||||
|
HygieneId::ROOT,
|
||||||
|
);
|
||||||
let args_pat = self.alloc_pat_desugared(Pat::Bind { id: args_binding, subpat: None });
|
let args_pat = self.alloc_pat_desugared(Pat::Bind { id: args_binding, subpat: None });
|
||||||
self.add_definition_to_binding(args_binding, args_pat);
|
self.add_definition_to_binding(args_binding, args_pat);
|
||||||
let elements = arguments
|
let elements = arguments
|
||||||
|
|
@ -3057,8 +3055,11 @@ impl ExprCollector<'_> {
|
||||||
.collect();
|
.collect();
|
||||||
let array =
|
let array =
|
||||||
self.alloc_expr_desugared(Expr::Array(Array::ElementList { elements: args }));
|
self.alloc_expr_desugared(Expr::Array(Array::ElementList { elements: args }));
|
||||||
let args_binding =
|
let args_binding = self.alloc_binding(
|
||||||
self.alloc_binding(args_name.clone(), BindingAnnotation::Unannotated, hygiene);
|
args_name.clone(),
|
||||||
|
BindingAnnotation::Unannotated,
|
||||||
|
HygieneId::ROOT,
|
||||||
|
);
|
||||||
let args_pat = self.alloc_pat_desugared(Pat::Bind { id: args_binding, subpat: None });
|
let args_pat = self.alloc_pat_desugared(Pat::Bind { id: args_binding, subpat: None });
|
||||||
self.add_definition_to_binding(args_binding, args_pat);
|
self.add_definition_to_binding(args_binding, args_pat);
|
||||||
let let_stmt2 = Statement::Let {
|
let let_stmt2 = Statement::Let {
|
||||||
|
|
|
||||||
|
|
@ -984,3 +984,17 @@ fn main<'a, T: Foo + Bar + Baz>(
|
||||||
|e| matches!(e, MirEvalError::MirLowerError(_, MirLowerError::GenericArgNotProvided(..))),
|
|e| matches!(e, MirEvalError::MirLowerError(_, MirLowerError::GenericArgNotProvided(..))),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn format_args_pass() {
|
||||||
|
check_pass(
|
||||||
|
r#"
|
||||||
|
//- minicore: fmt
|
||||||
|
fn main() {
|
||||||
|
let x1 = format_args!("");
|
||||||
|
let x2 = format_args!("{}", x1);
|
||||||
|
let x3 = format_args!("{} {}", x1, x2);
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -100,9 +100,7 @@ fn f() { let a: u128 = 1; let b: u128 = todo$0!() }"#,
|
||||||
fn test_complete_todo_with_msg() {
|
fn test_complete_todo_with_msg() {
|
||||||
check_assist(
|
check_assist(
|
||||||
term_search,
|
term_search,
|
||||||
// FIXME: Since we are lacking of `super let`, term search fails due to borrowck failure.
|
r#"//- minicore: todo, unimplemented
|
||||||
// Should implement super let and remove `fmt_before_1_89_0`
|
|
||||||
r#"//- minicore: todo, unimplemented, fmt_before_1_89_0
|
|
||||||
fn f() { let a: u128 = 1; let b: u128 = todo$0!("asd") }"#,
|
fn f() { let a: u128 = 1; let b: u128 = todo$0!("asd") }"#,
|
||||||
r#"fn f() { let a: u128 = 1; let b: u128 = a }"#,
|
r#"fn f() { let a: u128 = 1; let b: u128 = a }"#,
|
||||||
)
|
)
|
||||||
|
|
@ -112,10 +110,8 @@ fn f() { let a: u128 = 1; let b: u128 = todo$0!("asd") }"#,
|
||||||
fn test_complete_unimplemented_with_msg() {
|
fn test_complete_unimplemented_with_msg() {
|
||||||
check_assist(
|
check_assist(
|
||||||
term_search,
|
term_search,
|
||||||
// FIXME: Since we are lacking of `super let`, term search fails due to borrowck failure.
|
r#"//- minicore: todo, unimplemented
|
||||||
// Should implement super let and remove `fmt_before_1_89_0`
|
fn f() { let a: u128 = 1; let b: u128 = unimplemented$0!("asd") }"#,
|
||||||
r#"//- minicore: todo, unimplemented, fmt_before_1_89_0
|
|
||||||
fn f() { let a: u128 = 1; let b: u128 = todo$0!("asd") }"#,
|
|
||||||
r#"fn f() { let a: u128 = 1; let b: u128 = a }"#,
|
r#"fn f() { let a: u128 = 1; let b: u128 = a }"#,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -124,10 +120,8 @@ fn f() { let a: u128 = 1; let b: u128 = todo$0!("asd") }"#,
|
||||||
fn test_complete_unimplemented() {
|
fn test_complete_unimplemented() {
|
||||||
check_assist(
|
check_assist(
|
||||||
term_search,
|
term_search,
|
||||||
// FIXME: Since we are lacking of `super let`, term search fails due to borrowck failure.
|
r#"//- minicore: todo, unimplemented
|
||||||
// Should implement super let and remove `fmt_before_1_89_0`
|
fn f() { let a: u128 = 1; let b: u128 = unimplemented$0!() }"#,
|
||||||
r#"//- minicore: todo, unimplemented, fmt_before_1_89_0
|
|
||||||
fn f() { let a: u128 = 1; let b: u128 = todo$0!("asd") }"#,
|
|
||||||
r#"fn f() { let a: u128 = 1; let b: u128 = a }"#,
|
r#"fn f() { let a: u128 = 1; let b: u128 = a }"#,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue