Skip to content

Commit 254c6ec

Browse files
committed
fix: Use ROOT hygiene for args inside new format_args! expansion
1 parent ab9e7bd commit 254c6ec

File tree

3 files changed

+36
-27
lines changed

3 files changed

+36
-27
lines changed

crates/hir-def/src/expr_store/lower.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2825,14 +2825,7 @@ impl ExprCollector<'_> {
28252825
let use_format_args_since_1_89_0 = fmt_args().is_some() && fmt_unsafe_arg().is_none();
28262826

28272827
let idx = if use_format_args_since_1_89_0 {
2828-
self.collect_format_args_impl(
2829-
syntax_ptr,
2830-
fmt,
2831-
hygiene,
2832-
argmap,
2833-
lit_pieces,
2834-
format_options,
2835-
)
2828+
self.collect_format_args_impl(syntax_ptr, fmt, argmap, lit_pieces, format_options)
28362829
} else {
28372830
self.collect_format_args_before_1_89_0_impl(
28382831
syntax_ptr,
@@ -2962,7 +2955,6 @@ impl ExprCollector<'_> {
29622955
&mut self,
29632956
syntax_ptr: AstPtr<ast::Expr>,
29642957
fmt: FormatArgs,
2965-
hygiene: HygieneId,
29662958
argmap: FxIndexSet<(usize, ArgumentType)>,
29672959
lit_pieces: ExprId,
29682960
format_options: ExprId,
@@ -2997,8 +2989,11 @@ impl ExprCollector<'_> {
29972989
let args =
29982990
self.alloc_expr_desugared(Expr::Array(Array::ElementList { elements: args }));
29992991
let args_name = Name::new_symbol_root(sym::args);
3000-
let args_binding =
3001-
self.alloc_binding(args_name.clone(), BindingAnnotation::Unannotated, hygiene);
2992+
let args_binding = self.alloc_binding(
2993+
args_name.clone(),
2994+
BindingAnnotation::Unannotated,
2995+
HygieneId::ROOT,
2996+
);
30022997
let args_pat = self.alloc_pat_desugared(Pat::Bind { id: args_binding, subpat: None });
30032998
self.add_definition_to_binding(args_binding, args_pat);
30042999
// TODO: We don't have `super let` yet.
@@ -3008,13 +3003,16 @@ impl ExprCollector<'_> {
30083003
initializer: Some(args),
30093004
else_branch: None,
30103005
};
3011-
(vec![let_stmt], self.alloc_expr_desugared(Expr::Path(Path::from(args_name))))
3006+
(vec![let_stmt], self.alloc_expr_desugared(Expr::Path(args_name.into())))
30123007
} else {
30133008
// Generate:
30143009
// super let args = (&arg0, &arg1, &...);
30153010
let args_name = Name::new_symbol_root(sym::args);
3016-
let args_binding =
3017-
self.alloc_binding(args_name.clone(), BindingAnnotation::Unannotated, hygiene);
3011+
let args_binding = self.alloc_binding(
3012+
args_name.clone(),
3013+
BindingAnnotation::Unannotated,
3014+
HygieneId::ROOT,
3015+
);
30183016
let args_pat = self.alloc_pat_desugared(Pat::Bind { id: args_binding, subpat: None });
30193017
self.add_definition_to_binding(args_binding, args_pat);
30203018
let elements = arguments
@@ -3057,8 +3055,11 @@ impl ExprCollector<'_> {
30573055
.collect();
30583056
let array =
30593057
self.alloc_expr_desugared(Expr::Array(Array::ElementList { elements: args }));
3060-
let args_binding =
3061-
self.alloc_binding(args_name.clone(), BindingAnnotation::Unannotated, hygiene);
3058+
let args_binding = self.alloc_binding(
3059+
args_name.clone(),
3060+
BindingAnnotation::Unannotated,
3061+
HygieneId::ROOT,
3062+
);
30623063
let args_pat = self.alloc_pat_desugared(Pat::Bind { id: args_binding, subpat: None });
30633064
self.add_definition_to_binding(args_binding, args_pat);
30643065
let let_stmt2 = Statement::Let {

crates/hir-ty/src/mir/eval/tests.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,3 +984,17 @@ fn main<'a, T: Foo + Bar + Baz>(
984984
|e| matches!(e, MirEvalError::MirLowerError(_, MirLowerError::GenericArgNotProvided(..))),
985985
);
986986
}
987+
988+
#[test]
989+
fn format_args_pass() {
990+
check_pass(
991+
r#"
992+
//- minicore: fmt
993+
fn main() {
994+
let x1 = format_args!("");
995+
let x2 = format_args!("{}", x1);
996+
let x3 = format_args!("{} {}", x1, x2);
997+
}
998+
"#,
999+
);
1000+
}

crates/ide-assists/src/handlers/term_search.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ fn f() { let a: u128 = 1; let b: u128 = todo$0!() }"#,
100100
fn test_complete_todo_with_msg() {
101101
check_assist(
102102
term_search,
103-
// FIXME: Since we are lacking of `super let`, term search fails due to borrowck failure.
104-
// Should implement super let and remove `fmt_before_1_89_0`
105-
r#"//- minicore: todo, unimplemented, fmt_before_1_89_0
103+
r#"//- minicore: todo, unimplemented
106104
fn f() { let a: u128 = 1; let b: u128 = todo$0!("asd") }"#,
107105
r#"fn f() { let a: u128 = 1; let b: u128 = a }"#,
108106
)
@@ -112,10 +110,8 @@ fn f() { let a: u128 = 1; let b: u128 = todo$0!("asd") }"#,
112110
fn test_complete_unimplemented_with_msg() {
113111
check_assist(
114112
term_search,
115-
// FIXME: Since we are lacking of `super let`, term search fails due to borrowck failure.
116-
// Should implement super let and remove `fmt_before_1_89_0`
117-
r#"//- minicore: todo, unimplemented, fmt_before_1_89_0
118-
fn f() { let a: u128 = 1; let b: u128 = todo$0!("asd") }"#,
113+
r#"//- minicore: todo, unimplemented
114+
fn f() { let a: u128 = 1; let b: u128 = unimplemented$0!("asd") }"#,
119115
r#"fn f() { let a: u128 = 1; let b: u128 = a }"#,
120116
)
121117
}
@@ -124,10 +120,8 @@ fn f() { let a: u128 = 1; let b: u128 = todo$0!("asd") }"#,
124120
fn test_complete_unimplemented() {
125121
check_assist(
126122
term_search,
127-
// FIXME: Since we are lacking of `super let`, term search fails due to borrowck failure.
128-
// Should implement super let and remove `fmt_before_1_89_0`
129-
r#"//- minicore: todo, unimplemented, fmt_before_1_89_0
130-
fn f() { let a: u128 = 1; let b: u128 = todo$0!("asd") }"#,
123+
r#"//- minicore: todo, unimplemented
124+
fn f() { let a: u128 = 1; let b: u128 = unimplemented$0!() }"#,
131125
r#"fn f() { let a: u128 = 1; let b: u128 = a }"#,
132126
)
133127
}

0 commit comments

Comments
 (0)