Skip to content

Commit

Permalink
Ignore desugarings when comparing duplicate trait error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Oct 4, 2018
1 parent 113141b commit ea3d8f5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4060,7 +4060,7 @@ impl<'a> LoweringContext<'a> {
let head_sp = head.span;
let desugared_span = self.allow_internal_unstable(
CompilerDesugaringKind::ForLoop,
head.span,
head_sp,
);

let iter = self.str_to_ident("iter");
Expand Down
22 changes: 17 additions & 5 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use ty::subst::Subst;
use ty::SubtypePredicate;
use util::nodemap::{FxHashMap, FxHashSet};

use syntax_pos::{DUMMY_SP, Span};
use syntax_pos::{DUMMY_SP, Span, ExpnInfo, ExpnFormat};

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

for (index, error) in errors.iter().enumerate() {
error_map.entry(error.obligation.cause.span).or_default().push(
// We want to ignore desugarings here: spans are equivalent even
// if one is the result of a desugaring and the other is not.
let mut span = error.obligation.cause.span;
if let Some(ExpnInfo {
format: ExpnFormat::CompilerDesugaring(_),
def_site: Some(def_span),
..
}) = span.ctxt().outer().expn_info() {
span = def_span;
}

error_map.entry(span).or_default().push(
ErrorDescriptor {
predicate: error.obligation.predicate.clone(),
index: Some(index)
});
}
);

self.reported_trait_errors.borrow_mut()
.entry(error.obligation.cause.span).or_default()
.entry(span).or_default()
.push(error.obligation.predicate.clone());
}

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

0 comments on commit ea3d8f5

Please sign in to comment.