-
Notifications
You must be signed in to change notification settings - Fork 16
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
Unsafe macros and #![forbid(unsafe_code)] #2
Comments
What if just make the macro insert On the other hand, it may contradict with user intentions who use |
At first glance this seems like a rustc bug, why does |
I mean |
Which docs are you referring to? Given a crate like #[macro_export]
macro_rules! foo {
() => { loop { break; let _ = 5; } }
}
#[macro_export]
macro_rules! bar {
() => { unsafe { let _ = ::std::mem::transmute::<i32, u32>(5); } }
} and using it in another crate like use temp::{foo, bar};
pub fn baz() {
foo!();
bar!();
}
#[allow(unreachable_code)]
#[forbid(unsafe_code)]
pub fn qux() {
foo!();
bar!();
} the output is:
I would expect either both the If this is intended behaviour, then I don't know what |
Ok, testing adding
|
How is this different from linking to a crate that uses |
@Diggsey, Unsafe-wielding dependency crates may be reviewed and locked. The macro's name and documentation looks like a one of an unsafe function, yet it can be used from safe code. For example, if |
There are macros like
unsafe_unpinned!
, which are documented as unsafe and creates a safe function, but with an unsafe block inside.Does it mean that a crate under
#![forbid(unsafe_code)]
rule may circumvent the safety by linking to pin_utils? Shall those macros somehow requireunsafe{}
block or define an unsafe function?Or should entire "pin_utils" be an "unsafe crate", not directly linkable from
#![forbid(unsafe_code)]
crates?The text was updated successfully, but these errors were encountered: