Skip to content

Commit 21319d1

Browse files
committed
Auto merge of rust-lang#13329 - Veykril:rustc-proc-macro, r=Veykril
Use $crate instead of std for panic builtin_fn_macro This should be closer to the expected output and gets rid of a few type mismatches in rustc/library
2 parents 99c205c + 1574fe0 commit 21319d1

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ macro_rules! option_env {() => {}}
9393
9494
fn main() { option_env!("TEST_ENV_VAR"); }
9595
"#,
96-
expect![[r##"
96+
expect![[r#"
9797
#[rustc_builtin_macro]
9898
macro_rules! option_env {() => {}}
9999
100-
fn main() { std::option::Option::None:: < &str>; }
101-
"##]],
100+
fn main() { $crate::option::Option::None:: < &str>; }
101+
"#]],
102102
);
103103
}
104104

@@ -191,17 +191,17 @@ fn main() {
191191
format_args!("{} {:?}", arg1(a, b, c), arg2);
192192
}
193193
"#,
194-
expect![[r##"
194+
expect![[r#"
195195
#[rustc_builtin_macro]
196196
macro_rules! format_args {
197197
($fmt:expr) => ({ /* compiler built-in */ });
198198
($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ })
199199
}
200200
201201
fn main() {
202-
std::fmt::Arguments::new_v1(&[], &[std::fmt::ArgumentV1::new(&(arg1(a, b, c)), std::fmt::Display::fmt), std::fmt::ArgumentV1::new(&(arg2), std::fmt::Display::fmt), ]);
202+
$crate::fmt::Arguments::new_v1(&[], &[$crate::fmt::ArgumentV1::new(&(arg1(a, b, c)), $crate::fmt::Display::fmt), $crate::fmt::ArgumentV1::new(&(arg2), $crate::fmt::Display::fmt), ]);
203203
}
204-
"##]],
204+
"#]],
205205
);
206206
}
207207

@@ -219,17 +219,17 @@ fn main() {
219219
format_args!("{} {:?}", a::<A,B>(), b);
220220
}
221221
"#,
222-
expect![[r##"
222+
expect![[r#"
223223
#[rustc_builtin_macro]
224224
macro_rules! format_args {
225225
($fmt:expr) => ({ /* compiler built-in */ });
226226
($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ })
227227
}
228228
229229
fn main() {
230-
std::fmt::Arguments::new_v1(&[], &[std::fmt::ArgumentV1::new(&(a::<A, B>()), std::fmt::Display::fmt), std::fmt::ArgumentV1::new(&(b), std::fmt::Display::fmt), ]);
230+
$crate::fmt::Arguments::new_v1(&[], &[$crate::fmt::ArgumentV1::new(&(a::<A, B>()), $crate::fmt::Display::fmt), $crate::fmt::ArgumentV1::new(&(b), $crate::fmt::Display::fmt), ]);
231231
}
232-
"##]],
232+
"#]],
233233
);
234234
}
235235

@@ -248,7 +248,7 @@ fn main() {
248248
format_args!/*+errors*/("{} {:?}", a.);
249249
}
250250
"#,
251-
expect![[r##"
251+
expect![[r#"
252252
#[rustc_builtin_macro]
253253
macro_rules! format_args {
254254
($fmt:expr) => ({ /* compiler built-in */ });
@@ -258,9 +258,9 @@ macro_rules! format_args {
258258
fn main() {
259259
let _ =
260260
/* parse error: expected field name or number */
261-
std::fmt::Arguments::new_v1(&[], &[std::fmt::ArgumentV1::new(&(a.), std::fmt::Display::fmt), ]);
261+
$crate::fmt::Arguments::new_v1(&[], &[$crate::fmt::ArgumentV1::new(&(a.), $crate::fmt::Display::fmt), ]);
262262
}
263-
"##]],
263+
"#]],
264264
);
265265
}
266266

crates/hir-expand/src/builtin_fn_macro.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ fn format_args_expand(
238238
) -> ExpandResult<tt::Subtree> {
239239
// We expand `format_args!("", a1, a2)` to
240240
// ```
241-
// std::fmt::Arguments::new_v1(&[], &[
242-
// std::fmt::ArgumentV1::new(&arg1,std::fmt::Display::fmt),
243-
// std::fmt::ArgumentV1::new(&arg2,std::fmt::Display::fmt),
241+
// $crate::fmt::Arguments::new_v1(&[], &[
242+
// $crate::fmt::ArgumentV1::new(&arg1,$crate::fmt::Display::fmt),
243+
// $crate::fmt::ArgumentV1::new(&arg2,$crate::fmt::Display::fmt),
244244
// ])
245245
// ```,
246246
// which is still not really correct, but close enough for now
@@ -262,10 +262,10 @@ fn format_args_expand(
262262
}
263263
let _format_string = args.remove(0);
264264
let arg_tts = args.into_iter().flat_map(|arg| {
265-
quote! { std::fmt::ArgumentV1::new(&(#arg), std::fmt::Display::fmt), }
265+
quote! { #DOLLAR_CRATE::fmt::ArgumentV1::new(&(#arg), #DOLLAR_CRATE::fmt::Display::fmt), }
266266
}.token_trees);
267267
let expanded = quote! {
268-
std::fmt::Arguments::new_v1(&[], &[##arg_tts])
268+
#DOLLAR_CRATE::fmt::Arguments::new_v1(&[], &[##arg_tts])
269269
};
270270
ExpandResult::ok(expanded)
271271
}
@@ -675,8 +675,8 @@ fn option_env_expand(
675675
};
676676

677677
let expanded = match get_env_inner(db, arg_id, &key) {
678-
None => quote! { std::option::Option::None::<&str> },
679-
Some(s) => quote! { std::option::Some(#s) },
678+
None => quote! { #DOLLAR_CRATE::option::Option::None::<&str> },
679+
Some(s) => quote! { #DOLLAR_CRATE::option::Some(#s) },
680680
};
681681

682682
ExpandResult::ok(ExpandedEager::new(expanded))

0 commit comments

Comments
 (0)