From 15eccf29e8eb4ee458c1c57474e2735a33cef55e Mon Sep 17 00:00:00 2001 From: oxalica Date: Thu, 26 Aug 2021 16:42:45 +0800 Subject: [PATCH] Fix missing unsafe block for the nightly change Fix #10022 --- crates/hir_expand/src/builtin_macro.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/hir_expand/src/builtin_macro.rs b/crates/hir_expand/src/builtin_macro.rs index c9149f27a9..f3bfd65987 100644 --- a/crates/hir_expand/src/builtin_macro.rs +++ b/crates/hir_expand/src/builtin_macro.rs @@ -256,7 +256,13 @@ fn format_args_expand( quote! { std::fmt::ArgumentV1::new(&(#arg), std::fmt::Display::fmt), } }.token_trees); let expanded = quote! { - std::fmt::Arguments::new_v1(&[], &[##arg_tts]) + // It's unsafe since https://github.com/rust-lang/rust/pull/83302 + // Wrap an unsafe block to avoid false-positive `missing-unsafe` lint. + // FIXME: Currently we don't have `unused_unsafe` lint so an extra unsafe block won't cause issues on early + // stable rust-src. + unsafe { + std::fmt::Arguments::new_v1(&[], &[##arg_tts]) + } }; ExpandResult::ok(expanded) } @@ -762,7 +768,7 @@ mod tests { format_args!("{} {:?}", arg1(a, b, c), arg2); "#, expect![[ - r#"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),])"# + r#"unsafe{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),])}"# ]], ); } @@ -779,7 +785,7 @@ mod tests { format_args!("{} {:?}", a::(), b); "#, expect![[ - r#"std::fmt::Arguments::new_v1(&[], &[std::fmt::ArgumentV1::new(&(a::()),std::fmt::Display::fmt),std::fmt::ArgumentV1::new(&(b),std::fmt::Display::fmt),])"# + r#"unsafe{std::fmt::Arguments::new_v1(&[], &[std::fmt::ArgumentV1::new(&(a::()),std::fmt::Display::fmt),std::fmt::ArgumentV1::new(&(b),std::fmt::Display::fmt),])}"# ]], ); }