Fix assoc type shorthand from method bounds
In code like this:
```rust
impl<T> Option<T> {
fn as_deref(&self) -> T::Target where T: Deref {}
}
```
when trying to resolve the associated type `T::Target`, we were only
looking at the bounds on the impl (where the type parameter is defined),
but the method can add additional bounds that can also be used to refer
to associated types. Hence, when resolving such an associated type, it's
not enough to just know the type parameter T, we also need to know
exactly where we are currently.
This fixes #11364 (beta apparently switched some bounds around).
This commit is contained in:
@@ -2235,8 +2235,11 @@ impl TypeParam {
|
||||
Type::new_with_resolver_inner(db, krate, &resolver, ty)
|
||||
}
|
||||
|
||||
/// FIXME: this only lists trait bounds from the item defining the type
|
||||
/// parameter, not additional bounds that might be added e.g. by a method if
|
||||
/// the parameter comes from an impl!
|
||||
pub fn trait_bounds(self, db: &dyn HirDatabase) -> Vec<Trait> {
|
||||
db.generic_predicates_for_param(self.id, None)
|
||||
db.generic_predicates_for_param(self.id.parent, self.id, None)
|
||||
.iter()
|
||||
.filter_map(|pred| match &pred.skip_binders().skip_binders() {
|
||||
hir_ty::WhereClause::Implemented(trait_ref) => {
|
||||
|
||||
Reference in New Issue
Block a user