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
Activity
gurry commentedon Oct 17, 2023
The issue occurs in this function:
rust/compiler/rustc_errors/src/emitter.rs
Line 372 in 631a116
where we iterate through primary spans:
rust/compiler/rustc_errors/src/emitter.rs
Line 375 in 631a116
and potentially insert the same label multiple times:
rust/compiler/rustc_errors/src/emitter.rs
Line 434 in 631a116
without checking if it has already been inserted in the previous iteration of the loop. As a result we may end up with as many duplicates as there are primary spans.
@rustbot claim
gurry commentedon Oct 17, 2023
Bisected to nightly-22-06-04
commit[0] 2022-06-02: Auto merge of #97575 - nnethercote:lazify-SourceFile-lines, r=Mark-Simulacrum
commit[1] 2022-06-02: Auto merge of #97598 - spastorino:simplify-universal-impl-trait-lowering, r=cjgillot
commit[2] 2022-06-03: Auto merge of #97667 - matthiaskrgr:rollup-5cfxc85, r=matthiaskrgr
commit[3] 2022-06-03: Auto merge of #97497 - c410-f3r:z-errors, r=petrochenkov
commit[4] 2022-06-03: Auto merge of #96296 - cjgillot:remove-label-lt-shadow, r=petrochenkov
commit[5] 2022-06-03: Auto merge of #97679 - Dylan-DPC:rollup-nswmgmx, r=Dylan-DPC
commit[6] 2022-06-03: Auto merge of #89862 - lcnr:path-generics-diagnostics, r=estebank
commit[7] 2022-06-03: Auto merge of #97694 - Dylan-DPC:rollup-2yxo7ce, r=Dylan-DPC
commit[8] 2022-06-03: Auto merge of #85993 - bjorn3:serde_json, r=wesleywiser
commit[9] 2022-06-03: Auto merge of #95833 - notriddle:notriddle/human-readable-signals, r=yaahc
render_multispan_macro_backtrace()
#116838Rollup merge of rust-lang#116838 - gurry:116836-dup-macro-invoc-diag,…
Auto merge of rust-lang#116838 - gurry:116836-dup-macro-invoc-diag, r…