aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/lib.rs')
-rw-r--r--crates/hir_ty/src/lib.rs40
1 files changed, 20 insertions, 20 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index c927ed973..4c3d904bf 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -312,7 +312,7 @@ impl TyKind {
312} 312}
313 313
314impl Ty { 314impl Ty {
315 pub fn interned(&self, _interner: &Interner) -> &TyKind { 315 pub fn kind(&self, _interner: &Interner) -> &TyKind {
316 &self.0 316 &self.0
317 } 317 }
318 318
@@ -846,14 +846,14 @@ impl Ty {
846 } 846 }
847 847
848 pub fn as_reference(&self) -> Option<(&Ty, Mutability)> { 848 pub fn as_reference(&self) -> Option<(&Ty, Mutability)> {
849 match self.interned(&Interner) { 849 match self.kind(&Interner) {
850 TyKind::Ref(mutability, ty) => Some((ty, *mutability)), 850 TyKind::Ref(mutability, ty) => Some((ty, *mutability)),
851 _ => None, 851 _ => None,
852 } 852 }
853 } 853 }
854 854
855 pub fn as_reference_or_ptr(&self) -> Option<(&Ty, Rawness, Mutability)> { 855 pub fn as_reference_or_ptr(&self) -> Option<(&Ty, Rawness, Mutability)> {
856 match self.interned(&Interner) { 856 match self.kind(&Interner) {
857 TyKind::Ref(mutability, ty) => Some((ty, Rawness::Ref, *mutability)), 857 TyKind::Ref(mutability, ty) => Some((ty, Rawness::Ref, *mutability)),
858 TyKind::Raw(mutability, ty) => Some((ty, Rawness::RawPtr, *mutability)), 858 TyKind::Raw(mutability, ty) => Some((ty, Rawness::RawPtr, *mutability)),
859 _ => None, 859 _ => None,
@@ -863,7 +863,7 @@ impl Ty {
863 pub fn strip_references(&self) -> &Ty { 863 pub fn strip_references(&self) -> &Ty {
864 let mut t: &Ty = self; 864 let mut t: &Ty = self;
865 865
866 while let TyKind::Ref(_mutability, ty) = t.interned(&Interner) { 866 while let TyKind::Ref(_mutability, ty) = t.kind(&Interner) {
867 t = ty; 867 t = ty;
868 } 868 }
869 869
@@ -871,21 +871,21 @@ impl Ty {
871 } 871 }
872 872
873 pub fn as_adt(&self) -> Option<(hir_def::AdtId, &Substitution)> { 873 pub fn as_adt(&self) -> Option<(hir_def::AdtId, &Substitution)> {
874 match self.interned(&Interner) { 874 match self.kind(&Interner) {
875 TyKind::Adt(AdtId(adt), parameters) => Some((*adt, parameters)), 875 TyKind::Adt(AdtId(adt), parameters) => Some((*adt, parameters)),
876 _ => None, 876 _ => None,
877 } 877 }
878 } 878 }
879 879
880 pub fn as_tuple(&self) -> Option<&Substitution> { 880 pub fn as_tuple(&self) -> Option<&Substitution> {
881 match self.interned(&Interner) { 881 match self.kind(&Interner) {
882 TyKind::Tuple(_, substs) => Some(substs), 882 TyKind::Tuple(_, substs) => Some(substs),
883 _ => None, 883 _ => None,
884 } 884 }
885 } 885 }
886 886
887 pub fn as_generic_def(&self, db: &dyn HirDatabase) -> Option<GenericDefId> { 887 pub fn as_generic_def(&self, db: &dyn HirDatabase) -> Option<GenericDefId> {
888 match *self.interned(&Interner) { 888 match *self.kind(&Interner) {
889 TyKind::Adt(AdtId(adt), ..) => Some(adt.into()), 889 TyKind::Adt(AdtId(adt), ..) => Some(adt.into()),
890 TyKind::FnDef(callable, ..) => { 890 TyKind::FnDef(callable, ..) => {
891 Some(db.lookup_intern_callable_def(callable.into()).into()) 891 Some(db.lookup_intern_callable_def(callable.into()).into())
@@ -897,15 +897,15 @@ impl Ty {
897 } 897 }
898 898
899 pub fn is_never(&self) -> bool { 899 pub fn is_never(&self) -> bool {
900 matches!(self.interned(&Interner), TyKind::Never) 900 matches!(self.kind(&Interner), TyKind::Never)
901 } 901 }
902 902
903 pub fn is_unknown(&self) -> bool { 903 pub fn is_unknown(&self) -> bool {
904 matches!(self.interned(&Interner), TyKind::Unknown) 904 matches!(self.kind(&Interner), TyKind::Unknown)
905 } 905 }
906 906
907 pub fn equals_ctor(&self, other: &Ty) -> bool { 907 pub fn equals_ctor(&self, other: &Ty) -> bool {
908 match (self.interned(&Interner), other.interned(&Interner)) { 908 match (self.kind(&Interner), other.kind(&Interner)) {
909 (TyKind::Adt(adt, ..), TyKind::Adt(adt2, ..)) => adt == adt2, 909 (TyKind::Adt(adt, ..), TyKind::Adt(adt2, ..)) => adt == adt2,
910 (TyKind::Slice(_), TyKind::Slice(_)) | (TyKind::Array(_), TyKind::Array(_)) => true, 910 (TyKind::Slice(_), TyKind::Slice(_)) | (TyKind::Array(_), TyKind::Array(_)) => true,
911 (TyKind::FnDef(def_id, ..), TyKind::FnDef(def_id2, ..)) => def_id == def_id2, 911 (TyKind::FnDef(def_id, ..), TyKind::FnDef(def_id2, ..)) => def_id == def_id2,
@@ -934,7 +934,7 @@ impl Ty {
934 934
935 /// If this is a `dyn Trait` type, this returns the `Trait` part. 935 /// If this is a `dyn Trait` type, this returns the `Trait` part.
936 fn dyn_trait_ref(&self) -> Option<&TraitRef> { 936 fn dyn_trait_ref(&self) -> Option<&TraitRef> {
937 match self.interned(&Interner) { 937 match self.kind(&Interner) {
938 TyKind::Dyn(dyn_ty) => { 938 TyKind::Dyn(dyn_ty) => {
939 dyn_ty.bounds.value.interned().get(0).and_then(|b| match b.skip_binders() { 939 dyn_ty.bounds.value.interned().get(0).and_then(|b| match b.skip_binders() {
940 WhereClause::Implemented(trait_ref) => Some(trait_ref), 940 WhereClause::Implemented(trait_ref) => Some(trait_ref),
@@ -951,7 +951,7 @@ impl Ty {
951 } 951 }
952 952
953 fn builtin_deref(&self) -> Option<Ty> { 953 fn builtin_deref(&self) -> Option<Ty> {
954 match self.interned(&Interner) { 954 match self.kind(&Interner) {
955 TyKind::Ref(.., ty) => Some(ty.clone()), 955 TyKind::Ref(.., ty) => Some(ty.clone()),
956 TyKind::Raw(.., ty) => Some(ty.clone()), 956 TyKind::Raw(.., ty) => Some(ty.clone()),
957 _ => None, 957 _ => None,
@@ -959,7 +959,7 @@ impl Ty {
959 } 959 }
960 960
961 pub fn callable_def(&self, db: &dyn HirDatabase) -> Option<CallableDefId> { 961 pub fn callable_def(&self, db: &dyn HirDatabase) -> Option<CallableDefId> {
962 match self.interned(&Interner) { 962 match self.kind(&Interner) {
963 &TyKind::FnDef(def, ..) => Some(db.lookup_intern_callable_def(def.into())), 963 &TyKind::FnDef(def, ..) => Some(db.lookup_intern_callable_def(def.into())),
964 _ => None, 964 _ => None,
965 } 965 }
@@ -974,7 +974,7 @@ impl Ty {
974 } 974 }
975 975
976 pub fn callable_sig(&self, db: &dyn HirDatabase) -> Option<CallableSig> { 976 pub fn callable_sig(&self, db: &dyn HirDatabase) -> Option<CallableSig> {
977 match self.interned(&Interner) { 977 match self.kind(&Interner) {
978 TyKind::Function(fn_ptr) => Some(CallableSig::from_fn_ptr(fn_ptr)), 978 TyKind::Function(fn_ptr) => Some(CallableSig::from_fn_ptr(fn_ptr)),
979 TyKind::FnDef(def, parameters) => { 979 TyKind::FnDef(def, parameters) => {
980 let callable_def = db.lookup_intern_callable_def((*def).into()); 980 let callable_def = db.lookup_intern_callable_def((*def).into());
@@ -992,7 +992,7 @@ impl Ty {
992 /// Returns the type parameters of this type if it has some (i.e. is an ADT 992 /// Returns the type parameters of this type if it has some (i.e. is an ADT
993 /// or function); so if `self` is `Option<u32>`, this returns the `u32`. 993 /// or function); so if `self` is `Option<u32>`, this returns the `u32`.
994 pub fn substs(&self) -> Option<&Substitution> { 994 pub fn substs(&self) -> Option<&Substitution> {
995 match self.interned(&Interner) { 995 match self.kind(&Interner) {
996 TyKind::Adt(_, substs) 996 TyKind::Adt(_, substs)
997 | TyKind::FnDef(_, substs) 997 | TyKind::FnDef(_, substs)
998 | TyKind::Function(FnPointer { substs, .. }) 998 | TyKind::Function(FnPointer { substs, .. })
@@ -1018,7 +1018,7 @@ impl Ty {
1018 } 1018 }
1019 1019
1020 pub fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<QuantifiedWhereClause>> { 1020 pub fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<QuantifiedWhereClause>> {
1021 match self.interned(&Interner) { 1021 match self.kind(&Interner) {
1022 TyKind::OpaqueType(opaque_ty_id, ..) => { 1022 TyKind::OpaqueType(opaque_ty_id, ..) => {
1023 match db.lookup_intern_impl_trait_id((*opaque_ty_id).into()) { 1023 match db.lookup_intern_impl_trait_id((*opaque_ty_id).into()) {
1024 ImplTraitId::AsyncBlockTypeImplTrait(def, _expr) => { 1024 ImplTraitId::AsyncBlockTypeImplTrait(def, _expr) => {
@@ -1093,7 +1093,7 @@ impl Ty {
1093 } 1093 }
1094 1094
1095 pub fn associated_type_parent_trait(&self, db: &dyn HirDatabase) -> Option<TraitId> { 1095 pub fn associated_type_parent_trait(&self, db: &dyn HirDatabase) -> Option<TraitId> {
1096 match self.interned(&Interner) { 1096 match self.kind(&Interner) {
1097 TyKind::AssociatedType(id, ..) => { 1097 TyKind::AssociatedType(id, ..) => {
1098 match from_assoc_type_id(*id).lookup(db.upcast()).container { 1098 match from_assoc_type_id(*id).lookup(db.upcast()).container {
1099 AssocContainerId::TraitId(trait_id) => Some(trait_id), 1099 AssocContainerId::TraitId(trait_id) => Some(trait_id),
@@ -1201,7 +1201,7 @@ pub trait TypeWalk {
1201 Self: Sized, 1201 Self: Sized,
1202 { 1202 {
1203 self.fold_binders( 1203 self.fold_binders(
1204 &mut |ty, binders| match ty.interned(&Interner) { 1204 &mut |ty, binders| match ty.kind(&Interner) {
1205 TyKind::BoundVar(bound) if bound.debruijn >= binders => { 1205 TyKind::BoundVar(bound) if bound.debruijn >= binders => {
1206 TyKind::BoundVar(bound.shifted_in_from(n)).intern(&Interner) 1206 TyKind::BoundVar(bound.shifted_in_from(n)).intern(&Interner)
1207 } 1207 }
@@ -1217,7 +1217,7 @@ pub trait TypeWalk {
1217 Self: Sized + std::fmt::Debug, 1217 Self: Sized + std::fmt::Debug,
1218 { 1218 {
1219 self.fold_binders( 1219 self.fold_binders(
1220 &mut |ty, binders| match ty.interned(&Interner) { 1220 &mut |ty, binders| match ty.kind(&Interner) {
1221 TyKind::BoundVar(bound) if bound.debruijn >= binders => { 1221 TyKind::BoundVar(bound) if bound.debruijn >= binders => {
1222 TyKind::BoundVar(bound.shifted_out_to(n).unwrap_or(bound.clone())) 1222 TyKind::BoundVar(bound.shifted_out_to(n).unwrap_or(bound.clone()))
1223 .intern(&Interner) 1223 .intern(&Interner)
@@ -1231,7 +1231,7 @@ pub trait TypeWalk {
1231 1231
1232impl TypeWalk for Ty { 1232impl TypeWalk for Ty {
1233 fn walk(&self, f: &mut impl FnMut(&Ty)) { 1233 fn walk(&self, f: &mut impl FnMut(&Ty)) {
1234 match self.interned(&Interner) { 1234 match self.kind(&Interner) {
1235 TyKind::Alias(AliasTy::Projection(p_ty)) => { 1235 TyKind::Alias(AliasTy::Projection(p_ty)) => {
1236 for t in p_ty.substitution.iter(&Interner) { 1236 for t in p_ty.substitution.iter(&Interner) {
1237 t.walk(f); 1237 t.walk(f);