Skip to content

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

Open
@VZout

Description

@VZout

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tT-macrosType: Issues with macros and macro expansion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions