Closed as not planned
Description
Summary
It's very common to match on uninhabited types when we statically know they are uninhabited. It's a very common pattern to express that the code is known to be dead. Especially trait impls of uninhabited types. Aside from that I believe the whole lint is broken since dereferencing an uninhabited type is not UB - it cannot happen in the first place. Creating it is UB. The lint should instead disallow casting inhabited types to uninhabited (using transmute
or pointers).
Lint Name
uninhabited_references
Reproducer
I tried this code:
enum Foo {}
fn never_happens(foo: &Foo) {
match *foo {}
}
I saw this happen:
warning: dereferencing a reference to an uninhabited type is undefined behavior
--> src/lib.rs:4:11
|
4 | match *foo {}
| ^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninhabited_references
= note: `#[warn(clippy::uninhabited_references)]` on by default
I expected to see this happen: No warning
Version
rustc 1.76.0-nightly (3f28fe133 2023-12-18)
binary: rustc
commit-hash: 3f28fe133475ec5faf3413b556bf3cfb0d51336c
commit-date: 2023-12-18
host: x86_64-unknown-linux-gnu
release: 1.76.0-nightly
LLVM version: 17.0.6
Additional Labels
No response