Account for type parameters in bound suggestion by estebank · Pull Request #134937 · rust-lang/rust (original) (raw)
When encountering a missing bound that involves a type parameter, on associated functions we look at the generics to see if the type parameter is present. If so, we suggest the bound on the associated function instead of on the impl/trait. At the impl/trait doesn't have another type parameter of that name, then we don't suggest the bound at that item level.
error[E0277]: the trait bound `B: From<T>` is not satisfied
--> $DIR/suggest-restriction-involving-type-param.rs:20:33
|
LL | B { x: v.iter().map(|e| B::from(e.clone()).x).collect::<Vec<String>>().join(" ") }
| ^ the trait `From<T>` is not implemented for `B`
|
help: consider further restricting the type
|
LL | pub fn from_many<T: Into<B> + Clone>(v: Vec<T>) -> Self where B: From<T> {
| ++++++++++++++++
Fix #104089.