Skip to content

Suggest accessing field when appropriate #81504

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

Merged
merged 9 commits into from
Feb 1, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add rust-fix test
hkmatsumoto committed Jan 29, 2021

Verified

This commit was signed with the committer’s verified signature. The key has expired.
oli-obk Oli Scherer
commit f641f5133bd0debee7e00e5fbb721045e7f6f87b
26 changes: 26 additions & 0 deletions src/test/ui/suggestions/field-access.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// run-rustfix
#![allow(dead_code)]

struct A {
b: B,
}

enum B {
Fst,
Snd,
}

fn main() {
let a = A { b: B::Fst };
if let B::Fst = a.b {};
//~^ ERROR mismatched types [E0308]
// note: you might have meant to use field `b` of type `B`
match a.b {
B::Fst => (),
B::Snd => (),
}
//~^^^ ERROR mismatched types [E0308]
// note: you might have meant to use field `b` of type `B`
//~^^^^ ERROR mismatched types [E0308]
// note: you might have meant to use field `b` of type `B`
}
3 changes: 3 additions & 0 deletions src/test/ui/suggestions/field-access.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// run-rustfix
#![allow(dead_code)]

struct A {
b: B,
}
6 changes: 3 additions & 3 deletions src/test/ui/suggestions/field-access.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/field-access.rs:12:12
--> $DIR/field-access.rs:15:12
|
LL | Fst,
| --- unit variant defined here
@@ -15,7 +15,7 @@ LL | if let B::Fst = a.b {};
| ^^^

error[E0308]: mismatched types
--> $DIR/field-access.rs:16:9
--> $DIR/field-access.rs:19:9
|
LL | Fst,
| --- unit variant defined here
@@ -31,7 +31,7 @@ LL | match a.b {
| ^^^

error[E0308]: mismatched types
--> $DIR/field-access.rs:17:9
--> $DIR/field-access.rs:20:9
|
LL | Snd,
| --- unit variant defined here