-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
binding-less matches on borrowed data are incorrectly allowed #45045
Comments
Does this imply that this is another bug on the pile of things fixed by MIR borrowck? |
Yeah. |
This still compiles with MIR borrowck, so I guess more work is needed. |
Is this same problem as #27282 ? |
It seems like the problem is that the
|
@pnkfelix points out that two-phase borrows may be the cause. This example gets an error: #![feature(nll)]
enum Xyz {
A,
B,
}
fn main() {
let mut e = Xyz::A;
let f = &mut e;
let g = f;
match e {
Xyz::A => println!("a"),
Xyz::B => println!("b"),
};
*g = Xyz::B;
} this gets the following output:
|
That's indeed what I expect under 2-phase borrows. |
Add NLL test for rust-lang#45045 cc rust-lang#45045 Part of rust-lang#47366 r? @nikomatsakis
Add NLL test for rust-lang#45045 cc rust-lang#45045 Part of rust-lang#47366 r? @nikomatsakis
…nts, r=nikomatsakis Make RValue::Discriminant a normal Shallow read Enum layout optimizations mean that the discriminant of an enum may not be stored in a tag disjoint from the rest of the fields of the enum. Stop borrow checking as though they are. Run with MIRI to see why this is needed: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=09a3236685a06b6096e2e2e3968b852c. This issue exists with the lexical borrow checker as well (see rust-lang#45045) so migrate mode should prevent this from being immediately breaking. r? @nikomatsakis Fixes rust-lang#56797
This is actually an unsoundness in AST borrowck: AST borrowck doesn't check things that are matched on for conflicting borrows unless there are actually pattern bindings, e.g. this compiles:
That is unsound because of e.g. data races. For example, this code compiles and runs, and semi-reliably segfaults:
The text was updated successfully, but these errors were encountered: