about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorOhad Ravid <ohad.rv@gmail.com>2019-10-30 16:53:41 +0100
committerOhad Ravid <ohad.rv@gmail.com>2019-10-31 09:30:14 +0100
commit8bb54501280eba814b31628db1088ca4f03638e1 (patch)
treef4a6d30029670a446da8319234f9cf6413d12e64 /src
parentc553e8e8812c19809e70523064989e66c5cfd3f1 (diff)
Fix incorrect diagnostics for expected type in E0271 with an associated type
Diffstat (limited to 'src')
-rw-r--r--src/librustc/traits/error_reporting.rs23
-rw-r--r--src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr12
-rw-r--r--src/test/ui/associated-types/associated-types-eq-3.rs4
-rw-r--r--src/test/ui/associated-types/associated-types-eq-3.stderr12
-rw-r--r--src/test/ui/associated-types/associated-types-eq-hr.stderr12
-rw-r--r--src/test/ui/associated-types/associated-types-issue-20346.stderr6
-rw-r--r--src/test/ui/associated-types/associated-types-multiple-types-one-trait.stderr16
-rw-r--r--src/test/ui/associated-types/associated-types-overridden-binding-2.stderr6
-rw-r--r--src/test/ui/async-await/async-block-control-flow-static-semantics.stderr12
-rw-r--r--src/test/ui/error-codes/E0271.stderr6
-rw-r--r--src/test/ui/issues/issue-24204.stderr6
11 files changed, 64 insertions, 51 deletions
diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs
index b55c0f29a70..7833d43438a 100644
--- a/src/librustc/traits/error_reporting.rs
+++ b/src/librustc/traits/error_reporting.rs
@@ -226,13 +226,26 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
                     0,
                     &mut obligations
                 );
+
+                debug!("report_projection_error obligation.cause={:?} obligation.param_env={:?}",
+                       obligation.cause, obligation.param_env);
+
+                debug!("report_projection_error normalized_ty={:?} data.ty={:?}",
+                       normalized_ty, data.ty);
+
+                let is_normalized_ty_expected = match &obligation.cause.code {
+                    ObligationCauseCode::ItemObligation(_) |
+                    ObligationCauseCode::BindingObligation(_, _) |
+                    ObligationCauseCode::ObjectCastObligation(_) => false,
+                    _ => true,
+                };
+
                 if let Err(error) = self.at(&obligation.cause, obligation.param_env)
-                    .eq(normalized_ty, data.ty)
+                    .eq_exp(is_normalized_ty_expected, normalized_ty, data.ty)
                 {
-                    values = Some(infer::ValuePairs::Types(ExpectedFound {
-                        expected: normalized_ty,
-                        found: data.ty,
-                    }));
+                    values = Some(infer::ValuePairs::Types(
+                        ExpectedFound::new(is_normalized_ty_expected, normalized_ty, data.ty)));
+
                     err_buf = error;
                     err = &err_buf;
                 }
diff --git a/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr b/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr
index 6a2135ca464..800b762911a 100644
--- a/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr
+++ b/src/test/ui/associated-types/associated-types-binding-to-type-defined-in-supertrait.stderr
@@ -5,10 +5,10 @@ LL | fn blue_car<C:Car<Color=Blue>>(c: C) {
    |    --------       ---------- required by this bound in `blue_car`
 ...
 LL | fn b() { blue_car(ModelT); }
-   |          ^^^^^^^^ expected struct `Black`, found struct `Blue`
+   |          ^^^^^^^^ expected struct `Blue`, found struct `Black`
    |
-   = note: expected type `Black`
-              found type `Blue`
+   = note: expected type `Blue`
+              found type `Black`
 
 error[E0271]: type mismatch resolving `<ModelU as Vehicle>::Color == Black`
   --> $DIR/associated-types-binding-to-type-defined-in-supertrait.rs:32:10
@@ -17,10 +17,10 @@ LL | fn black_car<C:Car<Color=Black>>(c: C) {
    |    ---------       ----------- required by this bound in `black_car`
 ...
 LL | fn c() { black_car(ModelU); }
-   |          ^^^^^^^^^ expected struct `Blue`, found struct `Black`
+   |          ^^^^^^^^^ expected struct `Black`, found struct `Blue`
    |
-   = note: expected type `Blue`
-              found type `Black`
+   = note: expected type `Black`
+              found type `Blue`
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/associated-types/associated-types-eq-3.rs b/src/test/ui/associated-types/associated-types-eq-3.rs
index 9366148b587..22e04a8f15c 100644
--- a/src/test/ui/associated-types/associated-types-eq-3.rs
+++ b/src/test/ui/associated-types/associated-types-eq-3.rs
@@ -37,8 +37,8 @@ pub fn main() {
     let a = 42;
     foo1(a);
     //~^ ERROR type mismatch resolving
-    //~| expected usize, found struct `Bar`
+    //~| expected struct `Bar`, found usize
     baz(&a);
     //~^ ERROR type mismatch resolving
-    //~| expected usize, found struct `Bar`
+    //~| expected struct `Bar`, found usize
 }
diff --git a/src/test/ui/associated-types/associated-types-eq-3.stderr b/src/test/ui/associated-types/associated-types-eq-3.stderr
index 83d89924944..0f2bc84aa1c 100644
--- a/src/test/ui/associated-types/associated-types-eq-3.stderr
+++ b/src/test/ui/associated-types/associated-types-eq-3.stderr
@@ -16,19 +16,19 @@ LL | fn foo1<I: Foo<A=Bar>>(x: I) {
    |    ----        ----- required by this bound in `foo1`
 ...
 LL |     foo1(a);
-   |     ^^^^ expected usize, found struct `Bar`
+   |     ^^^^ expected struct `Bar`, found usize
    |
-   = note: expected type `usize`
-              found type `Bar`
+   = note: expected type `Bar`
+              found type `usize`
 
 error[E0271]: type mismatch resolving `<isize as Foo>::A == Bar`
   --> $DIR/associated-types-eq-3.rs:41:9
    |
 LL |     baz(&a);
-   |         ^^ expected usize, found struct `Bar`
+   |         ^^ expected struct `Bar`, found usize
    |
-   = note: expected type `usize`
-              found type `Bar`
+   = note: expected type `Bar`
+              found type `usize`
    = note: required for the cast to the object type `dyn Foo<A = Bar>`
 
 error: aborting due to 3 previous errors
diff --git a/src/test/ui/associated-types/associated-types-eq-hr.stderr b/src/test/ui/associated-types/associated-types-eq-hr.stderr
index 45b6cc9ba5f..a8c239389e9 100644
--- a/src/test/ui/associated-types/associated-types-eq-hr.stderr
+++ b/src/test/ui/associated-types/associated-types-eq-hr.stderr
@@ -7,10 +7,10 @@ LL |     where T : for<'x> TheTrait<&'x isize, A = &'x isize>
    |                                           ------------- required by this bound in `foo`
 ...
 LL |     foo::<UintStruct>();
-   |     ^^^^^^^^^^^^^^^^^ expected usize, found isize
+   |     ^^^^^^^^^^^^^^^^^ expected isize, found usize
    |
-   = note: expected type `&usize`
-              found type `&isize`
+   = note: expected type `&isize`
+              found type `&usize`
 
 error[E0271]: type mismatch resolving `for<'x> <IntStruct as TheTrait<&'x isize>>::A == &'x usize`
   --> $DIR/associated-types-eq-hr.rs:86:5
@@ -21,10 +21,10 @@ LL |     where T : for<'x> TheTrait<&'x isize, A = &'x usize>
    |                                           ------------- required by this bound in `bar`
 ...
 LL |     bar::<IntStruct>();
-   |     ^^^^^^^^^^^^^^^^ expected isize, found usize
+   |     ^^^^^^^^^^^^^^^^ expected usize, found isize
    |
-   = note: expected type `&isize`
-              found type `&usize`
+   = note: expected type `&usize`
+              found type `&isize`
 
 error[E0277]: the trait bound `for<'x, 'y> Tuple: TheTrait<(&'x isize, &'y isize)>` is not satisfied
   --> $DIR/associated-types-eq-hr.rs:91:17
diff --git a/src/test/ui/associated-types/associated-types-issue-20346.stderr b/src/test/ui/associated-types/associated-types-issue-20346.stderr
index c8f8725afc4..b763b82d540 100644
--- a/src/test/ui/associated-types/associated-types-issue-20346.stderr
+++ b/src/test/ui/associated-types/associated-types-issue-20346.stderr
@@ -5,10 +5,10 @@ LL | fn is_iterator_of<A, I: Iterator<Item=A>>(_: &I) {}
    |    --------------                ------ required by this bound in `is_iterator_of`
 ...
 LL |     is_iterator_of::<Option<T>, _>(&adapter);
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter, found enum `std::option::Option`
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `std::option::Option`, found type parameter
    |
-   = note: expected type `T`
-              found type `std::option::Option<T>`
+   = note: expected type `std::option::Option<T>`
+              found type `T`
    = help: type parameters must be constrained to match other types
    = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
 
diff --git a/src/test/ui/associated-types/associated-types-multiple-types-one-trait.stderr b/src/test/ui/associated-types/associated-types-multiple-types-one-trait.stderr
index c7de186c1d3..e3a2b5edf3f 100644
--- a/src/test/ui/associated-types/associated-types-multiple-types-one-trait.stderr
+++ b/src/test/ui/associated-types/associated-types-multiple-types-one-trait.stderr
@@ -2,28 +2,28 @@ error[E0271]: type mismatch resolving `<T as Foo>::Y == i32`
   --> $DIR/associated-types-multiple-types-one-trait.rs:13:5
    |
 LL |     want_y(t);
-   |     ^^^^^^ expected associated type, found i32
+   |     ^^^^^^ expected i32, found associated type
 ...
 LL | fn want_y<T:Foo<Y=i32>>(t: &T) { }
    |    ------       ----- required by this bound in `want_y`
    |
-   = note: expected type `<T as Foo>::Y`
-              found type `i32`
-   = note: consider constraining the associated type `<T as Foo>::Y` to `i32` or calling a method that returns `<T as Foo>::Y`
+   = note: expected type `i32`
+              found type `<T as Foo>::Y`
+   = note: consider constraining the associated type `<T as Foo>::Y` to `i32`
    = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
 
 error[E0271]: type mismatch resolving `<T as Foo>::X == u32`
   --> $DIR/associated-types-multiple-types-one-trait.rs:18:5
    |
 LL |     want_x(t);
-   |     ^^^^^^ expected associated type, found u32
+   |     ^^^^^^ expected u32, found associated type
 ...
 LL | fn want_x<T:Foo<X=u32>>(t: &T) { }
    |    ------       ----- required by this bound in `want_x`
    |
-   = note: expected type `<T as Foo>::X`
-              found type `u32`
-   = note: consider constraining the associated type `<T as Foo>::X` to `u32` or calling a method that returns `<T as Foo>::X`
+   = note: expected type `u32`
+              found type `<T as Foo>::X`
+   = note: consider constraining the associated type `<T as Foo>::X` to `u32`
    = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
 
 error: aborting due to 2 previous errors
diff --git a/src/test/ui/associated-types/associated-types-overridden-binding-2.stderr b/src/test/ui/associated-types/associated-types-overridden-binding-2.stderr
index aff067c2891..02a6ac12dd9 100644
--- a/src/test/ui/associated-types/associated-types-overridden-binding-2.stderr
+++ b/src/test/ui/associated-types/associated-types-overridden-binding-2.stderr
@@ -2,10 +2,10 @@ error[E0271]: type mismatch resolving `<std::vec::IntoIter<u32> as std::iter::It
   --> $DIR/associated-types-overridden-binding-2.rs:6:43
    |
 LL |     let _: &dyn I32Iterator<Item = u32> = &vec![42].into_iter();
-   |                                           ^^^^^^^^^^^^^^^^^^^^^ expected u32, found i32
+   |                                           ^^^^^^^^^^^^^^^^^^^^^ expected i32, found u32
    |
-   = note: expected type `u32`
-              found type `i32`
+   = note: expected type `i32`
+              found type `u32`
    = note: required for the cast to the object type `dyn std::iter::Iterator<Item = u32, Item = i32>`
 
 error: aborting due to previous error
diff --git a/src/test/ui/async-await/async-block-control-flow-static-semantics.stderr b/src/test/ui/async-await/async-block-control-flow-static-semantics.stderr
index a9b0e7ae779..6bef9dca265 100644
--- a/src/test/ui/async-await/async-block-control-flow-static-semantics.stderr
+++ b/src/test/ui/async-await/async-block-control-flow-static-semantics.stderr
@@ -33,10 +33,10 @@ error[E0271]: type mismatch resolving `<impl std::future::Future as std::future:
   --> $DIR/async-block-control-flow-static-semantics.rs:18:39
    |
 LL |     let _: &dyn Future<Output = ()> = &block;
-   |                                       ^^^^^^ expected u8, found ()
+   |                                       ^^^^^^ expected (), found u8
    |
-   = note: expected type `u8`
-              found type `()`
+   = note: expected type `()`
+              found type `u8`
    = note: required for the cast to the object type `dyn std::future::Future<Output = ()>`
 
 error[E0308]: mismatched types
@@ -59,10 +59,10 @@ error[E0271]: type mismatch resolving `<impl std::future::Future as std::future:
   --> $DIR/async-block-control-flow-static-semantics.rs:27:39
    |
 LL |     let _: &dyn Future<Output = ()> = &block;
-   |                                       ^^^^^^ expected u8, found ()
+   |                                       ^^^^^^ expected (), found u8
    |
-   = note: expected type `u8`
-              found type `()`
+   = note: expected type `()`
+              found type `u8`
    = note: required for the cast to the object type `dyn std::future::Future<Output = ()>`
 
 error[E0308]: mismatched types
diff --git a/src/test/ui/error-codes/E0271.stderr b/src/test/ui/error-codes/E0271.stderr
index c56853f45a0..378e5e36306 100644
--- a/src/test/ui/error-codes/E0271.stderr
+++ b/src/test/ui/error-codes/E0271.stderr
@@ -5,10 +5,10 @@ LL | fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
    |    ---                         ------------------ required by this bound in `foo`
 ...
 LL |     foo(3_i8);
-   |     ^^^ expected reference, found u32
+   |     ^^^ expected u32, found reference
    |
-   = note: expected type `&'static str`
-              found type `u32`
+   = note: expected type `u32`
+              found type `&'static str`
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/issues/issue-24204.stderr b/src/test/ui/issues/issue-24204.stderr
index 9658f6980be..9c53c1b86ce 100644
--- a/src/test/ui/issues/issue-24204.stderr
+++ b/src/test/ui/issues/issue-24204.stderr
@@ -5,10 +5,10 @@ LL | trait Trait: Sized {
    | ------------------ required by `Trait`
 ...
 LL | fn test<T: Trait<B=i32>>(b: i32) -> T where T::A: MultiDispatch<i32> { T::new(b) }
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found type parameter
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter, found associated type
    |
-   = note: expected type `<<T as Trait>::A as MultiDispatch<i32>>::O`
-              found type `T`
+   = note: expected type `T`
+              found type `<<T as Trait>::A as MultiDispatch<i32>>::O`
    = note: you might be missing a type parameter or trait bound
 
 error: aborting due to previous error