-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't
Description
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
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't