Closed
Description
Code
enum Enum<T1, T2> { VariantA { _v1: T1, _v2: T2 }, VariantB }
type EnumUnit = Enum<(), ()>;
macro_rules! test {
() => (if let EnumUnit::VariantB::<i32, u32> {} = 5 { true } else { false });
}
fn main() {
test!();
}
Current output
error[E0109]: type arguments are not allowed on this type
--> ../dup-macro-invoc-diag.rs:6:40
|
6 | () => (if let EnumUnit::VariantB::<i32, u32> {} = 5 { true } else { false });
| -------- ^^^ ^^^ type argument not allowed
| |
| not allowed on this type
...
10 | test!();
| -------
| |
| in this macro invocation
| in this macro invocation
|
= note: enum variants can't have type parameters
= note: this error originates in the macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
help: you might have meant to specify type parameters on enum `Enum`
|
6 - () => (if let EnumUnit::VariantB::<i32, u32> {} = 5 { true } else { false });
6 + () => (if let EnumUnit::<i32, u32>::VariantB {} = 5 { true } else { false });
|
Desired output
error[E0109]: type arguments are not allowed on this type
--> ../dup-macro-invoc-diag.rs:6:40
|
6 | () => (if let EnumUnit::VariantB::<i32, u32> {} = 5 { true } else { false });
| -------- ^^^ ^^^ type argument not allowed
| |
| not allowed on this type
...
10 | test!();
| -------
| |
| in this macro invocation
|
= note: enum variants can't have type parameters
= note: this error originates in the macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
help: you might have meant to specify type parameters on enum `Enum`
|
6 - () => (if let EnumUnit::VariantB::<i32, u32> {} = 5 { true } else { false });
6 + () => (if let EnumUnit::<i32, u32>::VariantB {} = 5 { true } else { false });
|
Rationale and extra context
The label in this macro invocation
should appear only once.
Other cases
No response
Anything else?
The number of label repetitions equal the number of primary macro spans in the diagnostic. In the above code we have two primary spans:
6 | () => (if let EnumUnit::VariantB::<i32, u32> {} = 5 { true } else { false });
| -------- ^^^ ^^^ type argument not allowed
Therefore we see two repetitions of the in this macro invocation
label:
10 | test!();
| -------
| |
| in this macro invocation
| in this macro invocation
If we add another type param to enum Enum<T1, T2>
to make it enum Enum<T1, T2, T3>
and correspondingly update the macro it will result in three primary spans and therefore we will now see three occurrences of the label.
Metadata
rustc 1.72.1 (d5c2e9c 2023-09-13)
binary: rustc
commit-hash: d5c2e9c
commit-date: 2023-09-13
host: x86_64-pc-windows-msvc
release: 1.72.1
LLVM version: 16.0.5