about summary refs log tree commit diff
diff options
context:
space:
mode:
authormibac138 <5672750+mibac138@users.noreply.github.com>2021-05-05 18:59:37 +0200
committermibac138 <5672750+mibac138@users.noreply.github.com>2021-05-05 18:59:37 +0200
commit693e9579bc796e5a8f38f58563e20d3cc1c21ce3 (patch)
tree4608cb7c130fa492dcdb29e96de74548bbbaae51
parent24acc388da2cdbe1ec79b6933402941b6fffb26b (diff)
downloadrust-693e9579bc796e5a8f38f58563e20d3cc1c21ce3.tar.gz
rust-693e9579bc796e5a8f38f58563e20d3cc1c21ce3.zip
Suggest adding a type parameter for impls
-rw-r--r--compiler/rustc_resolve/src/late/diagnostics.rs10
-rw-r--r--src/test/ui/const-generics/diagnostics.stderr22
-rw-r--r--src/test/ui/traits/issue-75627.stderr4
-rw-r--r--src/test/ui/traits/issue-78372.stderr11
4 files changed, 39 insertions, 8 deletions
diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs
index 7561b3df3af..a4bf19aab95 100644
--- a/compiler/rustc_resolve/src/late/diagnostics.rs
+++ b/compiler/rustc_resolve/src/late/diagnostics.rs
@@ -1600,8 +1600,8 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
         if !self.diagnostic_metadata.currently_processing_generics && !single_uppercase_char {
             return None;
         }
-        match (self.diagnostic_metadata.current_item, single_uppercase_char) {
-            (Some(Item { kind: ItemKind::Fn(..), ident, .. }), _) if ident.name == sym::main => {
+        match (self.diagnostic_metadata.current_item, single_uppercase_char, self.diagnostic_metadata.currently_processing_generics) {
+            (Some(Item { kind: ItemKind::Fn(..), ident, .. }), _, _) if ident.name == sym::main => {
                 // Ignore `fn main()` as we don't want to suggest `fn main<T>()`
             }
             (
@@ -1613,9 +1613,11 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
                         | kind @ ItemKind::Union(..),
                     ..
                 }),
-                true,
+                true, _
             )
-            | (Some(Item { kind, .. }), false) => {
+            // Without the 2nd `true`, we'd suggest `impl <T>` for `impl T` when a type `T` isn't found
+            | (Some(Item { kind: kind @ ItemKind::Impl(..), .. }), true, true)
+            | (Some(Item { kind, .. }), false, _) => {
                 // Likely missing type parameter.
                 if let Some(generics) = kind.generics() {
                     if span.overlaps(generics.span) {
diff --git a/src/test/ui/const-generics/diagnostics.stderr b/src/test/ui/const-generics/diagnostics.stderr
index c8ee6ad61ec..983cb52f3ff 100644
--- a/src/test/ui/const-generics/diagnostics.stderr
+++ b/src/test/ui/const-generics/diagnostics.stderr
@@ -5,7 +5,16 @@ LL | struct A<const N: u8>;
    | ---------------------- similarly named struct `A` defined here
 LL | trait Foo {}
 LL | impl Foo for A<N> {}
-   |                ^ help: a struct with a similar name exists: `A`
+   |                ^
+   |
+help: a struct with a similar name exists
+   |
+LL | impl Foo for A<A> {}
+   |                ^
+help: you might be missing a type parameter
+   |
+LL | impl<N> Foo for A<N> {}
+   |     ^^^
 
 error[E0412]: cannot find type `T` in this scope
   --> $DIR/diagnostics.rs:16:32
@@ -14,7 +23,16 @@ LL | struct A<const N: u8>;
    | ---------------------- similarly named struct `A` defined here
 ...
 LL | impl<const N: u8> Foo for C<N, T> {}
-   |                                ^ help: a struct with a similar name exists: `A`
+   |                                ^
+   |
+help: a struct with a similar name exists
+   |
+LL | impl<const N: u8> Foo for C<N, A> {}
+   |                                ^
+help: you might be missing a type parameter
+   |
+LL | impl<const N, T: u8> Foo for C<N, T> {}
+   |             ^^^
 
 error[E0747]: unresolved item provided when a constant was expected
   --> $DIR/diagnostics.rs:7:16
diff --git a/src/test/ui/traits/issue-75627.stderr b/src/test/ui/traits/issue-75627.stderr
index 92d9ac0f84c..432ddf2dcdb 100644
--- a/src/test/ui/traits/issue-75627.stderr
+++ b/src/test/ui/traits/issue-75627.stderr
@@ -2,7 +2,9 @@ error[E0412]: cannot find type `T` in this scope
   --> $DIR/issue-75627.rs:3:26
    |
 LL | unsafe impl Send for Foo<T> {}
-   |                          ^ not found in this scope
+   |            -             ^ not found in this scope
+   |            |
+   |            help: you might be missing a type parameter: `<T>`
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/traits/issue-78372.stderr b/src/test/ui/traits/issue-78372.stderr
index 9267e838cea..e63740c4ea9 100644
--- a/src/test/ui/traits/issue-78372.stderr
+++ b/src/test/ui/traits/issue-78372.stderr
@@ -13,9 +13,18 @@ error[E0412]: cannot find type `U` in this scope
   --> $DIR/issue-78372.rs:3:31
    |
 LL | impl<T> DispatchFromDyn<Smaht<U, MISC>> for T {}
-   |      -                        ^ help: a type parameter with a similar name exists: `T`
+   |      -                        ^
    |      |
    |      similarly named type parameter `T` defined here
+   |
+help: a type parameter with a similar name exists
+   |
+LL | impl<T> DispatchFromDyn<Smaht<T, MISC>> for T {}
+   |                               ^
+help: you might be missing a type parameter
+   |
+LL | impl<T, U> DispatchFromDyn<Smaht<U, MISC>> for T {}
+   |       ^^^
 
 error[E0412]: cannot find type `MISC` in this scope
   --> $DIR/issue-78372.rs:3:34