Skip to content

Fix bug in matching struct patterns #8350

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

Closed
wants to merge 4 commits into from
Closed

Fix bug in matching struct patterns #8350

wants to merge 4 commits into from

Conversation

dim-an
Copy link
Contributor

@dim-an dim-an commented Aug 6, 2013

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.

dim-an added 4 commits August 6, 2013 23:55
Document possible use with -S option.
Added testcases for `match` keyword including test for issue #5625.
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.
bors added a commit that referenced this pull request Aug 9, 2013
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.
@bors bors closed this Aug 9, 2013
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jan 27, 2022
fix bad suggestion on `numeric_literal`

closes rust-lang#8331

changelog: [`numeric_literal`]  fix suggestion not showing sign
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segfault with enum struct and method Matching struct-like enum with wildcard is broken
2 participants