rust-lang / rust-lang/rust-clippy

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

Open
#7,839 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-negative T-macros
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported Rust snippet with cfg!(linux) and compare it with the commented #[cfg(linux)] case. Trace the mismatched_target_os lint entry point and its existing tests, then add coverage so the macro form receives the expected diagnostic.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.