-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Lints about unsafe {}
blocks propagate inside macros
#74838
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
It is expected behavior that |
I think the fix for this would be something like "unsafety hygiene". I am not sure if that is on the roadmap, but it is probably not backwards compatible so it could be done only for |
Unsafety hygiene would be the "next step", but to start I would just want to not warn about unsafe inside macros if they're already in an unsafe context -- that seems reasonable. I imagine that would be backwards compatible? We could also just silence "unused_unsafe" entirely inside macros, I guess, which would be easier. |
i think this was fixed by #100081 |
delete [allow(unused_unsafe)] from issue rust-lang#74838 While looking into issue rust-lang#111288 I noticed the following `#[allow(...)]` with a `FIXME` asking for it to be removed. Deleting the `#[allow(...)]` does not seem to break anything, it seems like the lint has been updated for unsafe blocks in macros?
current output (nightly 1.74.0 2023-09-26): macro_rules! spooky_macro {
() => {
unsafe { core::mem::zeroed::<u32>() }
};
}
fn main() {
// case 1: warning: unnecessary `unsafe` block
unsafe {
let _: [u8; 4] = core::mem::transmute(spooky_macro!());
}
}
pub unsafe fn spooky_fn() {
// case 2: Fixed! No warning.
let _: [u8; 4] = core::mem::transmute(spooky_macro!());
} So yes, since this issue was specifically filed about case 2, you could consider it fixed. There are two other issues about the same kind of problem: #49112 and #94912 |
Coming from #74200.
I used
#![deny(unsafe_op_in_unsafe_fn)]
instd/panicking.rs
. This raised an error about a missingunsafe {}
block instd/thread/local.rs
. Adding it raised a warning about extraneousunsafe {}
in other parts of the code. This forced me to use#[allow(unused_unsafe)]
.It was noted that lints like those (whatever those is) should maybe not propagate inside macros.
cc @Mark-Simulacrum who raised the point in the first place
The text was updated successfully, but these errors were encountered: