-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Segfault with enum struct and method #5625
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
Comments
Similar code that segfaults, except when enum AB {
A {x: int},
B
}
fn main() {
let a = A {x : 1};
let b = B;
match a {
A {x : _x1} => {
match b {
A {x : _x2} => io::println("AA"),
_ => io::println("A_")
}
},
_ => io::println("_")
}
} #5530 is almost certainly related (and quite probably the same issue), since both of these examples don't segfault when the |
Hmm, seems like it's an issue with struct variants. There are two things to note, 1) this code works as expected: enum AB {
A {x: int},
B
}
fn main() {
let a = A { x: 1 };
let b = B;
match a {
A {x : _x1} => {
match b {
A {x : _x2} => println("AA"),
_ => println("A_")
}
},
_ => println("_")
}
} and 2) even though the optimized example doesn't segfault, it still fails because it prints out |
Still reproduces |
There is a simpler testcase:
This code gets compiled to the following llvm-assembly:
as you can see both |
Code that collects fields in struct-like patterns used to ignore wildcard patterns like `Foo{_}`. But `enter_defaults` considered struct-like patterns as default in order to overcome this (accoring to my understanding of situation). However such behaviour caused code like this: ``` enum E { Foo{f: int}, Bar } let e = Bar; match e { Foo{f: _f} => { /* do something (1) */ } _ => { /* do something (2) */ } } ``` consider pattern `Foo{f: _f}` as default. That caused inproper behaviour and even segfaults while trying to destruct `Bar` as `Foo{f: _f}`. Issues: #5625 , #5530. This patch fixes `collect_record_or_struct_fields` to split cases of single wildcard struct-like pattern and no struct-like pattern at all. Former case resolved with `enter_rec_or_struct` (and not with `enter_defaults`). Closes #5625. Closes #5530.
Running this
test.rs
causes a segfault on Ubuntu 12.10 (compiled with incoming bda4dd3):Valgrind says this about it:
Note that the following variants of the last line of
main
do not cause a segfault:x.equals(&x);
y.equals(&y);
y.equals(&x);
The text was updated successfully, but these errors were encountered: