aboutsummaryrefslogtreecommitdiff
path: root/crates/hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir')
-rw-r--r--crates/hir/src/db.rs10
-rw-r--r--crates/hir/src/display.rs23
-rw-r--r--crates/hir/src/lib.rs106
3 files changed, 67 insertions, 72 deletions
diff --git a/crates/hir/src/db.rs b/crates/hir/src/db.rs
index 1902a8d16..df5758342 100644
--- a/crates/hir/src/db.rs
+++ b/crates/hir/src/db.rs
@@ -1,14 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3pub use hir_def::db::{ 3pub use hir_def::db::*;
4 AttrsQuery, BlockDefMapQuery, BodyQuery, BodyWithSourceMapQuery, ConstDataQuery,
5 CrateDefMapQueryQuery, CrateLangItemsQuery, DefDatabase, DefDatabaseStorage, EnumDataQuery,
6 ExprScopesQuery, FileItemTreeQuery, FunctionDataQuery, GenericParamsQuery, ImplDataQuery,
7 ImportMapQuery, InternConstQuery, InternDatabase, InternDatabaseStorage, InternEnumQuery,
8 InternFunctionQuery, InternImplQuery, InternStaticQuery, InternStructQuery, InternTraitQuery,
9 InternTypeAliasQuery, InternUnionQuery, LangItemQuery, StaticDataQuery, StructDataQuery,
10 TraitDataQuery, TypeAliasDataQuery, UnionDataQuery,
11};
12pub use hir_expand::db::{ 4pub use hir_expand::db::{
13 AstDatabase, AstDatabaseStorage, AstIdMapQuery, HygieneFrameQuery, InternEagerExpansionQuery, 5 AstDatabase, AstDatabaseStorage, AstIdMapQuery, HygieneFrameQuery, InternEagerExpansionQuery,
14 InternMacroQuery, MacroArgTextQuery, MacroDefQuery, MacroExpandQuery, ParseMacroExpansionQuery, 6 InternMacroQuery, MacroArgTextQuery, MacroDefQuery, MacroExpandQuery, ParseMacroExpansionQuery,
diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs
index 97a78ca25..993772aac 100644
--- a/crates/hir/src/display.rs
+++ b/crates/hir/src/display.rs
@@ -13,29 +13,28 @@ use syntax::ast::{self, NameOwner};
13 13
14use crate::{ 14use crate::{
15 Adt, Const, ConstParam, Enum, Field, Function, GenericParam, HasVisibility, LifetimeParam, 15 Adt, Const, ConstParam, Enum, Field, Function, GenericParam, HasVisibility, LifetimeParam,
16 Module, Static, Struct, Substitution, Trait, Type, TypeAlias, TypeParam, Union, Variant, 16 Module, Static, Struct, Trait, TyBuilder, Type, TypeAlias, TypeParam, Union, Variant,
17}; 17};
18 18
19impl HirDisplay for Function { 19impl HirDisplay for Function {
20 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { 20 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
21 let data = f.db.function_data(self.id); 21 let data = f.db.function_data(self.id);
22 write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; 22 write_visibility(self.module(f.db).id, self.visibility(f.db), f)?;
23 let qual = &data.qualifier; 23 if data.is_default() {
24 if qual.is_default {
25 write!(f, "default ")?; 24 write!(f, "default ")?;
26 } 25 }
27 if qual.is_const { 26 if data.is_const() {
28 write!(f, "const ")?; 27 write!(f, "const ")?;
29 } 28 }
30 if qual.is_async { 29 if data.is_async() {
31 write!(f, "async ")?; 30 write!(f, "async ")?;
32 } 31 }
33 if qual.is_unsafe { 32 if data.is_unsafe() {
34 write!(f, "unsafe ")?; 33 write!(f, "unsafe ")?;
35 } 34 }
36 if let Some(abi) = &qual.abi { 35 if let Some(abi) = &data.abi {
37 // FIXME: String escape? 36 // FIXME: String escape?
38 write!(f, "extern \"{}\" ", abi)?; 37 write!(f, "extern \"{}\" ", &**abi)?;
39 } 38 }
40 write!(f, "fn {}", data.name)?; 39 write!(f, "fn {}", data.name)?;
41 40
@@ -68,7 +67,7 @@ impl HirDisplay for Function {
68 write!(f, ", ")?; 67 write!(f, ", ")?;
69 } else { 68 } else {
70 first = false; 69 first = false;
71 if data.has_self_param { 70 if data.has_self_param() {
72 write_self_param(type_ref, f)?; 71 write_self_param(type_ref, f)?;
73 continue; 72 continue;
74 } 73 }
@@ -88,10 +87,10 @@ impl HirDisplay for Function {
88 // `FunctionData::ret_type` will be `::core::future::Future<Output = ...>` for async fns. 87 // `FunctionData::ret_type` will be `::core::future::Future<Output = ...>` for async fns.
89 // Use ugly pattern match to strip the Future trait. 88 // Use ugly pattern match to strip the Future trait.
90 // Better way? 89 // Better way?
91 let ret_type = if !qual.is_async { 90 let ret_type = if !data.is_async() {
92 &data.ret_type 91 &data.ret_type
93 } else { 92 } else {
94 match &data.ret_type { 93 match &*data.ret_type {
95 TypeRef::ImplTrait(bounds) => match &bounds[0] { 94 TypeRef::ImplTrait(bounds) => match &bounds[0] {
96 TypeBound::Path(path) => { 95 TypeBound::Path(path) => {
97 path.segments().iter().last().unwrap().args_and_bindings.unwrap().bindings 96 path.segments().iter().last().unwrap().args_and_bindings.unwrap().bindings
@@ -235,7 +234,7 @@ impl HirDisplay for TypeParam {
235 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { 234 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
236 write!(f, "{}", self.name(f.db))?; 235 write!(f, "{}", self.name(f.db))?;
237 let bounds = f.db.generic_predicates_for_param(self.id); 236 let bounds = f.db.generic_predicates_for_param(self.id);
238 let substs = Substitution::type_params(f.db, self.id.parent); 237 let substs = TyBuilder::type_params_subst(f.db, self.id.parent);
239 let predicates = bounds.iter().cloned().map(|b| b.subst(&substs)).collect::<Vec<_>>(); 238 let predicates = bounds.iter().cloned().map(|b| b.subst(&substs)).collect::<Vec<_>>();
240 if !(predicates.is_empty() || f.omit_verbose_types()) { 239 if !(predicates.is_empty() || f.omit_verbose_types()) {
241 write_bounds_like_dyn_trait_with_prefix(":", &predicates, f)?; 240 write_bounds_like_dyn_trait_with_prefix(":", &predicates, f)?;
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 97f162315..19901ed33 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -55,11 +55,10 @@ use hir_ty::{
55 autoderef, could_unify, 55 autoderef, could_unify,
56 method_resolution::{self, TyFingerprint}, 56 method_resolution::{self, TyFingerprint},
57 primitive::UintTy, 57 primitive::UintTy,
58 to_assoc_type_id,
59 traits::{FnTrait, Solution, SolutionVariables}, 58 traits::{FnTrait, Solution, SolutionVariables},
60 AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, CanonicalVarKinds, Cast, 59 AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, CanonicalVarKinds, Cast,
61 DebruijnIndex, InEnvironment, Interner, ProjectionTy, QuantifiedWhereClause, Scalar, 60 DebruijnIndex, InEnvironment, Interner, QuantifiedWhereClause, Scalar, Substitution,
62 Substitution, TraitEnvironment, Ty, TyDefId, TyKind, TyVariableKind, WhereClause, 61 TraitEnvironment, Ty, TyBuilder, TyDefId, TyKind, TyVariableKind, WhereClause,
63}; 62};
64use itertools::Itertools; 63use itertools::Itertools;
65use rustc_hash::FxHashSet; 64use rustc_hash::FxHashSet;
@@ -515,7 +514,7 @@ impl Field {
515 VariantDef::Union(it) => it.id.into(), 514 VariantDef::Union(it) => it.id.into(),
516 VariantDef::Variant(it) => it.parent.id.into(), 515 VariantDef::Variant(it) => it.parent.id.into(),
517 }; 516 };
518 let substs = Substitution::type_params(db, generic_def_id); 517 let substs = TyBuilder::type_params_subst(db, generic_def_id);
519 let ty = db.field_types(var_id)[self.id].clone().subst(&substs); 518 let ty = db.field_types(var_id)[self.id].clone().subst(&substs);
520 Type::new(db, self.parent.module(db).id.krate(), var_id, ty) 519 Type::new(db, self.parent.module(db).id.krate(), var_id, ty)
521 } 520 }
@@ -832,7 +831,7 @@ impl Function {
832 } 831 }
833 832
834 pub fn self_param(self, db: &dyn HirDatabase) -> Option<SelfParam> { 833 pub fn self_param(self, db: &dyn HirDatabase) -> Option<SelfParam> {
835 if !db.function_data(self.id).has_self_param { 834 if !db.function_data(self.id).has_self_param() {
836 return None; 835 return None;
837 } 836 }
838 Some(SelfParam { func: self.id }) 837 Some(SelfParam { func: self.id })
@@ -864,7 +863,7 @@ impl Function {
864 } 863 }
865 864
866 pub fn is_unsafe(self, db: &dyn HirDatabase) -> bool { 865 pub fn is_unsafe(self, db: &dyn HirDatabase) -> bool {
867 db.function_data(self.id).qualifier.is_unsafe 866 db.function_data(self.id).is_unsafe()
868 } 867 }
869 868
870 pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) { 869 pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) {
@@ -878,7 +877,7 @@ impl Function {
878 /// 877 ///
879 /// This is false in the case of required (not provided) trait methods. 878 /// This is false in the case of required (not provided) trait methods.
880 pub fn has_body(self, db: &dyn HirDatabase) -> bool { 879 pub fn has_body(self, db: &dyn HirDatabase) -> bool {
881 db.function_data(self.id).has_body 880 db.function_data(self.id).has_body()
882 } 881 }
883 882
884 /// A textual representation of the HIR of this function for debugging purposes. 883 /// A textual representation of the HIR of this function for debugging purposes.
@@ -957,7 +956,7 @@ impl SelfParam {
957 func_data 956 func_data
958 .params 957 .params
959 .first() 958 .first()
960 .map(|param| match *param { 959 .map(|param| match &**param {
961 TypeRef::Reference(.., mutability) => match mutability { 960 TypeRef::Reference(.., mutability) => match mutability {
962 hir_def::type_ref::Mutability::Shared => Access::Shared, 961 hir_def::type_ref::Mutability::Shared => Access::Shared,
963 hir_def::type_ref::Mutability::Mut => Access::Exclusive, 962 hir_def::type_ref::Mutability::Mut => Access::Exclusive,
@@ -1011,7 +1010,7 @@ impl Const {
1011 } 1010 }
1012 1011
1013 pub fn type_ref(self, db: &dyn HirDatabase) -> TypeRef { 1012 pub fn type_ref(self, db: &dyn HirDatabase) -> TypeRef {
1014 db.const_data(self.id).type_ref.clone() 1013 db.const_data(self.id).type_ref.as_ref().clone()
1015 } 1014 }
1016} 1015}
1017 1016
@@ -1101,7 +1100,7 @@ impl TypeAlias {
1101 } 1100 }
1102 1101
1103 pub fn type_ref(self, db: &dyn HirDatabase) -> Option<TypeRef> { 1102 pub fn type_ref(self, db: &dyn HirDatabase) -> Option<TypeRef> {
1104 db.type_alias_data(self.id).type_ref.clone() 1103 db.type_alias_data(self.id).type_ref.as_deref().cloned()
1105 } 1104 }
1106 1105
1107 pub fn ty(self, db: &dyn HirDatabase) -> Type { 1106 pub fn ty(self, db: &dyn HirDatabase) -> Type {
@@ -1129,7 +1128,7 @@ pub struct BuiltinType {
1129impl BuiltinType { 1128impl BuiltinType {
1130 pub fn ty(self, db: &dyn HirDatabase, module: Module) -> Type { 1129 pub fn ty(self, db: &dyn HirDatabase, module: Module) -> Type {
1131 let resolver = module.id.resolver(db.upcast()); 1130 let resolver = module.id.resolver(db.upcast());
1132 Type::new_with_resolver(db, &resolver, Ty::builtin(self.inner)) 1131 Type::new_with_resolver(db, &resolver, TyBuilder::builtin(self.inner))
1133 .expect("crate not present in resolver") 1132 .expect("crate not present in resolver")
1134 } 1133 }
1135 1134
@@ -1502,7 +1501,7 @@ impl TypeParam {
1502 let resolver = self.id.parent.resolver(db.upcast()); 1501 let resolver = self.id.parent.resolver(db.upcast());
1503 let krate = self.id.parent.module(db.upcast()).krate(); 1502 let krate = self.id.parent.module(db.upcast()).krate();
1504 let ty = params.get(local_idx)?.clone(); 1503 let ty = params.get(local_idx)?.clone();
1505 let subst = Substitution::type_params(db, self.id.parent); 1504 let subst = TyBuilder::type_params_subst(db, self.id.parent);
1506 let ty = ty.subst(&subst.prefix(local_idx)); 1505 let ty = ty.subst(&subst.prefix(local_idx));
1507 Some(Type::new_with_resolver_inner(db, krate, &resolver, ty)) 1506 Some(Type::new_with_resolver_inner(db, krate, &resolver, ty))
1508 } 1507 }
@@ -1615,7 +1614,7 @@ impl Impl {
1615 // FIXME: the return type is wrong. This should be a hir version of 1614 // FIXME: the return type is wrong. This should be a hir version of
1616 // `TraitRef` (ie, resolved `TypeRef`). 1615 // `TraitRef` (ie, resolved `TypeRef`).
1617 pub fn trait_(self, db: &dyn HirDatabase) -> Option<TraitRef> { 1616 pub fn trait_(self, db: &dyn HirDatabase) -> Option<TraitRef> {
1618 db.impl_data(self.id).target_trait.clone() 1617 db.impl_data(self.id).target_trait.as_deref().cloned()
1619 } 1618 }
1620 1619
1621 pub fn self_ty(self, db: &dyn HirDatabase) -> Type { 1620 pub fn self_ty(self, db: &dyn HirDatabase) -> Type {
@@ -1703,30 +1702,29 @@ impl Type {
1703 fn from_def( 1702 fn from_def(
1704 db: &dyn HirDatabase, 1703 db: &dyn HirDatabase,
1705 krate: CrateId, 1704 krate: CrateId,
1706 def: impl HasResolver + Into<TyDefId> + Into<GenericDefId>, 1705 def: impl HasResolver + Into<TyDefId>,
1707 ) -> Type { 1706 ) -> Type {
1708 let substs = Substitution::build_for_def(db, def).fill_with_unknown().build(); 1707 let ty = TyBuilder::def_ty(db, def.into()).fill_with_unknown().build();
1709 let ty = db.ty(def.into()).subst(&substs);
1710 Type::new(db, krate, def, ty) 1708 Type::new(db, krate, def, ty)
1711 } 1709 }
1712 1710
1713 pub fn is_unit(&self) -> bool { 1711 pub fn is_unit(&self) -> bool {
1714 matches!(self.ty.interned(&Interner), TyKind::Tuple(0, ..)) 1712 matches!(self.ty.kind(&Interner), TyKind::Tuple(0, ..))
1715 } 1713 }
1716 pub fn is_bool(&self) -> bool { 1714 pub fn is_bool(&self) -> bool {
1717 matches!(self.ty.interned(&Interner), TyKind::Scalar(Scalar::Bool)) 1715 matches!(self.ty.kind(&Interner), TyKind::Scalar(Scalar::Bool))
1718 } 1716 }
1719 1717
1720 pub fn is_mutable_reference(&self) -> bool { 1718 pub fn is_mutable_reference(&self) -> bool {
1721 matches!(self.ty.interned(&Interner), TyKind::Ref(hir_ty::Mutability::Mut, ..)) 1719 matches!(self.ty.kind(&Interner), TyKind::Ref(hir_ty::Mutability::Mut, ..))
1722 } 1720 }
1723 1721
1724 pub fn is_usize(&self) -> bool { 1722 pub fn is_usize(&self) -> bool {
1725 matches!(self.ty.interned(&Interner), TyKind::Scalar(Scalar::Uint(UintTy::Usize))) 1723 matches!(self.ty.kind(&Interner), TyKind::Scalar(Scalar::Uint(UintTy::Usize)))
1726 } 1724 }
1727 1725
1728 pub fn remove_ref(&self) -> Option<Type> { 1726 pub fn remove_ref(&self) -> Option<Type> {
1729 match &self.ty.interned(&Interner) { 1727 match &self.ty.kind(&Interner) {
1730 TyKind::Ref(.., ty) => Some(self.derived(ty.clone())), 1728 TyKind::Ref(.., ty) => Some(self.derived(ty.clone())),
1731 _ => None, 1729 _ => None,
1732 } 1730 }
@@ -1785,13 +1783,10 @@ impl Type {
1785 } 1783 }
1786 1784
1787 pub fn impls_trait(&self, db: &dyn HirDatabase, trait_: Trait, args: &[Type]) -> bool { 1785 pub fn impls_trait(&self, db: &dyn HirDatabase, trait_: Trait, args: &[Type]) -> bool {
1788 let trait_ref = hir_ty::TraitRef { 1786 let trait_ref = TyBuilder::trait_ref(db, trait_.id)
1789 trait_id: hir_ty::to_chalk_trait_id(trait_.id), 1787 .push(self.ty.clone())
1790 substitution: Substitution::build_for_def(db, trait_.id) 1788 .fill(args.iter().map(|t| t.ty.clone()))
1791 .push(self.ty.clone()) 1789 .build();
1792 .fill(args.iter().map(|t| t.ty.clone()))
1793 .build(),
1794 };
1795 1790
1796 let goal = Canonical { 1791 let goal = Canonical {
1797 value: hir_ty::InEnvironment::new(self.env.env.clone(), trait_ref.cast(&Interner)), 1792 value: hir_ty::InEnvironment::new(self.env.env.clone(), trait_ref.cast(&Interner)),
@@ -1804,11 +1799,10 @@ impl Type {
1804 pub fn normalize_trait_assoc_type( 1799 pub fn normalize_trait_assoc_type(
1805 &self, 1800 &self,
1806 db: &dyn HirDatabase, 1801 db: &dyn HirDatabase,
1807 trait_: Trait,
1808 args: &[Type], 1802 args: &[Type],
1809 alias: TypeAlias, 1803 alias: TypeAlias,
1810 ) -> Option<Type> { 1804 ) -> Option<Type> {
1811 let subst = Substitution::build_for_def(db, trait_.id) 1805 let projection = TyBuilder::assoc_type_projection(db, alias.id)
1812 .push(self.ty.clone()) 1806 .push(self.ty.clone())
1813 .fill(args.iter().map(|t| t.ty.clone())) 1807 .fill(args.iter().map(|t| t.ty.clone()))
1814 .build(); 1808 .build();
@@ -1816,10 +1810,7 @@ impl Type {
1816 InEnvironment::new( 1810 InEnvironment::new(
1817 self.env.env.clone(), 1811 self.env.env.clone(),
1818 AliasEq { 1812 AliasEq {
1819 alias: AliasTy::Projection(ProjectionTy { 1813 alias: AliasTy::Projection(projection),
1820 associated_ty_id: to_assoc_type_id(alias.id),
1821 substitution: subst,
1822 }),
1823 ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)) 1814 ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
1824 .intern(&Interner), 1815 .intern(&Interner),
1825 } 1816 }
@@ -1829,9 +1820,11 @@ impl Type {
1829 ); 1820 );
1830 1821
1831 match db.trait_solve(self.krate, goal)? { 1822 match db.trait_solve(self.krate, goal)? {
1832 Solution::Unique(SolutionVariables(subst)) => { 1823 Solution::Unique(SolutionVariables(subst)) => subst
1833 subst.value.first().map(|ty| self.derived(ty.clone())) 1824 .value
1834 } 1825 .interned(&Interner)
1826 .first()
1827 .map(|ty| self.derived(ty.assert_ty_ref(&Interner).clone())),
1835 Solution::Ambig(_) => None, 1828 Solution::Ambig(_) => None,
1836 } 1829 }
1837 } 1830 }
@@ -1853,15 +1846,15 @@ impl Type {
1853 } 1846 }
1854 1847
1855 pub fn is_closure(&self) -> bool { 1848 pub fn is_closure(&self) -> bool {
1856 matches!(&self.ty.interned(&Interner), TyKind::Closure { .. }) 1849 matches!(&self.ty.kind(&Interner), TyKind::Closure { .. })
1857 } 1850 }
1858 1851
1859 pub fn is_fn(&self) -> bool { 1852 pub fn is_fn(&self) -> bool {
1860 matches!(&self.ty.interned(&Interner), TyKind::FnDef(..) | TyKind::Function { .. }) 1853 matches!(&self.ty.kind(&Interner), TyKind::FnDef(..) | TyKind::Function { .. })
1861 } 1854 }
1862 1855
1863 pub fn is_packed(&self, db: &dyn HirDatabase) -> bool { 1856 pub fn is_packed(&self, db: &dyn HirDatabase) -> bool {
1864 let adt_id = match self.ty.interned(&Interner) { 1857 let adt_id = match self.ty.kind(&Interner) {
1865 &TyKind::Adt(hir_ty::AdtId(adt_id), ..) => adt_id, 1858 &TyKind::Adt(hir_ty::AdtId(adt_id), ..) => adt_id,
1866 _ => return false, 1859 _ => return false,
1867 }; 1860 };
@@ -1874,14 +1867,14 @@ impl Type {
1874 } 1867 }
1875 1868
1876 pub fn is_raw_ptr(&self) -> bool { 1869 pub fn is_raw_ptr(&self) -> bool {
1877 matches!(&self.ty.interned(&Interner), TyKind::Raw(..)) 1870 matches!(&self.ty.kind(&Interner), TyKind::Raw(..))
1878 } 1871 }
1879 1872
1880 pub fn contains_unknown(&self) -> bool { 1873 pub fn contains_unknown(&self) -> bool {
1881 return go(&self.ty); 1874 return go(&self.ty);
1882 1875
1883 fn go(ty: &Ty) -> bool { 1876 fn go(ty: &Ty) -> bool {
1884 match ty.interned(&Interner) { 1877 match ty.kind(&Interner) {
1885 TyKind::Unknown => true, 1878 TyKind::Unknown => true,
1886 1879
1887 TyKind::Adt(_, substs) 1880 TyKind::Adt(_, substs)
@@ -1889,7 +1882,9 @@ impl Type {
1889 | TyKind::Tuple(_, substs) 1882 | TyKind::Tuple(_, substs)
1890 | TyKind::OpaqueType(_, substs) 1883 | TyKind::OpaqueType(_, substs)
1891 | TyKind::FnDef(_, substs) 1884 | TyKind::FnDef(_, substs)
1892 | TyKind::Closure(_, substs) => substs.iter().any(go), 1885 | TyKind::Closure(_, substs) => {
1886 substs.iter(&Interner).filter_map(|a| a.ty(&Interner)).any(go)
1887 }
1893 1888
1894 TyKind::Array(ty) | TyKind::Slice(ty) | TyKind::Raw(_, ty) | TyKind::Ref(_, ty) => { 1889 TyKind::Array(ty) | TyKind::Slice(ty) | TyKind::Raw(_, ty) | TyKind::Ref(_, ty) => {
1895 go(ty) 1890 go(ty)
@@ -1910,7 +1905,7 @@ impl Type {
1910 } 1905 }
1911 1906
1912 pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)> { 1907 pub fn fields(&self, db: &dyn HirDatabase) -> Vec<(Field, Type)> {
1913 let (variant_id, substs) = match self.ty.interned(&Interner) { 1908 let (variant_id, substs) = match self.ty.kind(&Interner) {
1914 &TyKind::Adt(hir_ty::AdtId(AdtId::StructId(s)), ref substs) => (s.into(), substs), 1909 &TyKind::Adt(hir_ty::AdtId(AdtId::StructId(s)), ref substs) => (s.into(), substs),
1915 &TyKind::Adt(hir_ty::AdtId(AdtId::UnionId(u)), ref substs) => (u.into(), substs), 1910 &TyKind::Adt(hir_ty::AdtId(AdtId::UnionId(u)), ref substs) => (u.into(), substs),
1916 _ => return Vec::new(), 1911 _ => return Vec::new(),
@@ -1927,8 +1922,11 @@ impl Type {
1927 } 1922 }
1928 1923
1929 pub fn tuple_fields(&self, _db: &dyn HirDatabase) -> Vec<Type> { 1924 pub fn tuple_fields(&self, _db: &dyn HirDatabase) -> Vec<Type> {
1930 if let TyKind::Tuple(_, substs) = &self.ty.interned(&Interner) { 1925 if let TyKind::Tuple(_, substs) = &self.ty.kind(&Interner) {
1931 substs.iter().map(|ty| self.derived(ty.clone())).collect() 1926 substs
1927 .iter(&Interner)
1928 .map(|ty| self.derived(ty.assert_ty_ref(&Interner).clone()))
1929 .collect()
1932 } else { 1930 } else {
1933 Vec::new() 1931 Vec::new()
1934 } 1932 }
@@ -1973,8 +1971,9 @@ impl Type {
1973 .strip_references() 1971 .strip_references()
1974 .substs() 1972 .substs()
1975 .into_iter() 1973 .into_iter()
1976 .flat_map(|substs| substs.iter()) 1974 .flat_map(|substs| substs.iter(&Interner))
1977 .map(move |ty| self.derived(ty.clone())) 1975 .filter_map(|arg| arg.ty(&Interner).cloned())
1976 .map(move |ty| self.derived(ty))
1978 } 1977 }
1979 1978
1980 pub fn iterate_method_candidates<T>( 1979 pub fn iterate_method_candidates<T>(
@@ -2080,7 +2079,7 @@ impl Type {
2080 substs: &Substitution, 2079 substs: &Substitution,
2081 cb: &mut impl FnMut(Type), 2080 cb: &mut impl FnMut(Type),
2082 ) { 2081 ) {
2083 for ty in substs.iter() { 2082 for ty in substs.iter(&Interner).filter_map(|a| a.ty(&Interner)) {
2084 walk_type(db, &type_.derived(ty.clone()), cb); 2083 walk_type(db, &type_.derived(ty.clone()), cb);
2085 } 2084 }
2086 } 2085 }
@@ -2096,7 +2095,12 @@ impl Type {
2096 WhereClause::Implemented(trait_ref) => { 2095 WhereClause::Implemented(trait_ref) => {
2097 cb(type_.clone()); 2096 cb(type_.clone());
2098 // skip the self type. it's likely the type we just got the bounds from 2097 // skip the self type. it's likely the type we just got the bounds from
2099 for ty in trait_ref.substitution.iter().skip(1) { 2098 for ty in trait_ref
2099 .substitution
2100 .iter(&Interner)
2101 .skip(1)
2102 .filter_map(|a| a.ty(&Interner))
2103 {
2100 walk_type(db, &type_.derived(ty.clone()), cb); 2104 walk_type(db, &type_.derived(ty.clone()), cb);
2101 } 2105 }
2102 } 2106 }
@@ -2107,7 +2111,7 @@ impl Type {
2107 2111
2108 fn walk_type(db: &dyn HirDatabase, type_: &Type, cb: &mut impl FnMut(Type)) { 2112 fn walk_type(db: &dyn HirDatabase, type_: &Type, cb: &mut impl FnMut(Type)) {
2109 let ty = type_.ty.strip_references(); 2113 let ty = type_.ty.strip_references();
2110 match ty.interned(&Interner) { 2114 match ty.kind(&Interner) {
2111 TyKind::Adt(..) => { 2115 TyKind::Adt(..) => {
2112 cb(type_.derived(ty.clone())); 2116 cb(type_.derived(ty.clone()));
2113 } 2117 }