1
Fork 0

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<I>(x: &<I as Foo<A = Bar>>::A) {}
   |                         ^^^^^^^ associated item constraint not allowed here
   |
help: consider removing this associated item binding
   |
LL - fn baz<I>(x: &<I as Foo<A = Bar>>::A) {}
LL + fn baz<I>(x: &<I as Foo>::A) {}
   |
```
This commit is contained in:
Esteban Küber 2024-07-09 22:11:20 +00:00
parent 032be6f7bb
commit e38032fb3a
13 changed files with 101 additions and 64 deletions

View file

@ -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.