about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-04-19 17:47:33 +0000
committerMichael Goulet <michael@errs.io>2023-04-19 23:37:41 +0000
commitf362f6e9e6cb5d55bbac6a94353209c3e3a2ebb5 (patch)
treeb72fbddb642c4573dfd7f2f2858b49d50e9ac9d3
parent73038d3a640f563e47554d781e958f6e4ed08bc2 (diff)
downloadrust-f362f6e9e6cb5d55bbac6a94353209c3e3a2ebb5.tar.gz
rust-f362f6e9e6cb5d55bbac6a94353209c3e3a2ebb5.zip
Format missing GATs correctly
-rw-r--r--compiler/rustc_hir_analysis/src/check/mod.rs8
-rw-r--r--tests/ui/generic-associated-types/auxiliary/missing-item-sugg.rs5
-rw-r--r--tests/ui/generic-associated-types/missing-item-sugg.rs11
-rw-r--r--tests/ui/generic-associated-types/missing-item-sugg.stderr11
-rw-r--r--tests/ui/suggestions/missing-assoc-fn-applicable-suggestions.stderr2
5 files changed, 35 insertions, 2 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs
index 9fba538f12e..4b3f3cf169d 100644
--- a/compiler/rustc_hir_analysis/src/check/mod.rs
+++ b/compiler/rustc_hir_analysis/src/check/mod.rs
@@ -466,7 +466,13 @@ fn suggestion_signature<'tcx>(
                 assoc,
             )
         }
-        ty::AssocKind::Type => format!("type {} = /* Type */;", assoc.name),
+        ty::AssocKind::Type => {
+            let (generics, where_clauses) = bounds_from_generic_predicates(
+                tcx,
+                tcx.predicates_of(assoc.def_id).instantiate_own(tcx, substs),
+            );
+            format!("type {}{generics} = /* Type */{where_clauses};", assoc.name)
+        }
         ty::AssocKind::Const => {
             let ty = tcx.type_of(assoc.def_id).subst_identity();
             let val = ty_kind_suggestion(ty).unwrap_or("todo!()");
diff --git a/tests/ui/generic-associated-types/auxiliary/missing-item-sugg.rs b/tests/ui/generic-associated-types/auxiliary/missing-item-sugg.rs
new file mode 100644
index 00000000000..5b10aab4b3f
--- /dev/null
+++ b/tests/ui/generic-associated-types/auxiliary/missing-item-sugg.rs
@@ -0,0 +1,5 @@
+pub trait Foo {
+    type Gat<T>
+    where
+        T: std::fmt::Display;
+}
diff --git a/tests/ui/generic-associated-types/missing-item-sugg.rs b/tests/ui/generic-associated-types/missing-item-sugg.rs
new file mode 100644
index 00000000000..35d573d8188
--- /dev/null
+++ b/tests/ui/generic-associated-types/missing-item-sugg.rs
@@ -0,0 +1,11 @@
+// aux-build:missing-item-sugg.rs
+
+extern crate missing_item_sugg;
+
+struct Local;
+impl missing_item_sugg::Foo for Local {
+    //~^ ERROR not all trait items implemented, missing: `Gat`
+}
+//~^ HELP implement the missing item: `type Gat<T> = /* Type */ where T: std::fmt::Display;`
+
+fn main() {}
diff --git a/tests/ui/generic-associated-types/missing-item-sugg.stderr b/tests/ui/generic-associated-types/missing-item-sugg.stderr
new file mode 100644
index 00000000000..378115f6d38
--- /dev/null
+++ b/tests/ui/generic-associated-types/missing-item-sugg.stderr
@@ -0,0 +1,11 @@
+error[E0046]: not all trait items implemented, missing: `Gat`
+  --> $DIR/missing-item-sugg.rs:6:1
+   |
+LL | impl missing_item_sugg::Foo for Local {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Gat` in implementation
+   |
+   = help: implement the missing item: `type Gat<T> = /* Type */ where T: std::fmt::Display;`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0046`.
diff --git a/tests/ui/suggestions/missing-assoc-fn-applicable-suggestions.stderr b/tests/ui/suggestions/missing-assoc-fn-applicable-suggestions.stderr
index 657a5c546d3..4c2d2776d3d 100644
--- a/tests/ui/suggestions/missing-assoc-fn-applicable-suggestions.stderr
+++ b/tests/ui/suggestions/missing-assoc-fn-applicable-suggestions.stderr
@@ -1,7 +1,7 @@
 error[E0046]: not all trait items implemented, missing: `Type`, `bar`, `baz`, `A`
   --> $DIR/missing-assoc-fn-applicable-suggestions.rs:7:1
    |
-LL | impl TraitA<()> for S { 
+LL | impl TraitA<()> for S {
    | ^^^^^^^^^^^^^^^^^^^^^ missing `Type`, `bar`, `baz`, `A` in implementation
    |
    = help: implement the missing item: `type Type = /* Type */;`