Skip to content

Commit 620d4cb

Browse files
committed
switch compare_method to new-style trait error reporting
1 parent 06d4f70 commit 620d4cb

8 files changed

+23
-25
lines changed

src/librustc_typeck/check/compare_method.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,10 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
324324
debug!("sub_types failed: impl ty {:?}, trait ty {:?}",
325325
impl_fty,
326326
trait_fty);
327-
span_err!(tcx.sess, impl_m_span, E0053,
328-
"method `{}` has an incompatible type for trait: {}",
329-
trait_m.name,
330-
terr);
327+
let trace = infer::TypeTrace::types(origin, false, impl_fty, trait_fty);
328+
type_err!(infcx, trace, &terr, E0053,
329+
"method `{}` has an incompatible type for trait",
330+
trait_m.name).emit();
331331
return
332332
}
333333

@@ -437,10 +437,9 @@ pub fn compare_const_impl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
437437
// Compute skolemized form of impl and trait const tys.
438438
let impl_ty = impl_c.ty.subst(tcx, impl_to_skol_substs);
439439
let trait_ty = trait_c.ty.subst(tcx, &trait_to_skol_substs);
440+
let origin = TypeOrigin::Misc(impl_c_span);
440441

441442
let err = infcx.commit_if_ok(|_| {
442-
let origin = TypeOrigin::Misc(impl_c_span);
443-
444443
// There is no "body" here, so just pass dummy id.
445444
let impl_ty =
446445
assoc::normalize_associated_types_in(&infcx,
@@ -473,11 +472,13 @@ pub fn compare_const_impl<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
473472
debug!("checking associated const for compatibility: impl ty {:?}, trait ty {:?}",
474473
impl_ty,
475474
trait_ty);
476-
span_err!(tcx.sess, impl_c_span, E0326,
475+
let values = Some(infer::ValuePairs::Types(ExpectedFound {
476+
expected: trait_ty,
477+
found: impl_ty
478+
}));
479+
type_err!(infcx, origin, values, terr, E0326,
477480
"implemented const `{}` has an incompatible type for \
478-
trait: {}",
479-
trait_c.name,
480-
terr);
481+
trait", trait_c.name).emit();
481482
}
482483
});
483484
}

src/test/compile-fail/associated-const-impl-wrong-type.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ struct SignedBar;
1818

1919
impl Foo for SignedBar {
2020
const BAR: i32 = -1;
21-
//~^ ERROR implemented const `BAR` has an incompatible type for trait
22-
//~| expected u32,
23-
//~| found i32 [E0326]
21+
//~^ ERROR implemented const `BAR` has an incompatible type for trait [E0326]
22+
//~| expected u32, found i32
2423
}
2524

2625
fn main() {}

src/test/compile-fail/issue-13033.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ struct Baz;
1616

1717
impl Foo for Baz {
1818
fn bar(&mut self, other: &Foo) {}
19-
//~^ ERROR method `bar` has an incompatible type for trait: values differ in mutability [E0053]
19+
//~^ ERROR method `bar` has an incompatible type for trait
20+
//~| expected type `fn(&mut Baz, &mut Foo)`
21+
//~| found type `fn(&mut Baz, &Foo)`
2022
}
2123

2224
fn main() {}

src/test/compile-fail/issue-15094.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ impl<T: fmt::Debug> ops::FnOnce<(),> for Debuger<T> {
2020
type Output = ();
2121
fn call_once(self, _args: ()) {
2222
//~^ ERROR `call_once` has an incompatible type for trait
23-
//~| expected "rust-call" fn,
24-
//~| found "Rust" fn
23+
//~| expected type `extern "rust-call" fn
24+
//~| found type `fn
2525
println!("{:?}", self.x);
2626
}
2727
}

src/test/compile-fail/issue-21332.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ impl Iterator for S {
1414
type Item = i32;
1515
fn next(&mut self) -> Result<i32, i32> { Ok(7) }
1616
//~^ ERROR method `next` has an incompatible type for trait
17-
//~| expected enum `std::option::Option`
18-
//~| found enum `std::result::Result` [E0053]
17+
//~| expected enum `std::option::Option`, found enum `std::result::Result`
1918
}
2019

2120
fn main() {}

src/test/compile-fail/issue-24356.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ fn main() {
3030
impl Deref for Thing {
3131
//~^ ERROR not all trait items implemented, missing: `Target` [E0046]
3232
fn deref(&self) -> i8 { self.0 }
33-
//~^ ERROR method `deref` has an incompatible type for trait
34-
//~| expected &-ptr
35-
//~| found i8 [E0053]
3633
}
3734

3835
let thing = Thing(72);

src/test/compile-fail/trait-impl-method-mismatch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ impl Mumbo for usize {
1717
// Cannot have a larger effect than the trait:
1818
unsafe fn jumbo(&self, x: &usize) { *self + *x; }
1919
//~^ ERROR method `jumbo` has an incompatible type for trait
20-
//~| expected normal fn,
21-
//~| found unsafe fn
20+
//~| expected type `fn
21+
//~| found type `unsafe fn
2222
}
2323

2424
fn main() {}

src/test/compile-fail/unsafe-trait-impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ trait Foo {
1717
impl Foo for u32 {
1818
fn len(&self) -> u32 { *self }
1919
//~^ ERROR method `len` has an incompatible type for trait
20-
//~| expected unsafe fn,
21-
//~| found normal fn
20+
//~| expected type `unsafe fn(&u32) -> u32`
21+
//~| found type `fn(&u32) -> u32`
2222
}
2323

2424
fn main() { }

0 commit comments

Comments
 (0)