diff options
Diffstat (limited to 'crates/hir')
-rw-r--r-- | crates/hir/src/lib.rs | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index c4691d34c..d5a3d9034 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(), |
@@ -1403,12 +1402,9 @@ impl TypeParam { | |||
1403 | 1402 | ||
1404 | pub fn ty(self, db: &dyn HirDatabase) -> Type { | 1403 | pub fn ty(self, db: &dyn HirDatabase) -> Type { |
1405 | let resolver = self.id.parent.resolver(db.upcast()); | 1404 | let resolver = self.id.parent.resolver(db.upcast()); |
1406 | let environment = TraitEnvironment::lower(db, &resolver); | 1405 | let krate = self.id.parent.module(db.upcast()).krate(); |
1407 | let ty = Ty::Placeholder(self.id); | 1406 | let ty = Ty::Placeholder(self.id); |
1408 | Type { | 1407 | Type::new_with_resolver_inner(db, krate, &resolver, ty) |
1409 | krate: self.id.parent.module(db.upcast()).krate(), | ||
1410 | ty: InEnvironment { value: ty, environment }, | ||
1411 | } | ||
1412 | } | 1408 | } |
1413 | 1409 | ||
1414 | pub fn trait_bounds(self, db: &dyn HirDatabase) -> Vec<Trait> { | 1410 | pub fn trait_bounds(self, db: &dyn HirDatabase) -> Vec<Trait> { |
@@ -1427,14 +1423,11 @@ impl TypeParam { | |||
1427 | let params = db.generic_defaults(self.id.parent); | 1423 | let params = db.generic_defaults(self.id.parent); |
1428 | let local_idx = hir_ty::param_idx(db, self.id)?; | 1424 | let local_idx = hir_ty::param_idx(db, self.id)?; |
1429 | let resolver = self.id.parent.resolver(db.upcast()); | 1425 | let resolver = self.id.parent.resolver(db.upcast()); |
1430 | let environment = TraitEnvironment::lower(db, &resolver); | 1426 | let krate = self.id.parent.module(db.upcast()).krate(); |
1431 | let ty = params.get(local_idx)?.clone(); | 1427 | let ty = params.get(local_idx)?.clone(); |
1432 | let subst = Substs::type_params(db, self.id.parent); | 1428 | let subst = Substs::type_params(db, self.id.parent); |
1433 | let ty = ty.subst(&subst.prefix(local_idx)); | 1429 | let ty = ty.subst(&subst.prefix(local_idx)); |
1434 | Some(Type { | 1430 | Some(Type::new_with_resolver_inner(db, krate, &resolver, ty)) |
1435 | krate: self.id.parent.module(db.upcast()).krate(), | ||
1436 | ty: InEnvironment { value: ty, environment }, | ||
1437 | }) | ||
1438 | } | 1431 | } |
1439 | } | 1432 | } |
1440 | 1433 | ||
@@ -1523,13 +1516,10 @@ impl Impl { | |||
1523 | pub fn target_ty(self, db: &dyn HirDatabase) -> Type { | 1516 | pub fn target_ty(self, db: &dyn HirDatabase) -> Type { |
1524 | let impl_data = db.impl_data(self.id); | 1517 | let impl_data = db.impl_data(self.id); |
1525 | let resolver = self.id.resolver(db.upcast()); | 1518 | let resolver = self.id.resolver(db.upcast()); |
1519 | let krate = self.id.lookup(db.upcast()).container.module(db.upcast()).krate(); | ||
1526 | let ctx = hir_ty::TyLoweringContext::new(db, &resolver); | 1520 | let ctx = hir_ty::TyLoweringContext::new(db, &resolver); |
1527 | let environment = TraitEnvironment::lower(db, &resolver); | ||
1528 | let ty = Ty::from_hir(&ctx, &impl_data.target_type); | 1521 | let ty = Ty::from_hir(&ctx, &impl_data.target_type); |
1529 | Type { | 1522 | Type::new_with_resolver_inner(db, krate, &resolver, ty) |
1530 | krate: self.id.lookup(db.upcast()).container.module(db.upcast()).krate(), | ||
1531 | ty: InEnvironment { value: ty, environment }, | ||
1532 | } | ||
1533 | } | 1523 | } |
1534 | 1524 | ||
1535 | pub fn items(self, db: &dyn HirDatabase) -> Vec<AssocItem> { | 1525 | pub fn items(self, db: &dyn HirDatabase) -> Vec<AssocItem> { |
@@ -1725,13 +1715,11 @@ impl Type { | |||
1725 | }; | 1715 | }; |
1726 | 1716 | ||
1727 | match db.trait_solve(self.krate, goal)? { | 1717 | match db.trait_solve(self.krate, goal)? { |
1728 | Solution::Unique(SolutionVariables(subst)) => subst.value.first().cloned(), | 1718 | Solution::Unique(SolutionVariables(subst)) => { |
1719 | subst.value.first().map(|ty| self.derived(ty.clone())) | ||
1720 | } | ||
1729 | Solution::Ambig(_) => None, | 1721 | Solution::Ambig(_) => None, |
1730 | } | 1722 | } |
1731 | .map(|ty| Type { | ||
1732 | krate: self.krate, | ||
1733 | ty: InEnvironment { value: ty, environment: Arc::clone(&self.ty.environment) }, | ||
1734 | }) | ||
1735 | } | 1723 | } |
1736 | 1724 | ||
1737 | pub fn is_copy(&self, db: &dyn HirDatabase) -> bool { | 1725 | pub fn is_copy(&self, db: &dyn HirDatabase) -> bool { |