rust-lang / rust-lang/rust-clippy
`mismatched_target_os` false negative when using the `cfg` macro instead of the attribute.
Open
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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