-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
assign to part of possibly uninitialized variable is flagged as UB (but only in 2018 edition) #60450
Comments
Nothing here says there is any UB. This is just about whether the type-checker accepts this program. We reject plenty of non-UB programs. If I grep for that error in the tests, the hits are all in the "borrowck" directory. That would also explain the edition difference; the error likely comes from NLL. |
This is just something that NLL chose not to support because the fields can't ever be read (for now). The message isn't particularly great though. |
It says "potential UB" right in the error message. But if as you say it's not UB, then I don't think we should be breaking existing code for it. |
cc #54987. This was discussed in depth by the language team with decision recorded in #21232 (comment). Accepting this would be completely useless at the moment as you cannot use the field (as @matthewjasper notes). I think we should therefore convert this into a hard error on both editions and eventually perhaps accept gradual initialization of structs but a sane variant of that (e.g. taking definitive initialization and uninhabitedness into account). |
(as mentioned in my edit of the issue description) It's not "completely useless", I am in fact using this today with inline assembly (which is how I ran into this issue): https://github.com/fortanix/rust-sgx/blob/886d08d/enclave-runner/src/tcs.rs#L99. With inline assembly you sometimes have to specify an output variable even if you're going to do nothing with the result.
To be clear the decision was to "tentatively decided to attempt, for the short-term ..." which sounds much less definitive. |
@jethrogb Since I'm not familiar with what you are doing... Is there a reason you cannot just
This refers to the implementation effort (note attempt -- it was attempted successfully). |
The only reason I brought up my example was just to point out that it's not completely useless. I can work around this by just creating two uninitialized bindings instead, which I didn't do before because it's an additional useless line of code. I'm not particularly bothered about needing to make such a change, especially since it only concerns inline assembly. I'm more bothered by the messaging involved. |
Fair enough; It's quite a niche use case (unlike gradual initialization in general) and as you say you can do it through other, and in my view clearer, ways. |
oops I missed that, sorry. |
137: Fix warning that appeared in latest nightly r=jseyfried a=jethrogb See rust-lang/rust#60450 Co-authored-by: Jethro Beekman <[email protected]>
Since NLL on 2015 edition has now landed, what should the timeline look like for transitioning this to a hard error? |
@tmandry If you can separate this from the other NLL error-downgrades I would welcome making it a hard error right away. Otherwise you'll have to wait for all the NLL error-downgrades to be removed. |
This is one of the behaviors we no longer allow in NLL. Since it can lead to undefined behavior, I think it's definitely worth making it a hard error without waiting to turn off migration mode (rust-lang#58781). Closes rust-lang#60450. My ulterior motive here is making it impossible to leave variables partially initialized across a yield (see discussion at rust-lang#63035), so tests are included for that.
…ized, r=Centril Make use of possibly uninitialized data [E0381] a hard error This is one of the behaviors we no longer allow in NLL. Since it can lead to undefined behavior, I think it's definitely worth making it a hard error without waiting to turn off migration mode (rust-lang#58781). Closes rust-lang#60450. My ulterior motive here is making it impossible to leave variables partially initialized across a yield (see rust-lang#60889, discussion at rust-lang#63035), so tests are included for that. cc rust-lang#54987 --- I'm not sure if bypassing the buffer is a good way of doing this. We could also make a `force_errors_buffer` or similar that gets recombined with all the errors as they are emitted. But this is simpler and seems fine to me. r? @Centril cc @cramertj @nikomatsakis @pnkfelix @RalfJung
…ized, r=Centril Make use of possibly uninitialized data [E0381] a hard error This is one of the behaviors we no longer allow in NLL. Since it can lead to undefined behavior, I think it's definitely worth making it a hard error without waiting to turn off migration mode (rust-lang#58781). Closes rust-lang#60450. My ulterior motive here is making it impossible to leave variables partially initialized across a yield (see rust-lang#60889, discussion at rust-lang#63035), so tests are included for that. cc rust-lang#54987 --- I'm not sure if bypassing the buffer is a good way of doing this. We could also make a `force_errors_buffer` or similar that gets recombined with all the errors as they are emitted. But this is simpler and seems fine to me. r? @Centril cc @cramertj @nikomatsakis @pnkfelix @RalfJung
…ized, r=Centril Make use of possibly uninitialized data [E0381] a hard error This is one of the behaviors we no longer allow in NLL. Since it can lead to undefined behavior, I think it's definitely worth making it a hard error without waiting to turn off migration mode (rust-lang#58781). Closes rust-lang#60450. My ulterior motive here is making it impossible to leave variables partially initialized across a yield (see rust-lang#60889, discussion at rust-lang#63035), so tests are included for that. cc rust-lang#54987 --- I'm not sure if bypassing the buffer is a good way of doing this. We could also make a `force_errors_buffer` or similar that gets recombined with all the errors as they are emitted. But this is simpler and seems fine to me. r? @Centril cc @cramertj @nikomatsakis @pnkfelix @RalfJung
Code sample:
When compiling this with
rustc +1.31.0 --edition 2018
, I get:In later versions, the warning message has been changed somewhat:
If I compile with
--edition 2015
I get no warnings at all. (Edit: this is still silent on 1.34.0 2015, but an warning is emitted in edition 2015 on the latest nightly).There are several issues as far as I can see:
Edit: I ran into this issue with inline assembly, where you may be required to specify an output register even if it's not used.
The text was updated successfully, but these errors were encountered: