Skip to content

Commit 73038d3

Browse files
Make missing impl item suggestions more obvious that they're missing
1 parent 204c516 commit 73038d3

File tree

10 files changed

+41
-51
lines changed

10 files changed

+41
-51
lines changed

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,10 @@ fn suggestion_signature<'tcx>(
466466
assoc,
467467
)
468468
}
469-
ty::AssocKind::Type => format!("type {} = Type;", assoc.name),
469+
ty::AssocKind::Type => format!("type {} = /* Type */;", assoc.name),
470470
ty::AssocKind::Const => {
471471
let ty = tcx.type_of(assoc.def_id).subst_identity();
472-
let val = ty_kind_suggestion(ty).unwrap_or("value");
472+
let val = ty_kind_suggestion(ty).unwrap_or("todo!()");
473473
format!("const {}: {} = {};", assoc.name, ty, val)
474474
}
475475
}

tests/ui/async-await/issue-74047.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0046]: not all trait items implemented, missing: `Error`, `try_from`
44
LL | impl TryFrom<OtherStream> for MyStream {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Error`, `try_from` in implementation
66
|
7-
= help: implement the missing item: `type Error = Type;`
7+
= help: implement the missing item: `type Error = /* Type */;`
88
= help: implement the missing item: `fn try_from(_: OtherStream) -> Result<Self, <Self as TryFrom<OtherStream>>::Error> { todo!() }`
99

1010
error: aborting due to previous error

tests/ui/missing/missing-items/m2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | impl m1::X for X {
55
| ^^^^^^^^^^^^^^^^ missing `CONSTANT`, `Type`, `method`, `method2`, `method3`, `method4`, `method5` in implementation
66
|
77
= help: implement the missing item: `const CONSTANT: u32 = 42;`
8-
= help: implement the missing item: `type Type = Type;`
8+
= help: implement the missing item: `type Type = /* Type */;`
99
= help: implement the missing item: `fn method(&self, _: String) -> <Self as m1::X>::Type { todo!() }`
1010
= help: implement the missing item: `fn method2(self: Box<Self>, _: String) -> <Self as m1::X>::Type { todo!() }`
1111
= help: implement the missing item: `fn method3(_: &Self, _: String) -> <Self as m1::X>::Type { todo!() }`

tests/ui/span/issue-23729.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0046]: not all trait items implemented, missing: `Item`
44
LL | impl Iterator for Recurrence {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Item` in implementation
66
|
7-
= help: implement the missing item: `type Item = Type;`
7+
= help: implement the missing item: `type Item = /* Type */;`
88

99
error: aborting due to previous error
1010

tests/ui/span/issue-23827.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0046]: not all trait items implemented, missing: `Output`
44
LL | impl<C: Component> FnOnce<(C,)> for Prototype {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Output` in implementation
66
|
7-
= help: implement the missing item: `type Output = Type;`
7+
= help: implement the missing item: `type Output = /* Type */;`
88

99
error: aborting due to previous error
1010

tests/ui/span/issue-24356.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0046]: not all trait items implemented, missing: `Target`
44
LL | impl Deref for Thing {
55
| ^^^^^^^^^^^^^^^^^^^^ missing `Target` in implementation
66
|
7-
= help: implement the missing item: `type Target = Type;`
7+
= help: implement the missing item: `type Target = /* Type */;`
88

99
error: aborting due to previous error
1010

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pub trait TraitB {
2+
type Item;
3+
}
4+
5+
pub trait TraitA<A> {
6+
type Type;
7+
8+
fn bar<T>(_: T) -> Self;
9+
10+
fn baz<T>(_: T) -> Self
11+
where
12+
T: TraitB,
13+
<T as TraitB>::Item: Copy;
14+
15+
const A: usize;
16+
}

tests/ui/suggestions/missing-assoc-fn-applicable-suggestions.fixed

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
// run-rustfix
2-
trait TraitB {
3-
type Item;
4-
}
1+
// aux-build:missing-assoc-fn-applicable-suggestions.rs
52

6-
trait TraitA<A> {
7-
type Type;
8-
fn bar<T>(_: T) -> Self;
9-
fn baz<T>(_: T) -> Self where T: TraitB, <T as TraitB>::Item: Copy;
10-
}
3+
extern crate missing_assoc_fn_applicable_suggestions;
4+
use missing_assoc_fn_applicable_suggestions::TraitA;
115

126
struct S;
13-
struct Type;
14-
15-
impl TraitA<()> for S { //~ ERROR not all trait items implemented
7+
impl TraitA<()> for S {
8+
//~^ ERROR not all trait items implemented
169
}
10+
//~^ HELP implement the missing item: `type Type = /* Type */;`
11+
//~| HELP implement the missing item: `fn bar<T>(_: T) -> Self { todo!() }`
12+
//~| HELP implement the missing item: `fn baz<T>(_: T) -> Self where T: TraitB, <T as TraitB>::Item: Copy { todo!() }`
13+
//~| HELP implement the missing item: `const A: usize = 42;`
1714

1815
fn main() {}

tests/ui/suggestions/missing-assoc-fn-applicable-suggestions.stderr

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
error[E0046]: not all trait items implemented, missing: `Type`, `bar`, `baz`
2-
--> $DIR/missing-assoc-fn-applicable-suggestions.rs:15:1
1+
error[E0046]: not all trait items implemented, missing: `Type`, `bar`, `baz`, `A`
2+
--> $DIR/missing-assoc-fn-applicable-suggestions.rs:7:1
33
|
4-
LL | type Type;
5-
| --------- `Type` from trait
6-
LL | fn bar<T>(_: T) -> Self;
7-
| ------------------------ `bar` from trait
8-
LL | fn baz<T>(_: T) -> Self where T: TraitB, <T as TraitB>::Item: Copy;
9-
| ------------------------------------------------------------------- `baz` from trait
10-
...
11-
LL | impl TraitA<()> for S {
12-
| ^^^^^^^^^^^^^^^^^^^^^ missing `Type`, `bar`, `baz` in implementation
4+
LL | impl TraitA<()> for S {
5+
| ^^^^^^^^^^^^^^^^^^^^^ missing `Type`, `bar`, `baz`, `A` in implementation
6+
|
7+
= help: implement the missing item: `type Type = /* Type */;`
8+
= help: implement the missing item: `fn bar<T>(_: T) -> Self { todo!() }`
9+
= help: implement the missing item: `fn baz<T>(_: T) -> Self where T: TraitB, <T as TraitB>::Item: Copy { todo!() }`
10+
= help: implement the missing item: `const A: usize = 42;`
1311

1412
error: aborting due to previous error
1513

0 commit comments

Comments
 (0)