macro_metavars_in_unsafe
does not lint "without a statement". · Issue #13219 · rust-lang/rust-clippy (original) (raw)
Summary
The current existing tests all have statements.
Lint Name
macro_metavars_in_unsafe
Reproducer
I tried this code:
#[macro_export] macro_rules! m { ($e:expr) => { unsafe { $e } }; }
pub fn f(p: *const i32) -> i32 { m!(*p) }
I expected to see this happen: Lint emitted.
Instead, this happened: No lint emitted.
However, this will correctly lint:
#[macro_export] macro_rules! m { ($e:expr) => { unsafe { $e } }; }
pub fn f(p: *const i32) -> i32 { m!(*p); 42 }
This will correctly lint as well:
#[macro_export] macro_rules! m { ($e:expr) => { unsafe { $e; } // Notice the semicolon. }; }
pub fn f(p: *const i32) -> i32 { m!(return *p) }
But if we remove the semicolon, it will again incorrectly not lint:
#[macro_export] macro_rules! m { ($e:expr) => { unsafe { $e } // Now gone. }; }
pub fn f(p: *const i32) -> i32 { m!(return *p) }
Version
Reproduced with Rust 1.80.0 and nightly (rustc 1.82.0-nightly (64ebd39da 2024-08-03)
).
Cc: @y21