Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing unsafe block for the nightly change #10032

Merged
merged 1 commit into from
Aug 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions crates/hir_expand/src/builtin_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine, we don't go out of our way to support older Rust versions.

// stable rust-src.
unsafe {
std::fmt::Arguments::new_v1(&[], &[##arg_tts])
}
};
ExpandResult::ok(expanded)
}
Expand Down Expand Up @@ -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),])}"#
]],
);
}
Expand All @@ -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),])}"#
]],
);
}
Expand Down