10032: Fix missing unsafe block for the nightly change r=lnicola a=oxalica

Fix #10022

Tested via vscode extension.

Co-authored-by: oxalica <oxalicc@pm.me>
This commit is contained in:
bors[bot] 2021-08-26 09:33:12 +00:00 committed by GitHub
commit 55d4813561
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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::<A,B>(), b);
"#,
expect![[
r#"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),])"#
r#"unsafe{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),])}"#
]],
);
}