From 23daa8c724cccc4ef75de60d271a50ef193abf0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 11 Feb 2025 23:47:56 +0000 Subject: [PATCH] Remove some the spans pointing at the enum in the path and its generic args ``` error[E0109]: type arguments are not allowed on tuple variant `TSVariant` --> $DIR/enum-variant-generic-args.rs:54:29 | LL | Enum::<()>::TSVariant::<()>(()); | --------- ^^ type argument not allowed | | | not allowed on tuple variant `TSVariant` | = note: generic arguments are not allowed on both an enum and its variant's path segments simultaneously; they are only valid in one place or the other help: remove the generics arguments from one of the path segments | LL - Enum::<()>::TSVariant::<()>(()); LL + Enum::<()>::TSVariant(()); | ``` --- .../src/hir_ty_lowering/errors.rs | 13 +++----- .../enum-variant-generic-args.rs | 6 ++-- .../enum-variant-generic-args.stderr | 33 +++++++++---------- 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs index 66746dfc3875..7eb982a31798 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs @@ -1047,10 +1047,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { }; }); - let segments: Vec<_> = match err_extend { - GenericsArgsErrExtend::DefVariant(segments) => segments.iter().collect(), - _ => segments.collect(), - }; + let segments: Vec<_> = segments.collect(); let types_and_spans: Vec<_> = segments .iter() .flat_map(|segment| { @@ -1511,10 +1508,10 @@ fn generics_args_err_extend<'a>( if args.len() > 1 && let Some(span) = args.into_iter().last() { - let msg = "generic arguments are not allowed on both an enum and its variant's \ - path segments simultaneously; they are only valid in one place or the \ - other"; - err.note(msg); + err.note( + "generic arguments are not allowed on both an enum and its variant's path \ + segments simultaneously; they are only valid in one place or the other", + ); err.span_suggestion_verbose( span, "remove the generics arguments from one of the path segments", diff --git a/tests/ui/type-alias-enum-variants/enum-variant-generic-args.rs b/tests/ui/type-alias-enum-variants/enum-variant-generic-args.rs index e4897005a5c1..759a7fd7e05a 100644 --- a/tests/ui/type-alias-enum-variants/enum-variant-generic-args.rs +++ b/tests/ui/type-alias-enum-variants/enum-variant-generic-args.rs @@ -52,7 +52,7 @@ fn main() { // Tuple struct variant Enum::<()>::TSVariant::<()>(()); - //~^ ERROR type arguments are not allowed on enum `Enum` and tuple variant `TSVariant` [E0109] + //~^ ERROR type arguments are not allowed on tuple variant `TSVariant` [E0109] Alias::TSVariant::<()>(()); //~^ ERROR type arguments are not allowed on this type [E0109] @@ -70,7 +70,7 @@ fn main() { // Struct variant Enum::<()>::SVariant::<()> { v: () }; - //~^ ERROR type arguments are not allowed on enum `Enum` and variant `SVariant` [E0109] + //~^ ERROR type arguments are not allowed on variant `SVariant` [E0109] Alias::SVariant::<()> { v: () }; //~^ ERROR type arguments are not allowed on this type [E0109] @@ -88,7 +88,7 @@ fn main() { // Unit variant Enum::<()>::UVariant::<()>; - //~^ ERROR type arguments are not allowed on enum `Enum` and unit variant `UVariant` [E0109] + //~^ ERROR type arguments are not allowed on unit variant `UVariant` [E0109] Alias::UVariant::<()>; //~^ ERROR type arguments are not allowed on this type [E0109] diff --git a/tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr b/tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr index 3f98a1eb5c09..5039ae8f288e 100644 --- a/tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr +++ b/tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr @@ -278,14 +278,13 @@ LL | Self::<()>::UVariant::<()>; | | | not allowed on this type -error[E0109]: type arguments are not allowed on enum `Enum` and tuple variant `TSVariant` - --> $DIR/enum-variant-generic-args.rs:54:12 +error[E0109]: type arguments are not allowed on tuple variant `TSVariant` + --> $DIR/enum-variant-generic-args.rs:54:29 | LL | Enum::<()>::TSVariant::<()>(()); - | ---- ^^ --------- ^^ type argument not allowed - | | | - | | not allowed on tuple variant `TSVariant` - | not allowed on enum `Enum` + | --------- ^^ type argument not allowed + | | + | not allowed on tuple variant `TSVariant` | = note: generic arguments are not allowed on both an enum and its variant's path segments simultaneously; they are only valid in one place or the other help: remove the generics arguments from one of the path segments @@ -354,14 +353,13 @@ LL | AliasFixed::<()>::TSVariant::<()>(()); | | | not allowed on this type -error[E0109]: type arguments are not allowed on enum `Enum` and variant `SVariant` - --> $DIR/enum-variant-generic-args.rs:72:12 +error[E0109]: type arguments are not allowed on variant `SVariant` + --> $DIR/enum-variant-generic-args.rs:72:28 | LL | Enum::<()>::SVariant::<()> { v: () }; - | ---- ^^ -------- ^^ type argument not allowed - | | | - | | not allowed on variant `SVariant` - | not allowed on enum `Enum` + | -------- ^^ type argument not allowed + | | + | not allowed on variant `SVariant` | = note: generic arguments are not allowed on both an enum and its variant's path segments simultaneously; they are only valid in one place or the other help: remove the generics arguments from one of the path segments @@ -458,14 +456,13 @@ LL - AliasFixed::<()>::SVariant::<()> { v: () }; LL + AliasFixed::<()>::SVariant { v: () }; | -error[E0109]: type arguments are not allowed on enum `Enum` and unit variant `UVariant` - --> $DIR/enum-variant-generic-args.rs:90:12 +error[E0109]: type arguments are not allowed on unit variant `UVariant` + --> $DIR/enum-variant-generic-args.rs:90:28 | LL | Enum::<()>::UVariant::<()>; - | ---- ^^ -------- ^^ type argument not allowed - | | | - | | not allowed on unit variant `UVariant` - | not allowed on enum `Enum` + | -------- ^^ type argument not allowed + | | + | not allowed on unit variant `UVariant` | = note: generic arguments are not allowed on both an enum and its variant's path segments simultaneously; they are only valid in one place or the other help: remove the generics arguments from one of the path segments