diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index baa389319ca72..7ebdb876ed02f 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1274,6 +1274,8 @@ fn check_impl_items_against_trait<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_id: DefId, impl_trait_ref: ty::TraitRef<'tcx>, impl_item_refs: &[hir::ImplItemRef]) { + let impl_span = tcx.sess.codemap().def_span(impl_span); + // If the trait reference itself is erroneous (so the compilation is going // to fail), skip checking the items here -- the `impl_item` table in `tcx` // isn't populated for such impls. diff --git a/src/test/ui/impl-trait/trait_type.stderr b/src/test/ui/impl-trait/trait_type.stderr index 42e1dcdb1c42a..7a0d01a8ec215 100644 --- a/src/test/ui/impl-trait/trait_type.stderr +++ b/src/test/ui/impl-trait/trait_type.stderr @@ -27,7 +27,7 @@ error[E0046]: not all trait items implemented, missing: `fmt` --> $DIR/trait_type.rs:31:1 | 31 | impl std::fmt::Display for MyType4 {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `fmt` in implementation + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `fmt` in implementation | = note: `fmt` from trait: `fn(&Self, &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error>` diff --git a/src/test/ui/missing-items/m2.stderr b/src/test/ui/missing-items/m2.stderr index 47164a5304abb..8c57214ec771f 100644 --- a/src/test/ui/missing-items/m2.stderr +++ b/src/test/ui/missing-items/m2.stderr @@ -3,9 +3,8 @@ error[E0601]: main function not found error[E0046]: not all trait items implemented, missing: `CONSTANT`, `Type`, `method` --> $DIR/m2.rs:19:1 | -19 | / impl m1::X for X { //~ ERROR not all trait items implemented -20 | | } - | |_^ missing `CONSTANT`, `Type`, `method` in implementation +19 | impl m1::X for X { //~ ERROR not all trait items implemented + | ^^^^^^^^^^^^^^^^ missing `CONSTANT`, `Type`, `method` in implementation | = note: `CONSTANT` from trait: `const CONSTANT: u32;` = note: `Type` from trait: `type Type;` diff --git a/src/test/ui/span/E0046.stderr b/src/test/ui/span/E0046.stderr index cd963de441b5f..fb13f21fe00f7 100644 --- a/src/test/ui/span/E0046.stderr +++ b/src/test/ui/span/E0046.stderr @@ -5,7 +5,7 @@ error[E0046]: not all trait items implemented, missing: `foo` | --------- `foo` from trait ... 17 | impl Foo for Bar {} - | ^^^^^^^^^^^^^^^^^^^ missing `foo` in implementation + | ^^^^^^^^^^^^^^^^ missing `foo` in implementation error: aborting due to previous error diff --git a/src/test/ui/span/impl-wrong-item-for-trait.stderr b/src/test/ui/span/impl-wrong-item-for-trait.stderr index 92993e192650e..6473b24dec5b3 100644 --- a/src/test/ui/span/impl-wrong-item-for-trait.stderr +++ b/src/test/ui/span/impl-wrong-item-for-trait.stderr @@ -16,16 +16,11 @@ error[E0323]: item `bar` is an associated const, which doesn't match its trait ` error[E0046]: not all trait items implemented, missing: `bar` --> $DIR/impl-wrong-item-for-trait.rs:21:1 | -15 | fn bar(&self); - | -------------- `bar` from trait +15 | fn bar(&self); + | -------------- `bar` from trait ... -21 | / impl Foo for FooConstForMethod { -22 | | //~^ ERROR E0046 -23 | | const bar: u64 = 1; -24 | | //~^ ERROR E0323 -25 | | const MY_CONST: u32 = 1; -26 | | } - | |_^ missing `bar` in implementation +21 | impl Foo for FooConstForMethod { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `bar` in implementation error[E0324]: item `MY_CONST` is an associated method, which doesn't match its trait `Foo` --> $DIR/impl-wrong-item-for-trait.rs:33:5 @@ -39,16 +34,11 @@ error[E0324]: item `MY_CONST` is an associated method, which doesn't match its t error[E0046]: not all trait items implemented, missing: `MY_CONST` --> $DIR/impl-wrong-item-for-trait.rs:30:1 | -16 | const MY_CONST: u32; - | -------------------- `MY_CONST` from trait +16 | const MY_CONST: u32; + | -------------------- `MY_CONST` from trait ... -30 | / impl Foo for FooMethodForConst { -31 | | //~^ ERROR E0046 -32 | | fn bar(&self) {} -33 | | fn MY_CONST() {} -34 | | //~^ ERROR E0324 -35 | | } - | |_^ missing `MY_CONST` in implementation +30 | impl Foo for FooMethodForConst { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `MY_CONST` in implementation error[E0325]: item `bar` is an associated type, which doesn't match its trait `Foo` --> $DIR/impl-wrong-item-for-trait.rs:41:5 @@ -62,24 +52,17 @@ error[E0325]: item `bar` is an associated type, which doesn't match its trait `F error[E0046]: not all trait items implemented, missing: `bar` --> $DIR/impl-wrong-item-for-trait.rs:39:1 | -15 | fn bar(&self); - | -------------- `bar` from trait +15 | fn bar(&self); + | -------------- `bar` from trait ... -39 | / impl Foo for FooTypeForMethod { -40 | | //~^ ERROR E0046 -41 | | type bar = u64; -42 | | //~^ ERROR E0325 -43 | | //~| ERROR E0437 -44 | | const MY_CONST: u32 = 1; -45 | | } - | |_^ missing `bar` in implementation +39 | impl Foo for FooTypeForMethod { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `bar` in implementation error[E0046]: not all trait items implemented, missing: `fmt` --> $DIR/impl-wrong-item-for-trait.rs:47:1 | -47 | / impl Debug for FooTypeForMethod { -48 | | } - | |_^ missing `fmt` in implementation +47 | impl Debug for FooTypeForMethod { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `fmt` in implementation | = note: `fmt` from trait: `fn(&Self, &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error>` diff --git a/src/test/ui/span/issue-23729.stderr b/src/test/ui/span/issue-23729.stderr index 0124d33635c47..60bf804ff30c4 100644 --- a/src/test/ui/span/issue-23729.stderr +++ b/src/test/ui/span/issue-23729.stderr @@ -1,14 +1,8 @@ error[E0046]: not all trait items implemented, missing: `Item` --> $DIR/issue-23729.rs:20:9 | -20 | / impl Iterator for Recurrence { -21 | | //~^ ERROR E0046 -22 | | #[inline] -23 | | fn next(&mut self) -> Option { -... | -34 | | } -35 | | } - | |_________^ missing `Item` in implementation +20 | impl Iterator for Recurrence { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Item` in implementation | = note: `Item` from trait: `type Item;` diff --git a/src/test/ui/span/issue-23827.stderr b/src/test/ui/span/issue-23827.stderr index acf499e4c8dde..d06d6c03616e3 100644 --- a/src/test/ui/span/issue-23827.stderr +++ b/src/test/ui/span/issue-23827.stderr @@ -1,13 +1,8 @@ error[E0046]: not all trait items implemented, missing: `Output` --> $DIR/issue-23827.rs:36:1 | -36 | / impl FnOnce<(C,)> for Prototype { -37 | | //~^ ERROR E0046 -38 | | extern "rust-call" fn call_once(self, (comp,): (C,)) -> Prototype { -39 | | Fn::call(&self, (comp,)) -40 | | } -41 | | } - | |_^ missing `Output` in implementation +36 | impl FnOnce<(C,)> for Prototype { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Output` in implementation | = note: `Output` from trait: `type Output;` diff --git a/src/test/ui/span/issue-24356.stderr b/src/test/ui/span/issue-24356.stderr index c526a4bc521c4..58fb943fef827 100644 --- a/src/test/ui/span/issue-24356.stderr +++ b/src/test/ui/span/issue-24356.stderr @@ -1,11 +1,8 @@ error[E0046]: not all trait items implemented, missing: `Target` --> $DIR/issue-24356.rs:30:9 | -30 | / impl Deref for Thing { -31 | | //~^ ERROR E0046 -32 | | fn deref(&self) -> i8 { self.0 } -33 | | } - | |_________^ missing `Target` in implementation +30 | impl Deref for Thing { + | ^^^^^^^^^^^^^^^^^^^^ missing `Target` in implementation | = note: `Target` from trait: `type Target;`