review comments

This commit is contained in:
Esteban Küber 2019-12-15 14:05:08 -08:00
parent 9c0000caca
commit c55615155d
14 changed files with 54 additions and 34 deletions

View File

@ -1339,16 +1339,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
err.span_label( err.span_label(
*sp, *sp,
format!( format!(
"{}this is {}the {} {}{}", "{}the {} {}{}{}",
if sp.is_desugaring(DesugaringKind::Async) { if count > 1 { "one of " } else { "" },
"in the desugared `async fn`, "
} else {
""
},
if count > 1 { "one of" } else { "" },
target, target,
key, key,
pluralize!(count), 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", ty::Opaque(..) => "opaque type",
_ => "", _ => "",
}; };
match t.kind { if let ty::Closure(def_id, _) | ty::Opaque(def_id, _) = t.kind {
ty::Closure(def_id, _) | ty::Opaque(def_id, _) => { let span = self.tcx.def_span(def_id);
let span = self.tcx.def_span(def_id); // Avoid cluttering the output when the "found" and error span overlap:
debug!("note_type_err visit_ty {:?}", span.macro_backtrace()); //
if !self.ignore_span.overlaps(span) // error[E0308]: mismatched types
&& !self.expected.values().any(|exp| exp.iter().any(|sp| *sp == span)) // --> $DIR/issue-20862.rs:2:5
{ // |
let entry = self.types.entry(kind).or_default(); // LL | |y| x + y
entry.insert(span); // | ^^^^^^^^^
} // | |
// | 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) t.super_visit_with(self)
} }

View File

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/dont-suggest-missing-await.rs:14:18 --> $DIR/dont-suggest-missing-await.rs:14:18
| |
LL | async fn make_u32() -> u32 { 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) LL | take_u32(x)
| ^ expected `u32`, found opaque type | ^ expected `u32`, found opaque type

View File

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/suggest-missing-await-closure.rs:16:18 --> $DIR/suggest-missing-await-closure.rs:16:18
| |
LL | async fn make_u32() -> u32 { 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) LL | take_u32(x)
| ^ | ^

View File

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/suggest-missing-await.rs:13:14 --> $DIR/suggest-missing-await.rs:13:14
| |
LL | async fn make_u32() -> u32 { 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) LL | take_u32(x)
| ^ | ^
@ -16,6 +16,9 @@ LL | take_u32(x)
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/suggest-missing-await.rs:23:5 --> $DIR/suggest-missing-await.rs:23:5
| |
LL | async fn dummy() {}
| - the found opaque type in the `Output` of this `async fn`
...
LL | dummy() LL | dummy()
| ^^^^^^^ expected `()`, found opaque type | ^^^^^^^ expected `()`, found opaque type
| |

View File

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/closure-reform-bad.rs:11:15 --> $DIR/closure-reform-bad.rs:11:15
| |
LL | let f = |s: &str| println!("{}{}", s, string); LL | let f = |s: &str| println!("{}{}", s, string);
| ------------------------------------- this is the found closure | ------------------------------------- the found closure
LL | call_bare(f) LL | call_bare(f)
| ^ expected fn pointer, found closure | ^ expected fn pointer, found closure
| |

View File

@ -1,6 +1,11 @@
error[E0308]: mismatched types error[E0308]: mismatched types
--> $DIR/extern-types-distinct-types.rs:9:5 --> $DIR/extern-types-distinct-types.rs:9:5
| |
LL | type A;
| ------- the found foreign type
LL | type B;
| ------- the expected foreign type
...
LL | r LL | r
| ^ expected extern type `B`, found extern type `A` | ^ expected extern type `B`, found extern type `A`
| |

View File

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/equality2.rs:25:18 --> $DIR/equality2.rs:25:18
| |
LL | fn hide<T: Foo>(x: T) -> impl Foo { LL | fn hide<T: Foo>(x: T) -> impl Foo {
| -------- this is the found opaque type | -------- the found opaque type
... ...
LL | let _: u32 = hide(0_u32); LL | let _: u32 = hide(0_u32);
| --- ^^^^^^^^^^^ expected `u32`, found opaque type | --- ^^^^^^^^^^^ expected `u32`, found opaque type
@ -16,7 +16,7 @@ error[E0308]: mismatched types
--> $DIR/equality2.rs:31:18 --> $DIR/equality2.rs:31:18
| |
LL | fn hide<T: Foo>(x: T) -> impl Foo { LL | fn hide<T: Foo>(x: T) -> impl Foo {
| -------- this is the found opaque type | -------- the found opaque type
... ...
LL | let _: i32 = Leak::leak(hide(0_i32)); LL | let _: i32 = Leak::leak(hide(0_i32));
| --- ^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found associated type | --- ^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found associated type
@ -32,7 +32,10 @@ error[E0308]: mismatched types
--> $DIR/equality2.rs:38:10 --> $DIR/equality2.rs:38:10
| |
LL | fn hide<T: Foo>(x: T) -> impl Foo { LL | fn hide<T: Foo>(x: T) -> impl Foo {
| -------- this is the expected opaque type | --------
| |
| the expected opaque type
| the found opaque type
... ...
LL | x = (x.1, LL | x = (x.1,
| ^^^ expected `u32`, found `i32` | ^^^ expected `u32`, found `i32`
@ -44,7 +47,10 @@ error[E0308]: mismatched types
--> $DIR/equality2.rs:41:10 --> $DIR/equality2.rs:41:10
| |
LL | fn hide<T: Foo>(x: T) -> impl Foo { LL | fn hide<T: Foo>(x: T) -> impl Foo {
| -------- this is the expected opaque type | --------
| |
| the expected opaque type
| the found opaque type
... ...
LL | x.0); LL | x.0);
| ^^^ expected `i32`, found `u32` | ^^^ expected `i32`, found `u32`

View File

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-24036.rs:3:9 --> $DIR/issue-24036.rs:3:9
| |
LL | let mut x = |c| c + 1; LL | let mut x = |c| c + 1;
| --------- this is the expected closure | --------- the expected closure
LL | x = |c| c + 1; LL | x = |c| c + 1;
| ^^^^^^^^^ expected closure, found a different closure | ^^^^^^^^^ expected closure, found a different closure
| |

View File

@ -236,7 +236,7 @@ error[E0308]: mismatched types
--> $DIR/fn-or-tuple-struct-without-args.rs:46:20 --> $DIR/fn-or-tuple-struct-without-args.rs:46:20
| |
LL | let closure = || 42; LL | let closure = || 42;
| ----- this is the found closure | ----- the found closure
LL | let _: usize = closure; LL | let _: usize = closure;
| ----- ^^^^^^^ | ----- ^^^^^^^
| | | | | |

View File

@ -2,7 +2,7 @@ error[E0308]: `if` and `else` have incompatible types
--> $DIR/opaque-type-error.rs:20:9 --> $DIR/opaque-type-error.rs:20:9
| |
LL | fn thing_two() -> impl Future<Output = Result<(), ()>> { LL | fn thing_two() -> impl Future<Output = Result<(), ()>> {
| ------------------------------------ this is the found opaque type | ------------------------------------ the found opaque type
... ...
LL | / if true { LL | / if true {
LL | | thing_one() LL | | thing_one()

View File

@ -13,7 +13,7 @@ LL | let z: i32 = x;
| expected due to this | expected due to this
... ...
LL | type WrongGeneric<T> = impl 'static; LL | type WrongGeneric<T> = impl 'static;
| ------------------------------------ this is the found opaque type | ------------------------------------ the found opaque type
| |
= note: expected type `i32` = note: expected type `i32`
found opaque type `WrongGeneric::<&{integer}>` found opaque type `WrongGeneric::<&{integer}>`

View File

@ -13,7 +13,7 @@ LL | let z: i32 = x;
| expected due to this | expected due to this
... ...
LL | type WrongGeneric<T> = impl 'static; LL | type WrongGeneric<T> = impl 'static;
| ------------------------------------ this is the found opaque type | ------------------------------------ the found opaque type
| |
= note: expected type `i32` = note: expected type `i32`
found opaque type `WrongGeneric::<&{integer}>` found opaque type `WrongGeneric::<&{integer}>`

View File

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/never_reveal_concrete_type.rs:13:27 --> $DIR/never_reveal_concrete_type.rs:13:27
| |
LL | type NoReveal = impl std::fmt::Debug; LL | type NoReveal = impl std::fmt::Debug;
| ------------------------------------- this is the found opaque type | ------------------------------------- the found opaque type
... ...
LL | let _: &'static str = x; LL | let _: &'static str = x;
| ------------ ^ expected `&str`, found opaque type | ------------ ^ expected `&str`, found opaque type

View File

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/no_revealing_outside_defining_module.rs:15:19 --> $DIR/no_revealing_outside_defining_module.rs:15:19
| |
LL | pub type Boo = impl ::std::fmt::Debug; LL | pub type Boo = impl ::std::fmt::Debug;
| -------------------------------------- this is the found opaque type | -------------------------------------- the found opaque type
... ...
LL | let _: &str = bomp(); LL | let _: &str = bomp();
| ---- ^^^^^^ expected `&str`, found opaque type | ---- ^^^^^^ expected `&str`, found opaque type
@ -16,7 +16,7 @@ error[E0308]: mismatched types
--> $DIR/no_revealing_outside_defining_module.rs:19:5 --> $DIR/no_revealing_outside_defining_module.rs:19:5
| |
LL | pub type Boo = impl ::std::fmt::Debug; LL | pub type Boo = impl ::std::fmt::Debug;
| -------------------------------------- this is the expected opaque type | -------------------------------------- the expected opaque type
... ...
LL | fn bomp() -> boo::Boo { LL | fn bomp() -> boo::Boo {
| -------- expected `Boo` because of return type | -------- expected `Boo` because of return type