rust-lang / rust-lang/rust-clippy
`uninhabited_references` is very likely to be a false positive
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
The new uninhabited_reference lint complains about deferencing a reference to an infallible type, saying this is UB. But it is possible to write such code in safe Rust, which will be provably impossible to call (absent unsafe code which itself is almost certainly incorrect).
The lint purpose would be better served by linting the creation of a reference to an uninhabited type. The original issue has some discussion saying that it's maybe not UB, but it's almost certainly wrong. Versus the dereference, which is safe to write and has legitimate usecases.
At the very least, the existing lint shouldn't trigger on trait implementations.
cc #11851
Lint Name
No response
Reproducer
impl PushBytesErrorReport for core::convert::Infallible {
#[inline]
fn input_len(&self) -> usize { match *self {} }
}
triggers the lint. But this code is clearly implementing an error-related trait for Infallible, with the understanding that the trait method is impossible to call.
Version
No response
Additional Labels
No response
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 running the provided Rust reproducer and inspecting the uninhabited_reference lint’s handling of trait implementations. Read the discussion in #11851 to compare linting reference creation with dereferencing, then add regression coverage for the chosen behavior. Done means the reported false positive is avoided while the lint still catches its intended cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100