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 {} {}{}", - if sp.is_desugaring(DesugaringKind::Async) { - "in the desugared `async fn`, " - } else { - "" - }, - if count > 1 { "one of" } else { "" }, + "{}the {} {}{}{}", + if count > 1 { "one of " } else { "" }, target, key, pluralize!(count), + if sp.is_desugaring(DesugaringKind::Async) { + " in the `Output` of this `async fn`" + } else { + "" + }, ), ); } @@ -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) } diff --git a/src/test/ui/async-await/dont-suggest-missing-await.stderr b/src/test/ui/async-await/dont-suggest-missing-await.stderr index 5bf10e00892..5c9b1d2c4d7 100644 --- a/src/test/ui/async-await/dont-suggest-missing-await.stderr +++ b/src/test/ui/async-await/dont-suggest-missing-await.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/dont-suggest-missing-await.rs:14:18 | LL | async fn make_u32() -> u32 { - | --- in the desugared `async fn`, this is the found opaque type + | --- the found opaque type in the `Output` of this `async fn` ... LL | take_u32(x) | ^ expected `u32`, found opaque type diff --git a/src/test/ui/async-await/suggest-missing-await-closure.stderr b/src/test/ui/async-await/suggest-missing-await-closure.stderr index 43366e6bbbf..5926c8351ff 100644 --- a/src/test/ui/async-await/suggest-missing-await-closure.stderr +++ b/src/test/ui/async-await/suggest-missing-await-closure.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/suggest-missing-await-closure.rs:16:18 | LL | async fn make_u32() -> u32 { - | --- in the desugared `async fn`, this is the found opaque type + | --- the found opaque type in the `Output` of this `async fn` ... LL | take_u32(x) | ^ diff --git a/src/test/ui/async-await/suggest-missing-await.stderr b/src/test/ui/async-await/suggest-missing-await.stderr index c7fcbdd8138..c0dc32b83fb 100644 --- a/src/test/ui/async-await/suggest-missing-await.stderr +++ b/src/test/ui/async-await/suggest-missing-await.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/suggest-missing-await.rs:13:14 | LL | async fn make_u32() -> u32 { - | --- in the desugared `async fn`, this is the found opaque type + | --- the found opaque type in the `Output` of this `async fn` ... LL | take_u32(x) | ^ @@ -16,6 +16,9 @@ LL | take_u32(x) error[E0308]: mismatched types --> $DIR/suggest-missing-await.rs:23:5 | +LL | async fn dummy() {} + | - the found opaque type in the `Output` of this `async fn` +... LL | dummy() | ^^^^^^^ expected `()`, found opaque type | diff --git a/src/test/ui/closures/closure-reform-bad.stderr b/src/test/ui/closures/closure-reform-bad.stderr index 16727b58e1f..3c4ae450764 100644 --- a/src/test/ui/closures/closure-reform-bad.stderr +++ b/src/test/ui/closures/closure-reform-bad.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/closure-reform-bad.rs:11:15 | LL | let f = |s: &str| println!("{}{}", s, string); - | ------------------------------------- this is the found closure + | ------------------------------------- the found closure LL | call_bare(f) | ^ expected fn pointer, found closure | diff --git a/src/test/ui/extern/extern-types-distinct-types.stderr b/src/test/ui/extern/extern-types-distinct-types.stderr index 2e258d687d3..32b45ee10ad 100644 --- a/src/test/ui/extern/extern-types-distinct-types.stderr +++ b/src/test/ui/extern/extern-types-distinct-types.stderr @@ -1,6 +1,11 @@ error[E0308]: mismatched types --> $DIR/extern-types-distinct-types.rs:9:5 | +LL | type A; + | ------- the found foreign type +LL | type B; + | ------- the expected foreign type +... LL | r | ^ expected extern type `B`, found extern type `A` | diff --git a/src/test/ui/impl-trait/equality2.stderr b/src/test/ui/impl-trait/equality2.stderr index 4e1880f31dc..b882514f616 100644 --- a/src/test/ui/impl-trait/equality2.stderr +++ b/src/test/ui/impl-trait/equality2.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/equality2.rs:25:18 | LL | fn hide(x: T) -> impl Foo { - | -------- this is the found opaque type + | -------- the found opaque type ... LL | let _: u32 = hide(0_u32); | --- ^^^^^^^^^^^ expected `u32`, found opaque type @@ -16,7 +16,7 @@ error[E0308]: mismatched types --> $DIR/equality2.rs:31:18 | LL | fn hide(x: T) -> impl Foo { - | -------- this is the found opaque type + | -------- the found opaque type ... LL | let _: i32 = Leak::leak(hide(0_i32)); | --- ^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found associated type @@ -32,7 +32,10 @@ error[E0308]: mismatched types --> $DIR/equality2.rs:38:10 | LL | fn hide(x: T) -> impl Foo { - | -------- this is the expected opaque type + | -------- + | | + | the expected opaque type + | the found opaque type ... LL | x = (x.1, | ^^^ expected `u32`, found `i32` @@ -44,7 +47,10 @@ error[E0308]: mismatched types --> $DIR/equality2.rs:41:10 | LL | fn hide(x: T) -> impl Foo { - | -------- this is the expected opaque type + | -------- + | | + | the expected opaque type + | the found opaque type ... LL | x.0); | ^^^ expected `i32`, found `u32` diff --git a/src/test/ui/issues/issue-24036.stderr b/src/test/ui/issues/issue-24036.stderr index 670bf57067b..036c05fc848 100644 --- a/src/test/ui/issues/issue-24036.stderr +++ b/src/test/ui/issues/issue-24036.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/issue-24036.rs:3:9 | LL | let mut x = |c| c + 1; - | --------- this is the expected closure + | --------- the expected closure LL | x = |c| c + 1; | ^^^^^^^^^ expected closure, found a different closure | diff --git a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr index 5b18c239b6e..232e54b5d37 100644 --- a/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr +++ b/src/test/ui/suggestions/fn-or-tuple-struct-without-args.stderr @@ -236,7 +236,7 @@ error[E0308]: mismatched types --> $DIR/fn-or-tuple-struct-without-args.rs:46:20 | LL | let closure = || 42; - | ----- this is the found closure + | ----- the found closure LL | let _: usize = closure; | ----- ^^^^^^^ | | | diff --git a/src/test/ui/suggestions/opaque-type-error.stderr b/src/test/ui/suggestions/opaque-type-error.stderr index 3a7ea2bcdd2..167d61bdf7c 100644 --- a/src/test/ui/suggestions/opaque-type-error.stderr +++ b/src/test/ui/suggestions/opaque-type-error.stderr @@ -2,7 +2,7 @@ error[E0308]: `if` and `else` have incompatible types --> $DIR/opaque-type-error.rs:20:9 | LL | fn thing_two() -> impl Future> { - | ------------------------------------ this is the found opaque type + | ------------------------------------ the found opaque type ... LL | / if true { LL | | thing_one() diff --git a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr index 182a3c7e81e..9549074d4bf 100644 --- a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr @@ -13,7 +13,7 @@ LL | let z: i32 = x; | expected due to this ... LL | type WrongGeneric = impl 'static; - | ------------------------------------ this is the found opaque type + | ------------------------------------ the found opaque type | = note: expected type `i32` found opaque type `WrongGeneric::<&{integer}>` diff --git a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr index b061ec3fff8..5a7f9d74eba 100644 --- a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr @@ -13,7 +13,7 @@ LL | let z: i32 = x; | expected due to this ... LL | type WrongGeneric = impl 'static; - | ------------------------------------ this is the found opaque type + | ------------------------------------ the found opaque type | = note: expected type `i32` found opaque type `WrongGeneric::<&{integer}>` diff --git a/src/test/ui/type-alias-impl-trait/never_reveal_concrete_type.stderr b/src/test/ui/type-alias-impl-trait/never_reveal_concrete_type.stderr index 415ac4bbdcb..70c99c944d6 100644 --- a/src/test/ui/type-alias-impl-trait/never_reveal_concrete_type.stderr +++ b/src/test/ui/type-alias-impl-trait/never_reveal_concrete_type.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/never_reveal_concrete_type.rs:13:27 | LL | type NoReveal = impl std::fmt::Debug; - | ------------------------------------- this is the found opaque type + | ------------------------------------- the found opaque type ... LL | let _: &'static str = x; | ------------ ^ expected `&str`, found opaque type diff --git a/src/test/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr b/src/test/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr index 3e67dc90dcb..375c0bc7fe2 100644 --- a/src/test/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr +++ b/src/test/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/no_revealing_outside_defining_module.rs:15:19 | LL | pub type Boo = impl ::std::fmt::Debug; - | -------------------------------------- this is the found opaque type + | -------------------------------------- the found opaque type ... LL | let _: &str = bomp(); | ---- ^^^^^^ expected `&str`, found opaque type @@ -16,7 +16,7 @@ error[E0308]: mismatched types --> $DIR/no_revealing_outside_defining_module.rs:19:5 | LL | pub type Boo = impl ::std::fmt::Debug; - | -------------------------------------- this is the expected opaque type + | -------------------------------------- the expected opaque type ... LL | fn bomp() -> boo::Boo { | -------- expected `Boo` because of return type