-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Matching struct-like enum with wildcard is broken #5530
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
This works now. I'll check in the test case. |
Hmm, it passed for me but failed on the Linux bot. Nominating for milestone 5, production-ready |
I get a failure on Mac OS X:
(line 34 is the case: |
The following program fails: the match returns true, but should return false. enum AB {
None,
A { a: int },
B { b: int }
}
fn main() {
let b = Some(B {b: 1});
assert!(!match b {
Some(A { a: _ }) => true,
_ => false
})
} I believe the cause of the failure is similar to the failures described in this issue. |
Incoming PR, will fix when landed (hopefully) |
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.
map_clone: avoid suggesting `copied()` for &mut changelog: map_clone: avoid suggesting `copied()` for &mut Fixes rust-lang#5524
fun1
andfun2
should return same value.The text was updated successfully, but these errors were encountered: