7931: Use `Type::new_with_resolver_inner` more r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
This commit is contained in:
bors[bot] 2021-03-09 11:36:40 +00:00 committed by GitHub
commit ffba4c0dce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -812,13 +812,11 @@ impl Function {
/// Get this function's return type /// Get this function's return type
pub fn ret_type(self, db: &dyn HirDatabase) -> Type { pub fn ret_type(self, db: &dyn HirDatabase) -> Type {
let resolver = self.id.resolver(db.upcast()); let resolver = self.id.resolver(db.upcast());
let krate = self.id.lookup(db.upcast()).container.module(db.upcast()).krate();
let ret_type = &db.function_data(self.id).ret_type; let ret_type = &db.function_data(self.id).ret_type;
let ctx = hir_ty::TyLoweringContext::new(db, &resolver); let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
let environment = TraitEnvironment::lower(db, &resolver); let ty = Ty::from_hir_ext(&ctx, ret_type).0;
Type { Type::new_with_resolver_inner(db, krate, &resolver, ty)
krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate(),
ty: InEnvironment { value: Ty::from_hir_ext(&ctx, ret_type).0, environment },
}
} }
pub fn self_param(self, db: &dyn HirDatabase) -> Option<SelfParam> { pub fn self_param(self, db: &dyn HirDatabase) -> Option<SelfParam> {
@ -830,6 +828,7 @@ impl Function {
pub fn assoc_fn_params(self, db: &dyn HirDatabase) -> Vec<Param> { pub fn assoc_fn_params(self, db: &dyn HirDatabase) -> Vec<Param> {
let resolver = self.id.resolver(db.upcast()); let resolver = self.id.resolver(db.upcast());
let krate = self.id.lookup(db.upcast()).container.module(db.upcast()).krate();
let ctx = hir_ty::TyLoweringContext::new(db, &resolver); let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
let environment = TraitEnvironment::lower(db, &resolver); let environment = TraitEnvironment::lower(db, &resolver);
db.function_data(self.id) db.function_data(self.id)
@ -837,7 +836,7 @@ impl Function {
.iter() .iter()
.map(|type_ref| { .map(|type_ref| {
let ty = Type { let ty = Type {
krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate(), krate,
ty: InEnvironment { ty: InEnvironment {
value: Ty::from_hir_ext(&ctx, type_ref).0, value: Ty::from_hir_ext(&ctx, type_ref).0,
environment: environment.clone(), environment: environment.clone(),
@ -1402,12 +1401,9 @@ impl TypeParam {
pub fn ty(self, db: &dyn HirDatabase) -> Type { pub fn ty(self, db: &dyn HirDatabase) -> Type {
let resolver = self.id.parent.resolver(db.upcast()); let resolver = self.id.parent.resolver(db.upcast());
let environment = TraitEnvironment::lower(db, &resolver); let krate = self.id.parent.module(db.upcast()).krate();
let ty = Ty::Placeholder(self.id); let ty = Ty::Placeholder(self.id);
Type { Type::new_with_resolver_inner(db, krate, &resolver, ty)
krate: self.id.parent.module(db.upcast()).krate(),
ty: InEnvironment { value: ty, environment },
}
} }
pub fn trait_bounds(self, db: &dyn HirDatabase) -> Vec<Trait> { pub fn trait_bounds(self, db: &dyn HirDatabase) -> Vec<Trait> {
@ -1426,14 +1422,11 @@ impl TypeParam {
let params = db.generic_defaults(self.id.parent); let params = db.generic_defaults(self.id.parent);
let local_idx = hir_ty::param_idx(db, self.id)?; let local_idx = hir_ty::param_idx(db, self.id)?;
let resolver = self.id.parent.resolver(db.upcast()); let resolver = self.id.parent.resolver(db.upcast());
let environment = TraitEnvironment::lower(db, &resolver); let krate = self.id.parent.module(db.upcast()).krate();
let ty = params.get(local_idx)?.clone(); let ty = params.get(local_idx)?.clone();
let subst = Substs::type_params(db, self.id.parent); let subst = Substs::type_params(db, self.id.parent);
let ty = ty.subst(&subst.prefix(local_idx)); let ty = ty.subst(&subst.prefix(local_idx));
Some(Type { Some(Type::new_with_resolver_inner(db, krate, &resolver, ty))
krate: self.id.parent.module(db.upcast()).krate(),
ty: InEnvironment { value: ty, environment },
})
} }
} }
@ -1522,13 +1515,10 @@ impl Impl {
pub fn target_ty(self, db: &dyn HirDatabase) -> Type { pub fn target_ty(self, db: &dyn HirDatabase) -> Type {
let impl_data = db.impl_data(self.id); let impl_data = db.impl_data(self.id);
let resolver = self.id.resolver(db.upcast()); let resolver = self.id.resolver(db.upcast());
let krate = self.id.lookup(db.upcast()).container.module(db.upcast()).krate();
let ctx = hir_ty::TyLoweringContext::new(db, &resolver); let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
let environment = TraitEnvironment::lower(db, &resolver);
let ty = Ty::from_hir(&ctx, &impl_data.target_type); let ty = Ty::from_hir(&ctx, &impl_data.target_type);
Type { Type::new_with_resolver_inner(db, krate, &resolver, ty)
krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate(),
ty: InEnvironment { value: ty, environment },
}
} }
pub fn items(self, db: &dyn HirDatabase) -> Vec<AssocItem> { pub fn items(self, db: &dyn HirDatabase) -> Vec<AssocItem> {
@ -1724,13 +1714,11 @@ impl Type {
}; };
match db.trait_solve(self.krate, goal)? { match db.trait_solve(self.krate, goal)? {
Solution::Unique(SolutionVariables(subst)) => subst.value.first().cloned(), Solution::Unique(SolutionVariables(subst)) => {
subst.value.first().map(|ty| self.derived(ty.clone()))
}
Solution::Ambig(_) => None, Solution::Ambig(_) => None,
} }
.map(|ty| Type {
krate: self.krate,
ty: InEnvironment { value: ty, environment: Arc::clone(&self.ty.environment) },
})
} }
pub fn is_copy(&self, db: &dyn HirDatabase) -> bool { pub fn is_copy(&self, db: &dyn HirDatabase) -> bool {