about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2018-10-04 14:48:32 +0100
committervarkor <github@varkor.com>2018-10-04 14:48:32 +0100
commitea3d8f510dfe18870b8b0b2bb5bf007fe914c262 (patch)
tree15c1694e69551b68394a3c0bb87b80f59f4ccdb8 /src
parent113141b6f5d10946f8a66442af3e2b0e2f454745 (diff)
downloadrust-ea3d8f510dfe18870b8b0b2bb5bf007fe914c262.tar.gz
rust-ea3d8f510dfe18870b8b0b2bb5bf007fe914c262.zip
Ignore desugarings when comparing duplicate trait error messages
Diffstat (limited to 'src')
-rw-r--r--src/librustc/hir/lowering.rs2
-rw-r--r--src/librustc/traits/error_reporting.rs22
2 files changed, 18 insertions, 6 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs
index 821c55a9f4e..bf421da61e4 100644
--- a/src/librustc/hir/lowering.rs
+++ b/src/librustc/hir/lowering.rs
@@ -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");
diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs
index 6fb5acde72c..3ba31e229e1 100644
--- a/src/librustc/traits/error_reporting.rs
+++ b/src/librustc/traits/error_reporting.rs
@@ -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,
@@ -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() {