(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, F=fn() -> 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.
This commit is contained in:
Florian Diebold 2020-06-26 16:36:59 +02:00
parent 117cf0b85b
commit 8e8d2ffecb
5 changed files with 98 additions and 21 deletions

View file

@ -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 },
})