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

mismatched_target_os false negative when using the cfg macro instead of the attribute. #7839

Open
VZout opened this issue Oct 19, 2021 · 2 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't T-macros Type: Issues with macros and macro expansion

Comments

@VZout
Copy link

VZout commented Oct 19, 2021

Lint name: mismatched_target_os

I tried this code:

fn main() {
    // Clippy throws error
    //#[cfg(linux)]
    //println!("Hello, Linux!");

    // Clippy doesn't care
    if cfg!(linux) {
        println!("Hello, Linux!");
    }
}

I expected to see the error operating system used in target family position here like you would see if you used the attribute #[cfg(linux)]

Instead, clippy doesn't give any error.

Meta

Rust version (rustc -Vv):

rustc 1.52.1 (9bc8c42bb 2021-05-09)
binary: rustc
commit-hash: 9bc8c42bb2f19e745a63f3445f1ac248fb015e53
commit-date: 2021-05-09
host: x86_64-pc-windows-msvc
release: 1.52.1
LLVM version: 12.0.0
@VZout VZout added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Oct 19, 2021
@xFrednet xFrednet added the T-macros Type: Issues with macros and macro expansion label Oct 19, 2021
@fanzeyi
Copy link

fanzeyi commented Dec 13, 2021

Agree, I came here to report the same issue. It would be great if clippy can detect this. A very easy mistake to make :)

@fanzeyi
Copy link

fanzeyi commented Dec 14, 2021

I tried to take this on and I have a working draft. I still need to tidy up -- reducing duplicated code and write tests, but I think I got it mostly working. I will try to open a PR tomorrow night. Getting late here. :)

Preview:

image

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-negative Issue: The lint should have been triggered on code, but wasn't T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants