-
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-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
Summary
False positive with the unnecessary_safety_comment
when the unsafe block is in a macro.
Lint Name
unnecessary_safety_comment
Reproducer
I tried this code:
#![warn(clippy::unnecessary_safety_comment)]
#![warn(clippy::undocumented_unsafe_blocks)]
unsafe fn bar() -> i32 {
42
}
macro_rules! foo {
() => {
// SAFETY: This is safe
unsafe { bar() }
};
}
fn main() {
foo!();
}
I saw this happen:
warning: expression has unnecessary safety comment
--> src/main.rs:11:18
|
11 | unsafe { bar() }
| ^^^^^
...
16 | foo!();
| ------ in this macro invocation
|
help: consider removing the safety comment
--> src/main.rs:10:9
|
10 | // SAFETY: This is safe
| ^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_safety_comment
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![warn(clippy::unnecessary_safety_comment)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
I expected to see this happen:
No warning triggered
Version
rustc 1.67.0-beta.2 (352eb59a4 2022-12-13)
binary: rustc
commit-hash: 352eb59a4c33abf739914422f2ad975925750146
commit-date: 2022-12-13
host: aarch64-apple-darwin
release: 1.67.0-beta.2
LLVM version: 15.0.6
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have