]> git.lizzy.rs Git - rust.git/commitdiff
switch compare_method to new-style trait error reporting
authorAriel Ben-Yehuda <ariel.byd@gmail.com>
Mon, 18 Jul 2016 20:13:34 +0000 (23:13 +0300)
committerAriel Ben-Yehuda <ariel.byd@gmail.com>
Fri, 22 Jul 2016 11:32:56 +0000 (14:32 +0300)
src/librustc_typeck/check/compare_method.rs
src/test/compile-fail/associated-const-impl-wrong-type.rs
src/test/compile-fail/issue-13033.rs
src/test/compile-fail/issue-15094.rs
src/test/compile-fail/issue-21332.rs
src/test/compile-fail/issue-24356.rs
src/test/compile-fail/trait-impl-method-mismatch.rs
src/test/compile-fail/unsafe-trait-impl.rs

index 35a5bc9c60967d69512b3b573d26b903e59ce187..847dcc90ad395fdd3202a617ebbf955c08d863f6 100644 (file)
@@ -324,10 +324,10 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
             debug!("sub_types failed: impl ty {:?}, trait ty {:?}",
                    impl_fty,
                    trait_fty);
-            span_err!(tcx.sess, impl_m_span, E0053,
-                      "method `{}` has an incompatible type for trait: {}",
-                      trait_m.name,
-                      terr);
+            let trace = infer::TypeTrace::types(origin, false, impl_fty, trait_fty);
+            type_err!(infcx, trace, &terr, E0053,
+                      "method `{}` has an incompatible type for trait",
+                      trait_m.name).emit();
             return
         }
 
@@ -437,10 +437,9 @@ pub fn compare_const_impl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
         // Compute skolemized form of impl and trait const tys.
         let impl_ty = impl_c.ty.subst(tcx, impl_to_skol_substs);
         let trait_ty = trait_c.ty.subst(tcx, &trait_to_skol_substs);
+        let origin = TypeOrigin::Misc(impl_c_span);
 
         let err = infcx.commit_if_ok(|_| {
-            let origin = TypeOrigin::Misc(impl_c_span);
-
             // There is no "body" here, so just pass dummy id.
             let impl_ty =
                 assoc::normalize_associated_types_in(&infcx,
@@ -473,11 +472,13 @@ pub fn compare_const_impl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
             debug!("checking associated const for compatibility: impl ty {:?}, trait ty {:?}",
                    impl_ty,
                    trait_ty);
-            span_err!(tcx.sess, impl_c_span, E0326,
+            let values = Some(infer::ValuePairs::Types(ExpectedFound {
+                expected: trait_ty,
+                found: impl_ty
+            }));
+            type_err!(infcx, origin, values, terr, E0326,
                       "implemented const `{}` has an incompatible type for \
-                      trait: {}",
-                      trait_c.name,
-                      terr);
+                      trait", trait_c.name).emit();
         }
     });
 }
index 4658d0f057d71c85aeeab2c9040bf4fd2c92bf40..95508a31044b87797dff021bc5a6a07b23cd2ff9 100644 (file)
@@ -18,9 +18,8 @@ trait Foo {
 
 impl Foo for SignedBar {
     const BAR: i32 = -1;
-    //~^ ERROR implemented const `BAR` has an incompatible type for trait
-    //~| expected u32,
-    //~| found i32 [E0326]
+    //~^ ERROR implemented const `BAR` has an incompatible type for trait [E0326]
+    //~| expected u32, found i32
 }
 
 fn main() {}
index 43cf70e5bc3cf086cefb00fcac577b41ec5ac266..3d9d81471cb1e40da806c9348464d193ff9cfa98 100644 (file)
@@ -16,7 +16,9 @@ trait Foo {
 
 impl Foo for Baz {
     fn bar(&mut self, other: &Foo) {}
-    //~^ ERROR method `bar` has an incompatible type for trait: values differ in mutability [E0053]
+    //~^ ERROR method `bar` has an incompatible type for trait
+    //~| expected type `fn(&mut Baz, &mut Foo)`
+    //~| found type `fn(&mut Baz, &Foo)`
 }
 
 fn main() {}
index 42e3456b309be35585a6ed39181eaebbb63aa745..da48bbb3ecd711a99a730cf859ec74f17bc9cc06 100644 (file)
@@ -20,8 +20,8 @@ impl<T: fmt::Debug> ops::FnOnce<(),> for Debuger<T> {
     type Output = ();
     fn call_once(self, _args: ()) {
     //~^ ERROR `call_once` has an incompatible type for trait
-    //~| expected "rust-call" fn,
-    //~| found "Rust" fn
+    //~| expected type `extern "rust-call" fn
+    //~| found type `fn
         println!("{:?}", self.x);
     }
 }
index b36918149fa99008b7fd5d7560a63ad82081b759..db3334834d44ec97e5230755df303f1f2e0b4a65 100644 (file)
@@ -14,8 +14,7 @@ impl Iterator for S {
     type Item = i32;
     fn next(&mut self) -> Result<i32, i32> { Ok(7) }
     //~^ ERROR method `next` has an incompatible type for trait
-    //~| expected enum `std::option::Option`
-    //~|    found enum `std::result::Result` [E0053]
+    //~| expected enum `std::option::Option`, found enum `std::result::Result`
 }
 
 fn main() {}
index 27d46be40fbeb69bbe96b617eff5dce36c28d484..ede81bea32ae3bfaea3db5168a4ea23f2ed19a1d 100644 (file)
@@ -30,9 +30,6 @@ fn deref(&self) -> &i8 { &self.0 }
         impl Deref for Thing {
             //~^ ERROR not all trait items implemented, missing: `Target` [E0046]
             fn deref(&self) -> i8 { self.0 }
-            //~^ ERROR method `deref` has an incompatible type for trait
-            //~| expected &-ptr
-            //~| found i8 [E0053]
         }
 
         let thing = Thing(72);
index f86d9b7648bbebfd19a2f9740fffdb0ad394c106..a05e007d6b7393e5774e44d76904c35b39fb3243 100644 (file)
@@ -17,8 +17,8 @@ impl Mumbo for usize {
     // Cannot have a larger effect than the trait:
     unsafe fn jumbo(&self, x: &usize) { *self + *x; }
     //~^ ERROR method `jumbo` has an incompatible type for trait
-    //~| expected normal fn,
-    //~| found unsafe fn
+    //~| expected type `fn
+    //~| found type `unsafe fn
 }
 
 fn main() {}
index 51f876661f6510834a4dfd78ea2ea39a770b5440..fb4652affd0d8c3ce6c8ce7f7023b57f447c3137 100644 (file)
@@ -17,8 +17,8 @@ trait Foo {
 impl Foo for u32 {
     fn len(&self) -> u32 { *self }
     //~^ ERROR method `len` has an incompatible type for trait
-    //~| expected unsafe fn,
-    //~| found normal fn
+    //~| expected type `unsafe fn(&u32) -> u32`
+    //~| found type `fn(&u32) -> u32`
 }
 
 fn main() { }