From 8e8d2ffecbc9e260ee5f0d37ba057b660e16076f Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 26 Jun 2020 16:36:59 +0200 Subject: (Partially) fix handling of type params depending on type params If the first type parameter gets inferred, that's still not handled correctly; it'll require some more refactoring: E.g. if we have `Thing T>` and then instantiate `Thing<_>`, that gets turned into `Thing<_, fn() -> _>` before the `_` is instantiated into a type variable -- so afterwards, we have two type variables without any connection to each other. --- crates/ra_hir/src/code_model.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 27e94b7fe..e86077dd6 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -543,7 +543,7 @@ impl_froms!(Adt: Struct, Union, Enum); impl Adt { pub fn has_non_default_type_params(self, db: &dyn HirDatabase) -> bool { let subst = db.generic_defaults(self.into()); - subst.iter().any(|ty| ty == &Ty::Unknown) + subst.iter().any(|ty| &ty.value == &Ty::Unknown) } /// Turns this ADT into a type. Any type parameters of the ADT will be @@ -775,7 +775,7 @@ pub struct TypeAlias { impl TypeAlias { pub fn has_non_default_type_params(self, db: &dyn HirDatabase) -> bool { let subst = db.generic_defaults(self.id.into()); - subst.iter().any(|ty| ty == &Ty::Unknown) + subst.iter().any(|ty| &ty.value == &Ty::Unknown) } pub fn module(self, db: &dyn HirDatabase) -> Module { @@ -1035,7 +1035,10 @@ impl TypeParam { let local_idx = hir_ty::param_idx(db, self.id)?; let resolver = self.id.parent.resolver(db.upcast()); let environment = TraitEnvironment::lower(db, &resolver); - params.get(local_idx).cloned().map(|ty| Type { + let ty = params.get(local_idx)?.clone(); + let subst = Substs::type_params(db, self.id.parent); + let ty = ty.subst(&subst.prefix(local_idx)); + Some(Type { krate: self.id.parent.module(db.upcast()).krate, ty: InEnvironment { value: ty, environment }, }) -- cgit v1.2.3