-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Macros can't hide unsafety because of unused-unsafe #8472
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
Comments
Still relevant
Produces It is possible to avoid the warning with
But not within the macro definition. |
Another workaround is to have multiple match patterns. This pattern may cause confusion since the macro_rules! foo {
(unsafe $e:expr) => {
unsafe { foo!($e) }
};
($e:expr) => {{
use std::mem;
mem::transmute($e)
}}
}
#[allow(unused_variables)]
fn main() {
let x: u32 = unsafe { foo!(1) };
let y: u32 = foo!(unsafe 1);
} |
This just works now #![feature(stmt_expr_attributes)]
macro_rules! foo(
() => {
#[allow(unused_unsafe)]
unsafe { use std::mem; let () = mem::transmute(()); }
}
);
fn main() {
unsafe { foo!(); }
foo!();
} |
Triage: This is fixed as noted above, |
…t_should_not_trigger_on_doc_hidden_items, r=flip1995 Disable ``[`new-without-default`]`` for new() methods that are marked… … with '#[doc(hidden)]' Fixes rust-lang#8152 changelog: Disable ``[`new-without-default`]`` for new() methods that are marked with `#[doc(hidden)]`
Consider the following.
This only does not emit a warning if the first line of code in main is removed. It would be nice to be able to squelch the unused unsafe warning that appears on the first invocation of
foo!()
, whether automatically or by being able to use#[allow(unused_unsafe)]
inside the macro definition.A workaround is to define a function in the macro that hides the unsafety and to call it.
The text was updated successfully, but these errors were encountered: