Skip to content
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

unnecessary_safety_comment false positive in macro #10084

Closed
CeleritasCelery opened this issue Dec 15, 2022 · 0 comments · Fixed by #10106
Closed

unnecessary_safety_comment false positive in macro #10084

CeleritasCelery opened this issue Dec 15, 2022 · 0 comments · Fixed by #10106
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@CeleritasCelery
Copy link
Contributor

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

@CeleritasCelery CeleritasCelery added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Dec 15, 2022
@bors bors closed this as completed in a9c251f Jan 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant