Skip to content

Commit ea3d8f5

Browse files
committed
Ignore desugarings when comparing duplicate trait error messages
1 parent 113141b commit ea3d8f5

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/librustc/hir/lowering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4060,7 +4060,7 @@ impl<'a> LoweringContext<'a> {
40604060
let head_sp = head.span;
40614061
let desugared_span = self.allow_internal_unstable(
40624062
CompilerDesugaringKind::ForLoop,
4063-
head.span,
4063+
head_sp,
40644064
);
40654065

40664066
let iter = self.str_to_ident("iter");

src/librustc/traits/error_reporting.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use ty::subst::Subst;
4646
use ty::SubtypePredicate;
4747
use util::nodemap::{FxHashMap, FxHashSet};
4848

49-
use syntax_pos::{DUMMY_SP, Span};
49+
use syntax_pos::{DUMMY_SP, Span, ExpnInfo, ExpnFormat};
5050

5151
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
5252
pub fn report_fulfillment_errors(&self,
@@ -68,18 +68,30 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
6868
}).collect();
6969

7070
for (index, error) in errors.iter().enumerate() {
71-
error_map.entry(error.obligation.cause.span).or_default().push(
71+
// We want to ignore desugarings here: spans are equivalent even
72+
// if one is the result of a desugaring and the other is not.
73+
let mut span = error.obligation.cause.span;
74+
if let Some(ExpnInfo {
75+
format: ExpnFormat::CompilerDesugaring(_),
76+
def_site: Some(def_span),
77+
..
78+
}) = span.ctxt().outer().expn_info() {
79+
span = def_span;
80+
}
81+
82+
error_map.entry(span).or_default().push(
7283
ErrorDescriptor {
7384
predicate: error.obligation.predicate.clone(),
7485
index: Some(index)
75-
});
86+
}
87+
);
7688

7789
self.reported_trait_errors.borrow_mut()
78-
.entry(error.obligation.cause.span).or_default()
90+
.entry(span).or_default()
7991
.push(error.obligation.predicate.clone());
8092
}
8193

82-
// We do this in 2 passes because we want to display errors in order, tho
94+
// We do this in 2 passes because we want to display errors in order, though
8395
// maybe it *is* better to sort errors by span or something.
8496
let mut is_suppressed = vec![false; errors.len()];
8597
for (_, error_set) in error_map.iter() {

0 commit comments

Comments
 (0)