aboutsummaryrefslogtreecommitdiff
path: root/crates/hir/src
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-03-09 11:31:16 +0000
committerJonas Schievink <[email protected]>2021-03-09 11:31:16 +0000
commit30791c52956c4f474a782cc46c7fe8598dcf1df0 (patch)
treeebf679fbfa8ec0bfaaa51b2d6cca78fbd2081fce /crates/hir/src
parent297240744d1d55ef5451ed4db3a3f37f8df38380 (diff)
Use `Type::new_with_resolver_inner` more
Diffstat (limited to 'crates/hir/src')
-rw-r--r--crates/hir/src/lib.rs40
1 files changed, 14 insertions, 26 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 62692c2c1..e3a332d30 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -812,13 +812,11 @@ impl Function {
812 /// Get this function's return type 812 /// Get this function's return type
813 pub fn ret_type(self, db: &dyn HirDatabase) -> Type { 813 pub fn ret_type(self, db: &dyn HirDatabase) -> Type {
814 let resolver = self.id.resolver(db.upcast()); 814 let resolver = self.id.resolver(db.upcast());
815 let krate = self.id.lookup(db.upcast()).container.module(db.upcast()).krate();
815 let ret_type = &db.function_data(self.id).ret_type; 816 let ret_type = &db.function_data(self.id).ret_type;
816 let ctx = hir_ty::TyLoweringContext::new(db, &resolver); 817 let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
817 let environment = TraitEnvironment::lower(db, &resolver); 818 let ty = Ty::from_hir_ext(&ctx, ret_type).0;
818 Type { 819 Type::new_with_resolver_inner(db, krate, &resolver, ty)
819 krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate(),
820 ty: InEnvironment { value: Ty::from_hir_ext(&ctx, ret_type).0, environment },
821 }
822 } 820 }
823 821
824 pub fn self_param(self, db: &dyn HirDatabase) -> Option<SelfParam> { 822 pub fn self_param(self, db: &dyn HirDatabase) -> Option<SelfParam> {
@@ -830,6 +828,7 @@ impl Function {
830 828
831 pub fn assoc_fn_params(self, db: &dyn HirDatabase) -> Vec<Param> { 829 pub fn assoc_fn_params(self, db: &dyn HirDatabase) -> Vec<Param> {
832 let resolver = self.id.resolver(db.upcast()); 830 let resolver = self.id.resolver(db.upcast());
831 let krate = self.id.lookup(db.upcast()).container.module(db.upcast()).krate();
833 let ctx = hir_ty::TyLoweringContext::new(db, &resolver); 832 let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
834 let environment = TraitEnvironment::lower(db, &resolver); 833 let environment = TraitEnvironment::lower(db, &resolver);
835 db.function_data(self.id) 834 db.function_data(self.id)
@@ -837,7 +836,7 @@ impl Function {
837 .iter() 836 .iter()
838 .map(|type_ref| { 837 .map(|type_ref| {
839 let ty = Type { 838 let ty = Type {
840 krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate(), 839 krate,
841 ty: InEnvironment { 840 ty: InEnvironment {
842 value: Ty::from_hir_ext(&ctx, type_ref).0, 841 value: Ty::from_hir_ext(&ctx, type_ref).0,
843 environment: environment.clone(), 842 environment: environment.clone(),
@@ -1402,12 +1401,9 @@ impl TypeParam {
1402 1401
1403 pub fn ty(self, db: &dyn HirDatabase) -> Type { 1402 pub fn ty(self, db: &dyn HirDatabase) -> Type {
1404 let resolver = self.id.parent.resolver(db.upcast()); 1403 let resolver = self.id.parent.resolver(db.upcast());
1405 let environment = TraitEnvironment::lower(db, &resolver); 1404 let krate = self.id.parent.module(db.upcast()).krate();
1406 let ty = Ty::Placeholder(self.id); 1405 let ty = Ty::Placeholder(self.id);
1407 Type { 1406 Type::new_with_resolver_inner(db, krate, &resolver, ty)
1408 krate: self.id.parent.module(db.upcast()).krate(),
1409 ty: InEnvironment { value: ty, environment },
1410 }
1411 } 1407 }
1412 1408
1413 pub fn trait_bounds(self, db: &dyn HirDatabase) -> Vec<Trait> { 1409 pub fn trait_bounds(self, db: &dyn HirDatabase) -> Vec<Trait> {
@@ -1426,14 +1422,11 @@ impl TypeParam {
1426 let params = db.generic_defaults(self.id.parent); 1422 let params = db.generic_defaults(self.id.parent);
1427 let local_idx = hir_ty::param_idx(db, self.id)?; 1423 let local_idx = hir_ty::param_idx(db, self.id)?;
1428 let resolver = self.id.parent.resolver(db.upcast()); 1424 let resolver = self.id.parent.resolver(db.upcast());
1429 let environment = TraitEnvironment::lower(db, &resolver); 1425 let krate = self.id.parent.module(db.upcast()).krate();
1430 let ty = params.get(local_idx)?.clone(); 1426 let ty = params.get(local_idx)?.clone();
1431 let subst = Substs::type_params(db, self.id.parent); 1427 let subst = Substs::type_params(db, self.id.parent);
1432 let ty = ty.subst(&subst.prefix(local_idx)); 1428 let ty = ty.subst(&subst.prefix(local_idx));
1433 Some(Type { 1429 Some(Type::new_with_resolver_inner(db, krate, &resolver, ty))
1434 krate: self.id.parent.module(db.upcast()).krate(),
1435 ty: InEnvironment { value: ty, environment },
1436 })
1437 } 1430 }
1438} 1431}
1439 1432
@@ -1522,13 +1515,10 @@ impl Impl {
1522 pub fn target_ty(self, db: &dyn HirDatabase) -> Type { 1515 pub fn target_ty(self, db: &dyn HirDatabase) -> Type {
1523 let impl_data = db.impl_data(self.id); 1516 let impl_data = db.impl_data(self.id);
1524 let resolver = self.id.resolver(db.upcast()); 1517 let resolver = self.id.resolver(db.upcast());
1518 let krate = self.id.lookup(db.upcast()).container.module(db.upcast()).krate();
1525 let ctx = hir_ty::TyLoweringContext::new(db, &resolver); 1519 let ctx = hir_ty::TyLoweringContext::new(db, &resolver);
1526 let environment = TraitEnvironment::lower(db, &resolver);
1527 let ty = Ty::from_hir(&ctx, &impl_data.target_type); 1520 let ty = Ty::from_hir(&ctx, &impl_data.target_type);
1528 Type { 1521 Type::new_with_resolver_inner(db, krate, &resolver, ty)
1529 krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate(),
1530 ty: InEnvironment { value: ty, environment },
1531 }
1532 } 1522 }
1533 1523
1534 pub fn items(self, db: &dyn HirDatabase) -> Vec<AssocItem> { 1524 pub fn items(self, db: &dyn HirDatabase) -> Vec<AssocItem> {
@@ -1724,13 +1714,11 @@ impl Type {
1724 }; 1714 };
1725 1715
1726 match db.trait_solve(self.krate, goal)? { 1716 match db.trait_solve(self.krate, goal)? {
1727 Solution::Unique(SolutionVariables(subst)) => subst.value.first().cloned(), 1717 Solution::Unique(SolutionVariables(subst)) => {
1718 subst.value.first().map(|ty| self.derived(ty.clone()))
1719 }
1728 Solution::Ambig(_) => None, 1720 Solution::Ambig(_) => None,
1729 } 1721 }
1730 .map(|ty| Type {
1731 krate: self.krate,
1732 ty: InEnvironment { value: ty, environment: Arc::clone(&self.ty.environment) },
1733 })
1734 } 1722 }
1735 1723
1736 pub fn is_copy(&self, db: &dyn HirDatabase) -> bool { 1724 pub fn is_copy(&self, db: &dyn HirDatabase) -> bool {