Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uninhabited_references warns on common patterns like match *x {} #11985

Closed
Kixunil opened this issue Dec 19, 2023 · 1 comment
Closed

uninhabited_references warns on common patterns like match *x {} #11985

Kixunil opened this issue Dec 19, 2023 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@Kixunil
Copy link

Kixunil commented Dec 19, 2023

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

@Kixunil Kixunil added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Dec 19, 2023
@Kixunil
Copy link
Author

Kixunil commented Dec 19, 2023

Oh, this is a duplicate of #11984, I'm closing this in favor of that one.

@Kixunil Kixunil closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2023
bors added a commit that referenced this issue Dec 23, 2023
…, r=xFrednet

Move `uninhabited_references` to `nursery`

I think this lint has too many false positives and should be put in pedantic. See #11984 and #11985 for context.

The lint is already in beta and is causing trouble for us, so I would also like this PR to be backported to beta as well.

changelog: Moved [`uninhabited_references`] to `nursery` (Now allow-by-default)
[#11997](#11997)
(Check if this has been backported)

Fixes #11984.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

1 participant