about summary refs log tree commit diff
path: root/src/librustc/infer
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-12-15 14:05:08 -0800
committerEsteban Küber <esteban@kuber.com.ar>2020-01-08 09:29:47 -0800
commitc55615155d161c8abb307db0019ab58545cd246b (patch)
treef3e2767a08b49eab341f99dce2b2e272cfe8c698 /src/librustc/infer
parent9c0000cacac904a9b04c64ca349f54169b98f60a (diff)
downloadrust-c55615155d161c8abb307db0019ab58545cd246b.tar.gz
rust-c55615155d161c8abb307db0019ab58545cd246b.zip
review comments
Diffstat (limited to 'src/librustc/infer')
-rw-r--r--src/librustc/infer/error_reporting/mod.rs40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs
index e134a6c17cc..d0243dad700 100644
--- a/src/librustc/infer/error_reporting/mod.rs
+++ b/src/librustc/infer/error_reporting/mod.rs
@@ -1339,16 +1339,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
                             err.span_label(
                                 *sp,
                                 format!(
-                                    "{}this is {}the {} {}{}",
+                                    "{}the {} {}{}{}",
+                                    if count > 1 { "one of " } else { "" },
+                                    target,
+                                    key,
+                                    pluralize!(count),
                                     if sp.is_desugaring(DesugaringKind::Async) {
-                                        "in the desugared `async fn`, "
+                                        " in the `Output` of this `async fn`"
                                     } else {
                                         ""
                                     },
-                                    if count > 1 { "one of" } else { "" },
-                                    target,
-                                    key,
-                                    pluralize!(count),
                                 ),
                             );
                         }
@@ -1364,18 +1364,24 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
                     ty::Opaque(..) => "opaque type",
                     _ => "",
                 };
-                match t.kind {
-                    ty::Closure(def_id, _) | ty::Opaque(def_id, _) => {
-                        let span = self.tcx.def_span(def_id);
-                        debug!("note_type_err visit_ty {:?}", span.macro_backtrace());
-                        if !self.ignore_span.overlaps(span)
-                            && !self.expected.values().any(|exp| exp.iter().any(|sp| *sp == span))
-                        {
-                            let entry = self.types.entry(kind).or_default();
-                            entry.insert(span);
-                        }
+                if let ty::Closure(def_id, _) | ty::Opaque(def_id, _) = t.kind {
+                    let span = self.tcx.def_span(def_id);
+                    // Avoid cluttering the output when the "found" and error span overlap:
+                    //
+                    // error[E0308]: mismatched types
+                    //   --> $DIR/issue-20862.rs:2:5
+                    //    |
+                    // LL |     |y| x + y
+                    //    |     ^^^^^^^^^
+                    //    |     |
+                    //    |     the found closure
+                    //    |     expected `()`, found closure
+                    //    |
+                    //    = note: expected unit type `()`
+                    //                 found closure `[closure@$DIR/issue-20862.rs:2:5: 2:14 x:_]`
+                    if !self.ignore_span.overlaps(span) {
+                        self.types.entry(kind).or_default().insert(span);
                     }
-                    _ => {}
                 }
                 t.super_visit_with(self)
             }