Rollup merge of #74173 - estebank:struct-pat-as-enum, r=petrochenkov

Detect tuple struct incorrectly used as struct pat

Subpart of #74005.

r? @petrochenkov
This commit is contained in:
Manish Goregaokar 2020-07-14 07:39:02 -07:00 committed by GitHub
commit b9a0f5803e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 137 additions and 49 deletions

View file

@ -2,8 +2,7 @@ struct S(usize, usize, usize, usize);
fn main() {
if let S { a, b, c, d } = S(1, 2, 3, 4) {
//~^ ERROR struct `S` does not have fields named `a`, `b`, `c`, `d` [E0026]
//~| ERROR pattern does not mention fields `0`, `1`, `2`, `3` [E0027]
//~^ ERROR tuple variant `S` written as struct variant
println!("hi");
}
}

View file

@ -1,18 +1,9 @@
error[E0026]: struct `S` does not have fields named `a`, `b`, `c`, `d`
--> $DIR/missing-fields-in-struct-pattern.rs:4:16
|
LL | if let S { a, b, c, d } = S(1, 2, 3, 4) {
| ^ ^ ^ ^ struct `S` does not have these fields
error[E0027]: pattern does not mention fields `0`, `1`, `2`, `3`
error[E0769]: tuple variant `S` written as struct variant
--> $DIR/missing-fields-in-struct-pattern.rs:4:12
|
LL | if let S { a, b, c, d } = S(1, 2, 3, 4) {
| ^^^^^^^^^^^^^^^^ missing fields `0`, `1`, `2`, `3`
|
= note: trying to match a tuple variant with a struct variant pattern
| ^^^^^^^^^^^^^^^^ help: use the tuple variant pattern syntax instead: `S(a, b, c, d)`
error: aborting due to 2 previous errors
error: aborting due to previous error
Some errors have detailed explanations: E0026, E0027.
For more information about an error, try `rustc --explain E0026`.
For more information about this error, try `rustc --explain E0769`.

View file

@ -4,7 +4,7 @@ enum X {
fn main() {
match X::Y(0) {
X::Y { number } => {} //~ ERROR does not have a field named `number`
//~^ ERROR pattern does not mention field `0`
X::Y { number } => {}
//~^ ERROR tuple variant `X::Y` written as struct variant
}
}

View file

@ -1,18 +1,9 @@
error[E0026]: variant `X::Y` does not have a field named `number`
--> $DIR/issue-41314.rs:7:16
|
LL | X::Y { number } => {}
| ^^^^^^ variant `X::Y` does not have this field
error[E0027]: pattern does not mention field `0`
error[E0769]: tuple variant `X::Y` written as struct variant
--> $DIR/issue-41314.rs:7:9
|
LL | X::Y { number } => {}
| ^^^^^^^^^^^^^^^ missing field `0`
|
= note: trying to match a tuple variant with a struct variant pattern
| ^^^^^^^^^^^^^^^ help: use the tuple variant pattern syntax instead: `X::Y(number)`
error: aborting due to 2 previous errors
error: aborting due to previous error
Some errors have detailed explanations: E0026, E0027.
For more information about an error, try `rustc --explain E0026`.
For more information about this error, try `rustc --explain E0769`.

View file

@ -48,18 +48,18 @@ error: union patterns should have exactly one field
LL | let U { a, b } = u;
| ^^^^^^^^^^
error[E0026]: union `U` does not have a field named `c`
--> $DIR/union-fields-2.rs:18:19
|
LL | let U { a, b, c } = u;
| ^ union `U` does not have this field
error: union patterns should have exactly one field
--> $DIR/union-fields-2.rs:18:9
|
LL | let U { a, b, c } = u;
| ^^^^^^^^^^^^^
error[E0026]: union `U` does not have a field named `c`
--> $DIR/union-fields-2.rs:18:19
|
LL | let U { a, b, c } = u;
| ^ union `U` does not have this field
error: union patterns should have exactly one field
--> $DIR/union-fields-2.rs:20:9
|