Skip to content

Commit f362f6e

Browse files
Format missing GATs correctly
1 parent 73038d3 commit f362f6e

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

compiler/rustc_hir_analysis/src/check/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,13 @@ fn suggestion_signature<'tcx>(
466466
assoc,
467467
)
468468
}
469-
ty::AssocKind::Type => format!("type {} = /* Type */;", assoc.name),
469+
ty::AssocKind::Type => {
470+
let (generics, where_clauses) = bounds_from_generic_predicates(
471+
tcx,
472+
tcx.predicates_of(assoc.def_id).instantiate_own(tcx, substs),
473+
);
474+
format!("type {}{generics} = /* Type */{where_clauses};", assoc.name)
475+
}
470476
ty::AssocKind::Const => {
471477
let ty = tcx.type_of(assoc.def_id).subst_identity();
472478
let val = ty_kind_suggestion(ty).unwrap_or("todo!()");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub trait Foo {
2+
type Gat<T>
3+
where
4+
T: std::fmt::Display;
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// aux-build:missing-item-sugg.rs
2+
3+
extern crate missing_item_sugg;
4+
5+
struct Local;
6+
impl missing_item_sugg::Foo for Local {
7+
//~^ ERROR not all trait items implemented, missing: `Gat`
8+
}
9+
//~^ HELP implement the missing item: `type Gat<T> = /* Type */ where T: std::fmt::Display;`
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0046]: not all trait items implemented, missing: `Gat`
2+
--> $DIR/missing-item-sugg.rs:6:1
3+
|
4+
LL | impl missing_item_sugg::Foo for Local {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Gat` in implementation
6+
|
7+
= help: implement the missing item: `type Gat<T> = /* Type */ where T: std::fmt::Display;`
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0046`.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
error[E0046]: not all trait items implemented, missing: `Type`, `bar`, `baz`, `A`
22
--> $DIR/missing-assoc-fn-applicable-suggestions.rs:7:1
33
|
4-
LL | impl TraitA<()> for S {
4+
LL | impl TraitA<()> for S {
55
| ^^^^^^^^^^^^^^^^^^^^^ missing `Type`, `bar`, `baz`, `A` in implementation
66
|
77
= help: implement the missing item: `type Type = /* Type */;`

0 commit comments

Comments
 (0)