-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #81504 - matsujika:suggestion-field-access, r=estebank
Suggest accessing field when appropriate Fix #81222 r? ``@estebank``
- Loading branch information
Showing
4 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// run-rustfix | ||
#![allow(dead_code)] | ||
|
||
struct A { | ||
b: B, | ||
} | ||
|
||
enum B { | ||
Fst, | ||
Snd, | ||
} | ||
|
||
union Foo { | ||
bar: u32, | ||
qux: f32, | ||
} | ||
|
||
fn main() { | ||
let a = A { b: B::Fst }; | ||
if let B::Fst = a.b {}; //~ ERROR mismatched types [E0308] | ||
//~^ HELP you might have meant to use field `b` of type `B` | ||
match a.b { | ||
//~^ HELP you might have meant to use field `b` of type `B` | ||
//~| HELP you might have meant to use field `b` of type `B` | ||
B::Fst => (), //~ ERROR mismatched types [E0308] | ||
B::Snd => (), //~ ERROR mismatched types [E0308] | ||
} | ||
|
||
let foo = Foo { bar: 42 }; | ||
match unsafe { foo.bar } { | ||
//~^ HELP you might have meant to use field `bar` of type `u32` | ||
1u32 => (), //~ ERROR mismatched types [E0308] | ||
_ => (), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// run-rustfix | ||
#![allow(dead_code)] | ||
|
||
struct A { | ||
b: B, | ||
} | ||
|
||
enum B { | ||
Fst, | ||
Snd, | ||
} | ||
|
||
union Foo { | ||
bar: u32, | ||
qux: f32, | ||
} | ||
|
||
fn main() { | ||
let a = A { b: B::Fst }; | ||
if let B::Fst = a {}; //~ ERROR mismatched types [E0308] | ||
//~^ HELP you might have meant to use field `b` of type `B` | ||
match a { | ||
//~^ HELP you might have meant to use field `b` of type `B` | ||
//~| HELP you might have meant to use field `b` of type `B` | ||
B::Fst => (), //~ ERROR mismatched types [E0308] | ||
B::Snd => (), //~ ERROR mismatched types [E0308] | ||
} | ||
|
||
let foo = Foo { bar: 42 }; | ||
match foo { | ||
//~^ HELP you might have meant to use field `bar` of type `u32` | ||
1u32 => (), //~ ERROR mismatched types [E0308] | ||
_ => (), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/field-access.rs:20:12 | ||
| | ||
LL | Fst, | ||
| --- unit variant defined here | ||
... | ||
LL | if let B::Fst = a {}; | ||
| ^^^^^^ - this expression has type `A` | ||
| | | ||
| expected struct `A`, found enum `B` | ||
| | ||
help: you might have meant to use field `b` of type `B` | ||
| | ||
LL | if let B::Fst = a.b {}; | ||
| ^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/field-access.rs:25:9 | ||
| | ||
LL | Fst, | ||
| --- unit variant defined here | ||
... | ||
LL | match a { | ||
| - this expression has type `A` | ||
... | ||
LL | B::Fst => (), | ||
| ^^^^^^ expected struct `A`, found enum `B` | ||
| | ||
help: you might have meant to use field `b` of type `B` | ||
| | ||
LL | match a.b { | ||
| ^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/field-access.rs:26:9 | ||
| | ||
LL | Snd, | ||
| --- unit variant defined here | ||
... | ||
LL | match a { | ||
| - this expression has type `A` | ||
... | ||
LL | B::Snd => (), | ||
| ^^^^^^ expected struct `A`, found enum `B` | ||
| | ||
help: you might have meant to use field `b` of type `B` | ||
| | ||
LL | match a.b { | ||
| ^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/field-access.rs:32:9 | ||
| | ||
LL | match foo { | ||
| --- this expression has type `Foo` | ||
LL | | ||
LL | 1u32 => (), | ||
| ^^^^ expected union `Foo`, found `u32` | ||
| | ||
help: you might have meant to use field `bar` of type `u32` | ||
| | ||
LL | match unsafe { foo.bar } { | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |