-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Uplift MaybeUninit::uninit().assume_init()
lint from clippy
#75968
Comments
Even the |
Ideally once there's a complete confidence that there's no false positives, we upgrade the deny by default into either a hard error, or maybe into an instant runtime panic. But that might be a controversial step? |
We already have a lint for this:
That's not true. Any |
This comment has been minimized.
This comment has been minimized.
Fair point on unions and zsts |
Ouch, that was silly of me... we actually have two things that try to guard against such bugs, a lint and runtime panics. However, the runtime panics only apply to So regarding the lint, I think it is in a pretty good shape already. The one thing it does not do is warn about uninitialized integers, raw pointers and floats. The reason for this is that rust-lang/unsafe-code-guidelines#71 is still open, so I didn't feel like we should already assert that uninit ints are UB when the lang team has not firmly made that decision yet. If there are any other cases of |
@Lokathor what is the actionable part of this issue? As I said above, we already have such a lint in rustc, and I'd be happy to improve it given examples where it should fire but does not. It also warns about some cases that are okay with the current rustc layout strategy but not if that ever changes, like enum Univariant {
V(MaybeUninit<bool>)
} I wanted to be conservative when adding the lint and not turn these into errors, but if T-lang is on board I would be fine with triggering the lint for all enums. |
Well, alright then. |
Using
MaybeUninit::uninit().assume_init()
is instant UB unless the target type is itself composed entirely of MaybeUninit (eg:[MaybeUninit<u8>; 10]
, or similar).It's also the most common thing for a person to try when using MaybeUninit for the first time. I don't think that Rust has any footgun bigger than this single expression.
Clippy has a lint against this, and the lint needs to be uplifted into the compiler.
Essentially the lint is: if the target type of this expression isn't itself some sort of MaybeUninit, then deny by default.
The text was updated successfully, but these errors were encountered: