-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Further restricting what coercions are allowed on places of type !
#131297
Comments
@lcnr also brought up a good point that |
Cc @rust-lang/opsem |
The question about struct and 1-variant enum matches also leads to the following formulation of the question: Is the following UB? #[repr(u8)]
enum Foo {
Foo,
}
fn main() {
let x: Foo = unsafe { std::mem::uninitialized() };
let Foo::Foo = x;
} I think the answer is no, it is defined behavior to do a discriminant read on a 1-variant enum because nothing needs to be read and there is no data to read in the first place ( If we agree on this, then I think we should say that struct patterns, and 1-variant enum patterns, should not be considered reads in this HIR analysis. |
Yep, that's approximately what I was thinking. |
I could see that argument for |
Yeah I think that code is definitely UB on the |
In #129392, I fixed a couple soundness holes having to do with the distinction between values and places and the
!
type, which has special divergence and coercion behavior in HIR typeck.To do so, I implemented a heuristic called
expr_guaranteed_to_constitute_read_for_never
(and same for patterns,pat_guaranteed...
), which determines whether an expression/pattern is guaranteed to perform a read of a value of type!
, which triggers the special divergence and coercion behavior. Read the description of the PR to see what the behavior is after the PR.There's still some open questions about what expressions and patterns should be considered reads in the HIR (such as reading structs with only field subpatterns that don't read, like
Struct { .. }
), but I'd like to separate that since the PR #129392 is strictly an improvement over the existing behavior.The text was updated successfully, but these errors were encountered: