Skip to content

Commit

Permalink
Fix duplicate labels emitted in render_multispan_macro_backtrace()
Browse files Browse the repository at this point in the history
Using hash set instead of vec to weed out duplicates
  • Loading branch information
gurry committed Oct 17, 2023
1 parent 9ace9da commit e59e7d3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 40 deletions.
9 changes: 5 additions & 4 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
use rustc_lint_defs::pluralize;

use derive_setters::Setters;
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
use rustc_data_structures::sync::{DynSend, IntoDynSyncSend, Lrc};
use rustc_error_messages::{FluentArgs, SpanLabel};
use rustc_span::hygiene::{ExpnKind, MacroKind};
Expand Down Expand Up @@ -370,7 +370,7 @@ pub trait Emitter: Translate {
}

fn render_multispan_macro_backtrace(&self, span: &mut MultiSpan, always_backtrace: bool) {
let mut new_labels: Vec<(Span, String)> = vec![];
let mut new_labels = FxHashSet::default();

for &sp in span.primary_spans() {
if sp.is_dummy() {
Expand All @@ -387,7 +387,7 @@ pub trait Emitter: Translate {
}

if always_backtrace {
new_labels.push((
new_labels.insert((
trace.def_site,
format!(
"in this expansion of `{}`{}",
Expand Down Expand Up @@ -431,7 +431,7 @@ pub trait Emitter: Translate {
format!("this {} desugaring", kind.descr()).into()
}
};
new_labels.push((
new_labels.insert((
trace.call_site,
format!(
"in {}{}",
Expand All @@ -452,6 +452,7 @@ pub trait Emitter: Translate {
}
}

#[allow(rustc::potential_query_instability)]
for (label_span, label_text) in new_labels {
span.push_span_label(label_span, label_text);
}
Expand Down
7 changes: 1 addition & 6 deletions tests/ui/asm/x86_64/interpolated-idents.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ LL | asm!("", $in(x) x, $out(x) x, $lateout(x) x, $inout(x) x, $in
LL | / m!(in out lateout inout inlateout const sym
LL | | pure nomem readonly preserves_flags
LL | | noreturn nostack att_syntax options);
| | -
| |___________________________________________|
| |___________________________________________in this macro invocation
| |___________________________________________in this macro invocation
| |___________________________________________in this macro invocation
| in this macro invocation
| |___________________________________________- in this macro invocation
|
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,12 +861,7 @@ LL | $($name: 'a, $name: 'a, )+;
| ^^^^^^^^^ ^^^^^^^^^
...
LL | m!(T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 T11 T12 T13 T14 T15);
| ---------------------------------------------------------
| |
| in this macro invocation
| in this macro invocation
| in this macro invocation
| in this macro invocation
| --------------------------------------------------------- in this macro invocation
|
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
help: remove these bounds
Expand Down
30 changes: 6 additions & 24 deletions tests/ui/typeck/issue-116473-ice-wrong-span-variant-args.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ LL | ($variant:tt) => (if let EnumUnit::$variant::<i32, u32> {} = 5 { true }
| not allowed on this type
...
LL | recursive_tt!();
| ---------------
| |
| in this macro invocation
| in this macro invocation
| --------------- in this macro invocation
|
= note: enum variants can't have type parameters
= note: this error originates in the macro `recursive_tt` (in Nightly builds, run with -Z macro-backtrace for more info)
Expand Down Expand Up @@ -44,10 +41,7 @@ LL | ($variant:ident) => (if let EnumUnit::$variant::<i32, u32> {} = 5 { tru
| ^^^ ^^^ type argument not allowed
...
LL | recursive_ident!();
| ------------------
| |
| in this macro invocation
| in this macro invocation
| ------------------ in this macro invocation
|
= note: enum variants can't have type parameters
= note: this error originates in the macro `recursive_ident` (in Nightly builds, run with -Z macro-backtrace for more info)
Expand Down Expand Up @@ -81,10 +75,7 @@ LL | ($variant:tt) => (if let EnumUnit::$variant::<i32, u32> {} = 5 { true }
| not allowed on this type
...
LL | nested1_tt!();
| -------------