mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-30 08:34:07 +00:00
Rollup merge of #76103 - GuillaumeGomez:cleanup-e0769, r=Dylan-DPC
Clean up E0769 r? @pickfire cc @Dylan-DPC
This commit is contained in:
commit
4f276202f5
@ -1,5 +1,5 @@
|
|||||||
A tuple struct or tuple variant was used in a pattern as if it were a
|
A tuple struct or tuple variant was used in a pattern as if it were a struct or
|
||||||
struct or struct variant.
|
struct variant.
|
||||||
|
|
||||||
Erroneous code example:
|
Erroneous code example:
|
||||||
|
|
||||||
@ -7,9 +7,13 @@ Erroneous code example:
|
|||||||
enum E {
|
enum E {
|
||||||
A(i32),
|
A(i32),
|
||||||
}
|
}
|
||||||
|
|
||||||
let e = E::A(42);
|
let e = E::A(42);
|
||||||
|
|
||||||
match e {
|
match e {
|
||||||
E::A { number } => println!("{}", x),
|
E::A { number } => { // error!
|
||||||
|
println!("{}", number);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -21,12 +25,14 @@ To fix this error, you can use the tuple pattern:
|
|||||||
# }
|
# }
|
||||||
# let e = E::A(42);
|
# let e = E::A(42);
|
||||||
match e {
|
match e {
|
||||||
E::A(number) => println!("{}", number),
|
E::A(number) => { // ok!
|
||||||
|
println!("{}", number);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Alternatively, you can also use the struct pattern by using the correct
|
Alternatively, you can also use the struct pattern by using the correct field
|
||||||
field names and binding them to new identifiers:
|
names and binding them to new identifiers:
|
||||||
|
|
||||||
```
|
```
|
||||||
# enum E {
|
# enum E {
|
||||||
@ -34,6 +40,8 @@ field names and binding them to new identifiers:
|
|||||||
# }
|
# }
|
||||||
# let e = E::A(42);
|
# let e = E::A(42);
|
||||||
match e {
|
match e {
|
||||||
E::A { 0: number } => println!("{}", number),
|
E::A { 0: number } => { // ok!
|
||||||
|
println!("{}", number);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user