diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-11-05 20:10:51 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-05 20:10:51 +0100 |
| commit | bb50ebfca41c76c2f0a105dcfb25286013da7834 (patch) | |
| tree | fd98aaa603f8c7b56629cdadc26a36b830485d1a /tests | |
| parent | b524be55db4e1363c4d77ac70cd44032e865f253 (diff) | |
| parent | e26ad8b67d31fa8c35bf1e5e3ed310c06418d18b (diff) | |
| download | rust-bb50ebfca41c76c2f0a105dcfb25286013da7834.tar.gz rust-bb50ebfca41c76c2f0a105dcfb25286013da7834.zip | |
Rollup merge of #132567 - estebank:bad-suggestion, r=Nadrieril
Properly suggest `E::assoc` when we encounter `E::Variant::assoc` Use the right span when encountering an enum variant followed by an associated item so we don't lose the associated item in the resulting code. Do not suggest the thing twice, once as a removal of the associated item and a second time as a typo suggestion.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/enum/assoc-fn-call-on-variant.rs | 15 | ||||
| -rw-r--r-- | tests/ui/enum/assoc-fn-call-on-variant.stderr | 14 | ||||
| -rw-r--r-- | tests/ui/resolve/resolve-variant-assoc-item.stderr | 6 |
3 files changed, 30 insertions, 5 deletions
diff --git a/tests/ui/enum/assoc-fn-call-on-variant.rs b/tests/ui/enum/assoc-fn-call-on-variant.rs new file mode 100644 index 00000000000..7fa8eb2da41 --- /dev/null +++ b/tests/ui/enum/assoc-fn-call-on-variant.rs @@ -0,0 +1,15 @@ +#[derive(Default)] +enum E { + A {}, + B {}, + #[default] + C, +} + +impl E { + fn f() {} +} + +fn main() { + E::A::f(); //~ ERROR failed to resolve: `A` is a variant, not a module +} diff --git a/tests/ui/enum/assoc-fn-call-on-variant.stderr b/tests/ui/enum/assoc-fn-call-on-variant.stderr new file mode 100644 index 00000000000..47fc630c923 --- /dev/null +++ b/tests/ui/enum/assoc-fn-call-on-variant.stderr @@ -0,0 +1,14 @@ +error[E0433]: failed to resolve: `A` is a variant, not a module + --> $DIR/assoc-fn-call-on-variant.rs:14:8 + | +LL | E::A::f(); + | ^ `A` is a variant, not a module + | +help: there is an enum variant `E::A`; try using the variant's enum + | +LL | E::f(); + | ~ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0433`. diff --git a/tests/ui/resolve/resolve-variant-assoc-item.stderr b/tests/ui/resolve/resolve-variant-assoc-item.stderr index ed157197d17..9a5a605ac05 100644 --- a/tests/ui/resolve/resolve-variant-assoc-item.stderr +++ b/tests/ui/resolve/resolve-variant-assoc-item.stderr @@ -6,7 +6,7 @@ LL | E::V::associated_item; | help: there is an enum variant `E::V`; try using the variant's enum | -LL | E; +LL | E::associated_item; | ~ error[E0433]: failed to resolve: `V` is a variant, not a module @@ -17,10 +17,6 @@ LL | V::associated_item; | help: there is an enum variant `E::V`; try using the variant's enum | -LL | E; - | ~ -help: an enum with a similar name exists - | LL | E::associated_item; | ~ |
