Skip to content

Commit

Permalink
switch compare_method to new-style trait error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
arielb1 committed Jul 22, 2016
1 parent cea88eb commit b7b2db4
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 25 deletions.
21 changes: 11 additions & 10 deletions src/librustc_typeck/check/compare_method.rs
Expand Up @@ -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
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
}
});
}
5 changes: 2 additions & 3 deletions src/test/compile-fail/associated-const-impl-wrong-type.rs
Expand Up @@ -18,9 +18,8 @@ struct SignedBar;

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() {}
4 changes: 3 additions & 1 deletion src/test/compile-fail/issue-13033.rs
Expand Up @@ -16,7 +16,9 @@ struct Baz;

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() {}
4 changes: 2 additions & 2 deletions src/test/compile-fail/issue-15094.rs
Expand Up @@ -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);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail/issue-21332.rs
Expand Up @@ -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() {}
3 changes: 0 additions & 3 deletions src/test/compile-fail/issue-24356.rs
Expand Up @@ -30,9 +30,6 @@ fn main() {
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);
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/trait-impl-method-mismatch.rs
Expand Up @@ -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() {}
4 changes: 2 additions & 2 deletions src/test/compile-fail/unsafe-trait-impl.rs
Expand Up @@ -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() { }

0 comments on commit b7b2db4

Please sign in to comment.