Skip to content

Commit 23daa8c

Browse files
committed
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(()); | ```
1 parent 1b98d0e commit 23daa8c

File tree

3 files changed

+23
-29
lines changed

3 files changed

+23
-29
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -1047,10 +1047,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
10471047
};
10481048
});
10491049

1050-
let segments: Vec<_> = match err_extend {
1051-
GenericsArgsErrExtend::DefVariant(segments) => segments.iter().collect(),
1052-
_ => segments.collect(),
1053-
};
1050+
let segments: Vec<_> = segments.collect();
10541051
let types_and_spans: Vec<_> = segments
10551052
.iter()
10561053
.flat_map(|segment| {
@@ -1511,10 +1508,10 @@ fn generics_args_err_extend<'a>(
15111508
if args.len() > 1
15121509
&& let Some(span) = args.into_iter().last()
15131510
{
1514-
let msg = "generic arguments are not allowed on both an enum and its variant's \
1515-
path segments simultaneously; they are only valid in one place or the \
1516-
other";
1517-
err.note(msg);
1511+
err.note(
1512+
"generic arguments are not allowed on both an enum and its variant's path \
1513+
segments simultaneously; they are only valid in one place or the other",
1514+
);
15181515
err.span_suggestion_verbose(
15191516
span,
15201517
"remove the generics arguments from one of the path segments",

tests/ui/type-alias-enum-variants/enum-variant-generic-args.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn main() {
5252
// Tuple struct variant
5353

5454
Enum::<()>::TSVariant::<()>(());
55-
//~^ ERROR type arguments are not allowed on enum `Enum` and tuple variant `TSVariant` [E0109]
55+
//~^ ERROR type arguments are not allowed on tuple variant `TSVariant` [E0109]
5656

5757
Alias::TSVariant::<()>(());
5858
//~^ ERROR type arguments are not allowed on this type [E0109]
@@ -70,7 +70,7 @@ fn main() {
7070
// Struct variant
7171

7272
Enum::<()>::SVariant::<()> { v: () };
73-
//~^ ERROR type arguments are not allowed on enum `Enum` and variant `SVariant` [E0109]
73+
//~^ ERROR type arguments are not allowed on variant `SVariant` [E0109]
7474

7575
Alias::SVariant::<()> { v: () };
7676
//~^ ERROR type arguments are not allowed on this type [E0109]
@@ -88,7 +88,7 @@ fn main() {
8888
// Unit variant
8989

9090
Enum::<()>::UVariant::<()>;
91-
//~^ ERROR type arguments are not allowed on enum `Enum` and unit variant `UVariant` [E0109]
91+
//~^ ERROR type arguments are not allowed on unit variant `UVariant` [E0109]
9292

9393
Alias::UVariant::<()>;
9494
//~^ ERROR type arguments are not allowed on this type [E0109]

tests/ui/type-alias-enum-variants/enum-variant-generic-args.stderr

+15-18
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,13 @@ LL | Self::<()>::UVariant::<()>;
278278
| |
279279
| not allowed on this type
280280

281-
error[E0109]: type arguments are not allowed on enum `Enum` and tuple variant `TSVariant`
282-
--> $DIR/enum-variant-generic-args.rs:54:12
281+
error[E0109]: type arguments are not allowed on tuple variant `TSVariant`
282+
--> $DIR/enum-variant-generic-args.rs:54:29
283283
|
284284
LL | Enum::<()>::TSVariant::<()>(());
285-
| ---- ^^ --------- ^^ type argument not allowed
286-
| | |
287-
| | not allowed on tuple variant `TSVariant`
288-
| not allowed on enum `Enum`
285+
| --------- ^^ type argument not allowed
286+
| |
287+
| not allowed on tuple variant `TSVariant`
289288
|
290289
= 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
291290
help: remove the generics arguments from one of the path segments
@@ -354,14 +353,13 @@ LL | AliasFixed::<()>::TSVariant::<()>(());
354353
| |
355354
| not allowed on this type
356355

357-
error[E0109]: type arguments are not allowed on enum `Enum` and variant `SVariant`
358-
--> $DIR/enum-variant-generic-args.rs:72:12
356+
error[E0109]: type arguments are not allowed on variant `SVariant`
357+
--> $DIR/enum-variant-generic-args.rs:72:28
359358
|
360359
LL | Enum::<()>::SVariant::<()> { v: () };
361-
| ---- ^^ -------- ^^ type argument not allowed
362-
| | |
363-
| | not allowed on variant `SVariant`
364-
| not allowed on enum `Enum`
360+
| -------- ^^ type argument not allowed
361+
| |
362+
| not allowed on variant `SVariant`
365363
|
366364
= 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
367365
help: remove the generics arguments from one of the path segments
@@ -458,14 +456,13 @@ LL - AliasFixed::<()>::SVariant::<()> { v: () };
458456
LL + AliasFixed::<()>::SVariant { v: () };
459457
|
460458

461-
error[E0109]: type arguments are not allowed on enum `Enum` and unit variant `UVariant`
462-
--> $DIR/enum-variant-generic-args.rs:90:12
459+
error[E0109]: type arguments are not allowed on unit variant `UVariant`
460+
--> $DIR/enum-variant-generic-args.rs:90:28
463461
|
464462
LL | Enum::<()>::UVariant::<()>;
465-
| ---- ^^ -------- ^^ type argument not allowed
466-
| | |
467-
| | not allowed on unit variant `UVariant`
468-
| not allowed on enum `Enum`
463+
| -------- ^^ type argument not allowed
464+
| |
465+
| not allowed on unit variant `UVariant`
469466
|
470467
= 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
471468
help: remove the generics arguments from one of the path segments

0 commit comments

Comments
 (0)