about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_hir_analysis/src/astconv/errors.rs44
-rw-r--r--tests/ui/associated-consts/assoc-const-eq-missing.stderr12
-rw-r--r--tests/ui/associated-type-bounds/missing-trait-bound-for-assoc-fails.stderr4
-rw-r--r--tests/ui/associated-types/associated-types-path-1.stderr4
-rw-r--r--tests/ui/feature-gates/feature-gate-return_type_notation.cfg.stderr4
-rw-r--r--tests/ui/feature-gates/feature-gate-return_type_notation.cfg_current.stderr4
-rw-r--r--tests/ui/feature-gates/feature-gate-return_type_notation.cfg_next.stderr4
7 files changed, 27 insertions, 49 deletions
diff --git a/compiler/rustc_hir_analysis/src/astconv/errors.rs b/compiler/rustc_hir_analysis/src/astconv/errors.rs
index 26bd3b0f6a9..ed4dde419c4 100644
--- a/compiler/rustc_hir_analysis/src/astconv/errors.rs
+++ b/compiler/rustc_hir_analysis/src/astconv/errors.rs
@@ -201,33 +201,27 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
             }
         }
 
-        // If we still couldn't find any associated type, just list them all.
-
-        if all_candidate_names.is_empty() {
-            err.help(format!(
-                "`{ty_param_name}` has no associated type, try removing `{assoc_name}`"
-            ));
-            return err.emit();
-        }
-
-        let msg = if all_candidate_names.len() > 1 {
-            format!("`{ty_param_name}` has the following associated types")
-        } else {
-            format!("`{ty_param_name}` has the following associated type")
-        };
+        // If we still couldn't find any associated type, and only one associated type exists,
+        // suggests using it.
+
+        if all_candidate_names.len() == 1 {
+            // this should still compile, except on `#![feature(associated_type_defaults)]`
+            // where it could suggests `type A = Self::A`, thus recursing infinitely
+            let applicability = if self.tcx().features().associated_type_defaults {
+                Applicability::Unspecified
+            } else {
+                Applicability::MaybeIncorrect
+            };
 
-        let applicability = if self.tcx().features().associated_type_defaults {
-            Applicability::Unspecified // `type A = Self::B` would suggest `type A = Self::A`
+            err.span_suggestion(
+                assoc_name.span,
+                format!("`{ty_param_name}` has the following associated type"),
+                all_candidate_names.first().unwrap().to_string(),
+                applicability,
+            );
         } else {
-            Applicability::MaybeIncorrect
-        };
-
-        err.span_suggestions(
-            assoc_name.span,
-            msg,
-            all_candidate_names.iter().map(|symbol| symbol.to_string()),
-            applicability,
-        );
+            err.span_label(assoc_name.span, format!("associated type `{assoc_name}` not found"));
+        }
 
         err.emit()
     }
diff --git a/tests/ui/associated-consts/assoc-const-eq-missing.stderr b/tests/ui/associated-consts/assoc-const-eq-missing.stderr
index 9cd3865fc3b..b4bd6456c85 100644
--- a/tests/ui/associated-consts/assoc-const-eq-missing.stderr
+++ b/tests/ui/associated-consts/assoc-const-eq-missing.stderr
@@ -2,25 +2,19 @@ error[E0220]: associated type `Z` not found for `Foo`
   --> $DIR/assoc-const-eq-missing.rs:15:16
    |
 LL | fn foo1<F: Foo<Z=3>>() {}
-   |                ^
-   |
-   = help: `Foo` has no associated type, try removing `Z`
+   |                ^ associated type `Z` not found
 
 error[E0220]: associated type `Z` not found for `Foo`
   --> $DIR/assoc-const-eq-missing.rs:17:16
    |
 LL | fn foo2<F: Foo<Z=usize>>() {}
-   |                ^
-   |
-   = help: `Foo` has no associated type, try removing `Z`
+   |                ^ associated type `Z` not found
 
 error[E0220]: associated type `Z` not found for `Foo`
   --> $DIR/assoc-const-eq-missing.rs:19:16
    |
 LL | fn foo3<F: Foo<Z=5>>() {}
-   |                ^
-   |
-   = help: `Foo` has no associated type, try removing `Z`
+   |                ^ associated type `Z` not found
 
 error: aborting due to 3 previous errors
 
diff --git a/tests/ui/associated-type-bounds/missing-trait-bound-for-assoc-fails.stderr b/tests/ui/associated-type-bounds/missing-trait-bound-for-assoc-fails.stderr
index a964c9df2c5..bc2807b0396 100644
--- a/tests/ui/associated-type-bounds/missing-trait-bound-for-assoc-fails.stderr
+++ b/tests/ui/associated-type-bounds/missing-trait-bound-for-assoc-fails.stderr
@@ -8,9 +8,7 @@ error[E0220]: associated type `Item` not found for `M`
   --> $DIR/missing-trait-bound-for-assoc-fails.rs:4:8
    |
 LL |     M::Item: Temp,
-   |        ^^^^
-   |
-   = help: `M` has no associated type, try removing `Item`
+   |        ^^^^ associated type `Item` not found
 
 error: aborting due to 2 previous errors
 
diff --git a/tests/ui/associated-types/associated-types-path-1.stderr b/tests/ui/associated-types/associated-types-path-1.stderr
index 195740359a3..a67f77e37c7 100644
--- a/tests/ui/associated-types/associated-types-path-1.stderr
+++ b/tests/ui/associated-types/associated-types-path-1.stderr
@@ -2,9 +2,7 @@ error[E0220]: associated type `A` not found for `T`
   --> $DIR/associated-types-path-1.rs:10:26
    |
 LL | pub fn f1<T>(a: T, x: T::A) {}
-   |                          ^
-   |
-   = help: `T` has no associated type, try removing `A`
+   |                          ^ associated type `A` not found
 
 error[E0221]: ambiguous associated type `A` in bounds of `T`
   --> $DIR/associated-types-path-1.rs:11:34
diff --git a/tests/ui/feature-gates/feature-gate-return_type_notation.cfg.stderr b/tests/ui/feature-gates/feature-gate-return_type_notation.cfg.stderr
index 012913fd0e0..1bdb2574ead 100644
--- a/tests/ui/feature-gates/feature-gate-return_type_notation.cfg.stderr
+++ b/tests/ui/feature-gates/feature-gate-return_type_notation.cfg.stderr
@@ -19,9 +19,7 @@ error[E0220]: associated type `m` not found for `Trait`
   --> $DIR/feature-gate-return_type_notation.rs:14:17
    |
 LL | fn foo<T: Trait<m(): Send>>() {}
-   |                 ^
-   |
-   = help: `Trait` has no associated type, try removing `m`
+   |                 ^ associated type `m` not found
 
 error: aborting due to 3 previous errors
 
diff --git a/tests/ui/feature-gates/feature-gate-return_type_notation.cfg_current.stderr b/tests/ui/feature-gates/feature-gate-return_type_notation.cfg_current.stderr
index 68cf8e36fcc..ce39f6b2971 100644
--- a/tests/ui/feature-gates/feature-gate-return_type_notation.cfg_current.stderr
+++ b/tests/ui/feature-gates/feature-gate-return_type_notation.cfg_current.stderr
@@ -19,9 +19,7 @@ error[E0220]: associated type `m` not found for `Trait`
   --> $DIR/feature-gate-return_type_notation.rs:17:17
    |
 LL | fn foo<T: Trait<m(): Send>>() {}
-   |                 ^
-   |
-   = help: `Trait` has no associated type, try removing `m`
+   |                 ^ associated type `m` not found
 
 error: aborting due to 3 previous errors
 
diff --git a/tests/ui/feature-gates/feature-gate-return_type_notation.cfg_next.stderr b/tests/ui/feature-gates/feature-gate-return_type_notation.cfg_next.stderr
index 68cf8e36fcc..ce39f6b2971 100644
--- a/tests/ui/feature-gates/feature-gate-return_type_notation.cfg_next.stderr
+++ b/tests/ui/feature-gates/feature-gate-return_type_notation.cfg_next.stderr
@@ -19,9 +19,7 @@ error[E0220]: associated type `m` not found for `Trait`
   --> $DIR/feature-gate-return_type_notation.rs:17:17
    |
 LL | fn foo<T: Trait<m(): Send>>() {}
-   |                 ^
-   |
-   = help: `Trait` has no associated type, try removing `m`
+   |                 ^ associated type `m` not found
 
 error: aborting due to 3 previous errors