From e38032fb3ad5736934ea1ff1ecc43e8af4c47a87 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Esteban=20K=C3=BCber?=
Date: Tue, 9 Jul 2024 22:11:20 +0000
Subject: [PATCH] Fix associated item removal suggestion
We were previously telling people to write what was already there, instead of removal.
```
error[E0229]: associated item constraints are not allowed here
--> $DIR/E0229.rs:13:25
|
LL | fn baz(x: &>::A) {}
| ^^^^^^^ associated item constraint not allowed here
|
help: consider removing this associated item binding
|
LL - fn baz(x: &>::A) {}
LL + fn baz(x: &::A) {}
|
```
---
.../src/hir_ty_lowering/errors.rs | 14 +++----
.../ice-unresolved-import-100241.stderr | 11 +++++
.../invalid_associated_const.stderr | 10 +++--
tests/rustdoc-ui/issue-102467.stderr | 10 +++--
.../issue-102335-const.stderr | 10 +++--
.../issue-102335-ty.stderr | 20 ++++++----
.../no-gat-position.stderr | 5 ++-
.../associated-types-eq-2.stderr | 40 +++++++++++--------
.../rtn-in-impl-signature.stderr | 5 ++-
tests/ui/error-codes/E0229.stderr | 15 ++++---
.../issue-102335-gat.stderr | 10 +++--
...lid-associated-type-supertrait-hrtb.stderr | 5 ++-
tests/ui/suggestions/issue-85347.stderr | 10 +++--
13 files changed, 101 insertions(+), 64 deletions(-)
create mode 100644 tests/rustdoc-ui/ice-unresolved-import-100241.stderr
diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs
index 5e595488ea7a8..cd0451b41656b 100644
--- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs
+++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs
@@ -1257,14 +1257,12 @@ pub fn prohibit_assoc_item_constraint(
};
// Now emit the suggestion
- if let Ok(suggestion) = tcx.sess.source_map().span_to_snippet(removal_span) {
- e.span_suggestion_verbose(
- removal_span,
- format!("consider removing this associated item {}", constraint.kind.descr()),
- suggestion,
- Applicability::MaybeIncorrect,
- );
- }
+ e.span_suggestion_verbose(
+ removal_span,
+ format!("consider removing this associated item {}", constraint.kind.descr()),
+ "",
+ Applicability::MaybeIncorrect,
+ );
};
// Suggest replacing the associated item binding with a generic argument.
diff --git a/tests/rustdoc-ui/ice-unresolved-import-100241.stderr b/tests/rustdoc-ui/ice-unresolved-import-100241.stderr
new file mode 100644
index 0000000000000..57fbbb59c8d41
--- /dev/null
+++ b/tests/rustdoc-ui/ice-unresolved-import-100241.stderr
@@ -0,0 +1,11 @@
+error[E0432]: unresolved import `inner`
+ --> $DIR/ice-unresolved-import-100241.rs:9:13
+ |
+LL | pub use inner::S;
+ | ^^^^^ maybe a missing crate `inner`?
+ |
+ = help: consider adding `extern crate inner` to use the `inner` crate
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0432`.
diff --git a/tests/rustdoc-ui/invalid_associated_const.stderr b/tests/rustdoc-ui/invalid_associated_const.stderr
index 6e5ddc449828c..66f8ffe6d7298 100644
--- a/tests/rustdoc-ui/invalid_associated_const.stderr
+++ b/tests/rustdoc-ui/invalid_associated_const.stderr
@@ -6,8 +6,9 @@ LL | type A: S = 34>;
|
help: consider removing this associated item binding
|
-LL | type A: S = 34>;
- | ~~~~~~~~~~
+LL - type A: S = 34>;
+LL + type A: S;
+ |
error[E0229]: associated item constraints are not allowed here
--> $DIR/invalid_associated_const.rs:4:17
@@ -18,8 +19,9 @@ LL | type A: S = 34>;
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider removing this associated item binding
|
-LL | type A: S = 34>;
- | ~~~~~~~~~~
+LL - type A: S = 34>;
+LL + type A: S;
+ |
error: aborting due to 2 previous errors
diff --git a/tests/rustdoc-ui/issue-102467.stderr b/tests/rustdoc-ui/issue-102467.stderr
index 99f911023192c..5fcdba782e7eb 100644
--- a/tests/rustdoc-ui/issue-102467.stderr
+++ b/tests/rustdoc-ui/issue-102467.stderr
@@ -6,8 +6,9 @@ LL | type A: S = 34>;
|
help: consider removing this associated item binding
|
-LL | type A: S = 34>;
- | ~~~~~~~~~~
+LL - type A: S = 34>;
+LL + type A: S;
+ |
error[E0229]: associated item constraints are not allowed here
--> $DIR/issue-102467.rs:7:17
@@ -18,8 +19,9 @@ LL | type A: S = 34>;
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider removing this associated item binding
|
-LL | type A: S = 34>;
- | ~~~~~~~~~~
+LL - type A: S = 34>;
+LL + type A: S;
+ |
error: aborting due to 2 previous errors
diff --git a/tests/ui/associated-consts/issue-102335-const.stderr b/tests/ui/associated-consts/issue-102335-const.stderr
index dc1631220e2a9..cf96c8cf8eb9d 100644
--- a/tests/ui/associated-consts/issue-102335-const.stderr
+++ b/tests/ui/associated-consts/issue-102335-const.stderr
@@ -6,8 +6,9 @@ LL | type A: S = 34>;
|
help: consider removing this associated item binding
|
-LL | type A: S = 34>;
- | ~~~~~~~~~~
+LL - type A: S = 34>;
+LL + type A: S;
+ |
error[E0229]: associated item constraints are not allowed here
--> $DIR/issue-102335-const.rs:4:17
@@ -18,8 +19,9 @@ LL | type A: S = 34>;
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider removing this associated item binding
|
-LL | type A: S = 34>;
- | ~~~~~~~~~~
+LL - type A: S = 34>;
+LL + type A: S;
+ |
error: aborting due to 2 previous errors
diff --git a/tests/ui/associated-type-bounds/issue-102335-ty.stderr b/tests/ui/associated-type-bounds/issue-102335-ty.stderr
index cd585f7f7d8f5..259b0ca00e1b3 100644
--- a/tests/ui/associated-type-bounds/issue-102335-ty.stderr
+++ b/tests/ui/associated-type-bounds/issue-102335-ty.stderr
@@ -6,8 +6,9 @@ LL | type A: S = ()>; // Just one erroneous equality constraint
|
help: consider removing this associated item binding
|
-LL | type A: S = ()>; // Just one erroneous equality constraint
- | ~~~~~~~~~~~
+LL - type A: S = ()>; // Just one erroneous equality constraint
+LL + type A: S; // Just one erroneous equality constraint
+ |
error[E0229]: associated item constraints are not allowed here
--> $DIR/issue-102335-ty.rs:2:17
@@ -18,8 +19,9 @@ LL | type A: S = ()>; // Just one erroneous equality constraint
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider removing this associated item binding
|
-LL | type A: S = ()>; // Just one erroneous equality constraint
- | ~~~~~~~~~~~
+LL - type A: S = ()>; // Just one erroneous equality constraint
+LL + type A: S; // Just one erroneous equality constraint
+ |
error[E0229]: associated item constraints are not allowed here
--> $DIR/issue-102335-ty.rs:8:17
@@ -29,8 +31,9 @@ LL | type A: S = ()>; // More than one erroneous equal
|
help: consider removing this associated item binding
|
-LL | type A: S = ()>; // More than one erroneous equality constraints
- | ~~~~~~~~~~
+LL - type A: S = ()>; // More than one erroneous equality constraints
+LL + type A: S = ()>; // More than one erroneous equality constraints
+ |
error[E0229]: associated item constraints are not allowed here
--> $DIR/issue-102335-ty.rs:8:17
@@ -41,8 +44,9 @@ LL | type A: S = ()>; // More than one erroneous equal
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider removing this associated item binding
|
-LL | type A: S = ()>; // More than one erroneous equality constraints
- | ~~~~~~~~~~
+LL - type A: S = ()>; // More than one erroneous equality constraints
+LL + type A: S = ()>; // More than one erroneous equality constraints
+ |
error: aborting due to 4 previous errors
diff --git a/tests/ui/associated-type-bounds/no-gat-position.stderr b/tests/ui/associated-type-bounds/no-gat-position.stderr
index 39a2f89f9acf0..03dc752c5330e 100644
--- a/tests/ui/associated-type-bounds/no-gat-position.stderr
+++ b/tests/ui/associated-type-bounds/no-gat-position.stderr
@@ -6,8 +6,9 @@ LL | fn next<'a>(&'a mut self) -> Option>;
|
help: consider removing this associated item constraint
|
-LL | fn next<'a>(&'a mut self) -> Option>;
- | ~~~~~~~~~~~
+LL - fn next<'a>(&'a mut self) -> Option>;
+LL + fn next<'a>(&'a mut self) -> Option>;
+ |
error: aborting due to 1 previous error
diff --git a/tests/ui/associated-types/associated-types-eq-2.stderr b/tests/ui/associated-types/associated-types-eq-2.stderr
index 69b1b533450c7..e5013a35d453b 100644
--- a/tests/ui/associated-types/associated-types-eq-2.stderr
+++ b/tests/ui/associated-types/associated-types-eq-2.stderr
@@ -50,8 +50,9 @@ LL | impl Tr1 for usize {
|
help: consider removing this associated item binding
|
-LL | impl Tr1 for usize {
- | ~~~~~~~~~~~
+LL - impl Tr1 for usize {
+LL + impl Tr1 for usize {
+ |
error[E0046]: not all trait items implemented, missing: `A`
--> $DIR/associated-types-eq-2.rs:20:1
@@ -70,8 +71,9 @@ LL | fn baz(_x: &>::A) {}
|
help: consider removing this associated item binding
|
-LL | fn baz(_x: &>::A) {}
- | ~~~~~~~
+LL - fn baz(_x: &>::A) {}
+LL + fn baz(_x: &::A) {}
+ |
error[E0107]: trait takes 3 generic arguments but 1 generic argument was supplied
--> $DIR/associated-types-eq-2.rs:40:6
@@ -128,8 +130,9 @@ LL | impl Tr2 for Qux {
|
help: consider removing this associated item binding
|
-LL | impl Tr2 for Qux {
- | ~~~~~~~~~~
+LL - impl Tr2 for Qux {
+LL + impl Tr2 for Qux {
+ |
error[E0107]: trait takes 3 generic arguments but 1 generic argument was supplied
--> $DIR/associated-types-eq-2.rs:54:6
@@ -157,8 +160,9 @@ LL | impl Tr2 for Bar {
|
help: consider removing this associated item binding
|
-LL | impl Tr2 for Bar {
- | ~~~~~~~~~
+LL - impl Tr2 for Bar {
+LL + impl Tr2 for Bar {
+ |
error[E0107]: trait takes 3 generic arguments but 2 generic arguments were supplied
--> $DIR/associated-types-eq-2.rs:61:6
@@ -228,8 +232,9 @@ LL | impl Tr3 for Qux {
|
help: consider removing this associated item binding
|
-LL | impl Tr3 for Qux {
- | ~~~~~~~
+LL - impl Tr3 for Qux {
+LL + impl Tr3 for Qux {
+ |
error[E0229]: associated item constraints are not allowed here
--> $DIR/associated-types-eq-2.rs:92:10
@@ -239,8 +244,9 @@ LL | impl Tr3 for Bar {
|
help: consider removing this associated item binding
|
-LL | impl Tr3 for Bar {
- | ~~~~~~~~
+LL - impl Tr3 for Bar {
+LL + impl Tr3 for Bar {
+ |
error[E0107]: trait takes 3 generic arguments but 1 generic argument was supplied
--> $DIR/associated-types-eq-2.rs:98:6
@@ -268,8 +274,9 @@ LL | impl Tr3<42, T2 = 42, T3 = usize> for Bar {
|
help: consider removing this associated item binding
|
-LL | impl Tr3<42, T2 = 42, T3 = usize> for Bar {
- | ~~~~~~~~~
+LL - impl Tr3<42, T2 = 42, T3 = usize> for Bar {
+LL + impl Tr3<42, T3 = usize> for Bar {
+ |
error[E0107]: trait takes 3 generic arguments but 0 generic arguments were supplied
--> $DIR/associated-types-eq-2.rs:106:6
@@ -295,8 +302,9 @@ LL | impl Tr3 for Bar {
|
help: consider removing this associated item binding
|
-LL | impl Tr3 for Bar {
- | ~~~~~~~
+LL - impl Tr3 for Bar {
+LL + impl Tr3 for Bar {
+ |
error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied
--> $DIR/associated-types-eq-2.rs:117:13
diff --git a/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.stderr b/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.stderr
index b23dbc37a55cc..e061587f49189 100644
--- a/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.stderr
+++ b/tests/ui/async-await/return-type-notation/rtn-in-impl-signature.stderr
@@ -15,8 +15,9 @@ LL | impl Super1<'_, bar(..): Send> for () {}
|
help: consider removing this associated item constraint
|
-LL | impl Super1<'_, bar(..): Send> for () {}
- | ~~~~~~~~~~~~~~~
+LL - impl Super1<'_, bar(..): Send> for () {}
+LL + impl Super1<'_> for () {}
+ |
error[E0046]: not all trait items implemented, missing: `bar`
--> $DIR/rtn-in-impl-signature.rs:10:1
diff --git a/tests/ui/error-codes/E0229.stderr b/tests/ui/error-codes/E0229.stderr
index 7d9cedc3bdc4f..038f44e8b14f0 100644
--- a/tests/ui/error-codes/E0229.stderr
+++ b/tests/ui/error-codes/E0229.stderr
@@ -6,8 +6,9 @@ LL | fn baz(x: &>::A) {}
|
help: consider removing this associated item binding
|
-LL | fn baz(x: &>::A) {}
- | ~~~~~~~~~
+LL - fn baz(x: &>::A) {}
+LL + fn baz(x: &::A) {}
+ |
error[E0229]: associated item constraints are not allowed here
--> $DIR/E0229.rs:13:25
@@ -18,8 +19,9 @@ LL | fn baz(x: &>::A) {}
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider removing this associated item binding
|
-LL | fn baz(x: &>::A) {}
- | ~~~~~~~~~
+LL - fn baz(x: &>::A) {}
+LL + fn baz(x: &::A) {}
+ |
error[E0229]: associated item constraints are not allowed here
--> $DIR/E0229.rs:13:25
@@ -30,8 +32,9 @@ LL | fn baz(x: &>::A) {}
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider removing this associated item binding
|
-LL | fn baz(x: &>::A) {}
- | ~~~~~~~~~
+LL - fn baz(x: &>::A) {}
+LL + fn baz(x: &::A) {}
+ |
error[E0277]: the trait bound `I: Foo` is not satisfied
--> $DIR/E0229.rs:13:15
diff --git a/tests/ui/generic-associated-types/issue-102335-gat.stderr b/tests/ui/generic-associated-types/issue-102335-gat.stderr
index b4772486e6e45..bcef76290fcdc 100644
--- a/tests/ui/generic-associated-types/issue-102335-gat.stderr
+++ b/tests/ui/generic-associated-types/issue-102335-gat.stderr
@@ -6,8 +6,9 @@ LL | type A: S = ()>;
|
help: consider removing this associated item binding
|
-LL | type A: S = ()>;
- | ~~~~~~~~~~
+LL - type A: S = ()>;
+LL + type A: S = ()>;
+ |
error[E0229]: associated item constraints are not allowed here
--> $DIR/issue-102335-gat.rs:2:21
@@ -18,8 +19,9 @@ LL | type A: S = ()>;
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider removing this associated item binding
|
-LL | type A: S = ()>;
- | ~~~~~~~~~~
+LL - type A: S = ()>;
+LL + type A: S = ()>;
+ |
error: aborting due to 2 previous errors
diff --git a/tests/ui/lifetimes/issue-83753-invalid-associated-type-supertrait-hrtb.stderr b/tests/ui/lifetimes/issue-83753-invalid-associated-type-supertrait-hrtb.stderr
index f8d919fd68b68..4ea14cdf042f3 100644
--- a/tests/ui/lifetimes/issue-83753-invalid-associated-type-supertrait-hrtb.stderr
+++ b/tests/ui/lifetimes/issue-83753-invalid-associated-type-supertrait-hrtb.stderr
@@ -6,8 +6,9 @@ LL | fn bar(foo: Foo) {}
|
help: consider removing this associated item binding
|
-LL | fn bar(foo: Foo) {}
- | ~~~~~~~~~~~~~~~~
+LL - fn bar(foo: Foo) {}
+LL + fn bar(foo: Foo) {}
+ |
error: aborting due to 1 previous error
diff --git a/tests/ui/suggestions/issue-85347.stderr b/tests/ui/suggestions/issue-85347.stderr
index b3616041c4cd9..af77ddd35e32f 100644
--- a/tests/ui/suggestions/issue-85347.stderr
+++ b/tests/ui/suggestions/issue-85347.stderr
@@ -22,8 +22,9 @@ LL | type Bar<'a>: Deref::Bar>;
|
help: consider removing this associated item binding
|
-LL | type Bar<'a>: Deref::Bar>;
- | ~~~~~~~~~~~~~~~
+LL - type Bar<'a>: Deref::Bar>;
+LL + type Bar<'a>: Deref::Bar>;
+ |
error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
--> $DIR/issue-85347.rs:3:42
@@ -51,8 +52,9 @@ LL | type Bar<'a>: Deref::Bar>;
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
help: consider removing this associated item binding
|
-LL | type Bar<'a>: Deref::Bar>;
- | ~~~~~~~~~~~~~~~
+LL - type Bar<'a>: Deref::Bar>;
+LL + type Bar<'a>: Deref::Bar>;
+ |
error: aborting due to 4 previous errors