-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Memory unsafety using & bindings more than one level deep when destructuring #19997
Comments
cc me |
Nominating. |
Simplified test case (no unsafe code): fn main() {
let a = 0u8;
let mut a = Some(&a);
if let (&Some(ref b),) = (&a,) {
a = None;
println!("{}, {}", a, b);
}
} This seems to be an issue with tuple patterns specifically. I can't get it to happen if I try the same thing without one. The behavior suggests to me that borrowck does not consider |
Actually, I can make it happen for tuple structs as well: fn main() {
struct Foo<'a, 'b: 'a>(&'a Option<&'b u8>);
let a = 0u8;
let mut a = Some(&a);
if let Foo(&Some(ref b)) = Foo(&a) {
a = None;
println!("{}, {}", a, b);
}
} and regular structs: fn main() {
struct Foo<'a, 'b: 'a> { data: &'a Option<&'b u8> };
let a = 0u8;
let mut a = Some(&a);
if let Foo { data: &Some(ref b) } = (Foo { data: &a }) {
a = None;
println!("{}, {}", a, b);
}
} and even enum variants: fn main() {
struct Foo<'a, 'b: 'a>(&'a Option<&'b u8>);
let a = 0u8;
let mut a = Some(&a);
if let Foo::Foo(&Some(ref b)) = Foo::Foo(&a) {
a = None;
println!("{}, {}", a, b);
}
} |
Got a fix coming. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This segfaults.
The text was updated successfully, but these errors were encountered: