about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2025-02-11 23:47:56 +0000
committerEsteban Küber <esteban@kuber.com.ar>2025-02-11 23:47:56 +0000
commit23daa8c724cccc4ef75de60d271a50ef193abf0f (patch)
treef94a3fead06c34ec520c7f6a700a1c4d09bc6f01
parent1b98d0ed13e4a8ff8d94e6aee0f11fab07d6139a (diff)
downloadrust-23daa8c724cccc4ef75de60d271a50ef193abf0f.tar.gz
rust-23daa8c724cccc4ef75de60d271a50ef193abf0f.zip
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(());
   |
```
-rw-r--r--compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs13
-rw-r--r--tests/ui/type-alias-enum-variants/enum-variant-generic-args.rs6
-rw-r--r--tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr33
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 66746dfc387..7eb982a3179 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 e4897005a5c..759a7fd7e05 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 3f98a1eb5c0..5039ae8f288 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