Rollup merge of #127888 - estebank:type-param-sugg, r=compiler-errors

More accurate span for type parameter suggestion

After:

```
error[E0229]: associated item constraints are not allowed here
  --> $DIR/impl-block-params-declared-in-wrong-spot-issue-113073.rs:3:10
   |
LL | impl Foo<T: Default> for String {}
   |          ^^^^^^^^^^ associated item constraint not allowed here
   |
help: declare the type parameter right after the `impl` keyword
   |
LL - impl Foo<T: Default> for String {}
LL + impl<T: Default> Foo<T> for String {}
   |
```

Before:

```
error[E0229]: associated item constraints are not allowed here
  --> $DIR/impl-block-params-declared-in-wrong-spot-issue-113073.rs:3:10
   |
LL | impl Foo<T: Default> for String {}
   |          ^^^^^^^^^^ associated item constraint not allowed here
   |
help: declare the type parameter right after the `impl` keyword
   |
LL | impl<T: Default> Foo<T> for String {}
   |     ++++++++++++     ~
```
This commit is contained in:
Matthias Krüger 2024-07-18 08:09:02 +02:00 committed by GitHub
commit d78be31a2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 15 deletions

View file

@ -1338,11 +1338,13 @@ pub fn prohibit_assoc_item_constraint(
format!("<{lifetimes}{type_with_constraints}>"),
)
};
let suggestions =
vec![param_decl, (constraint.span, format!("{}", matching_param.name))];
let suggestions = vec![
param_decl,
(constraint.span.with_lo(constraint.ident.span.hi()), String::new()),
];
err.multipart_suggestion_verbose(
format!("declare the type parameter right after the `impl` keyword"),
"declare the type parameter right after the `impl` keyword",
suggestions,
Applicability::MaybeIncorrect,
);