diff options
| author | Hirochika Matsumoto <matsujika@gmail.com> | 2021-01-29 05:43:35 +0900 |
|---|---|---|
| committer | Hirochika Matsumoto <matsujika@gmail.com> | 2021-01-29 06:52:49 +0900 |
| commit | 9e4ed337c783fab801d8a2e37feb58974205cfa3 (patch) | |
| tree | a58f4b38e8b2646843c00772b04587560b968368 /src | |
| parent | e32f372c4203b2527221b313cf63b05ea178e8a9 (diff) | |
| download | rust-9e4ed337c783fab801d8a2e37feb58974205cfa3.tar.gz rust-9e4ed337c783fab801d8a2e37feb58974205cfa3.zip | |
Suggest accessing field when code compiles with it
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/suggestions/field-access.rs | 15 | ||||
| -rw-r--r-- | src/test/ui/suggestions/field-access.stderr | 19 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/field-access.rs b/src/test/ui/suggestions/field-access.rs new file mode 100644 index 00000000000..822f66f2a47 --- /dev/null +++ b/src/test/ui/suggestions/field-access.rs @@ -0,0 +1,15 @@ +struct A { + b: B, +} + +enum B { + Fst, + Snd, +} + +fn main() { + let a = A { b: B::Fst }; + if let B::Fst = a {}; + //~^ ERROR mismatched types [E0308] + // note: you might have meant to use field `b` of type `B` +} diff --git a/src/test/ui/suggestions/field-access.stderr b/src/test/ui/suggestions/field-access.stderr new file mode 100644 index 00000000000..58bc6d3f2da --- /dev/null +++ b/src/test/ui/suggestions/field-access.stderr @@ -0,0 +1,19 @@ +error[E0308]: mismatched types + --> $DIR/field-access.rs:12: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: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. |
