aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/lib.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-03-14 15:34:37 +0000
committerGitHub <[email protected]>2021-03-14 15:34:37 +0000
commit406e4be04c2e74d58bcaa7e823e2509d1a7803d4 (patch)
tree79dcaa50fe38214d03c4e60b3738ca578e09d659 /crates/hir_ty/src/lib.rs
parentf57e2f55984758a83644b852a4cc47e0b27945df (diff)
parent195414783402d6973f4e673e84be9b7bc19cbfa6 (diff)
Merge #8016
8016: More Chalk adaptations r=flodiebold a=flodiebold - rename a bunch of fields - use `chalk_ir::FnSig` Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/lib.rs')
-rw-r--r--crates/hir_ty/src/lib.rs37
1 files changed, 18 insertions, 19 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index d6ff968f0..484652073 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -46,7 +46,7 @@ pub use lower::{
46}; 46};
47pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment}; 47pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment};
48 48
49pub use chalk_ir::{AdtId, BoundVar, DebruijnIndex, Mutability, Scalar, TyVariableKind}; 49pub use chalk_ir::{AdtId, BoundVar, DebruijnIndex, Mutability, Safety, Scalar, TyVariableKind};
50 50
51pub use crate::traits::chalk::Interner; 51pub use crate::traits::chalk::Interner;
52 52
@@ -66,7 +66,7 @@ pub enum Lifetime {
66#[derive(Clone, PartialEq, Eq, Debug, Hash)] 66#[derive(Clone, PartialEq, Eq, Debug, Hash)]
67pub struct OpaqueTy { 67pub struct OpaqueTy {
68 pub opaque_ty_id: OpaqueTyId, 68 pub opaque_ty_id: OpaqueTyId,
69 pub parameters: Substs, 69 pub substitution: Substs,
70} 70}
71 71
72/// A "projection" type corresponds to an (unnormalized) 72/// A "projection" type corresponds to an (unnormalized)
@@ -74,17 +74,17 @@ pub struct OpaqueTy {
74/// trait and all its parameters are fully known. 74/// trait and all its parameters are fully known.
75#[derive(Clone, PartialEq, Eq, Debug, Hash)] 75#[derive(Clone, PartialEq, Eq, Debug, Hash)]
76pub struct ProjectionTy { 76pub struct ProjectionTy {
77 pub associated_ty: AssocTypeId, 77 pub associated_ty_id: AssocTypeId,
78 pub parameters: Substs, 78 pub substitution: Substs,
79} 79}
80 80
81impl ProjectionTy { 81impl ProjectionTy {
82 pub fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef { 82 pub fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef {
83 TraitRef { trait_: self.trait_(db), substs: self.parameters.clone() } 83 TraitRef { trait_: self.trait_(db), substs: self.substitution.clone() }
84 } 84 }
85 85
86 fn trait_(&self, db: &dyn HirDatabase) -> TraitId { 86 fn trait_(&self, db: &dyn HirDatabase) -> TraitId {
87 match from_assoc_type_id(self.associated_ty).lookup(db.upcast()).container { 87 match from_assoc_type_id(self.associated_ty_id).lookup(db.upcast()).container {
88 AssocContainerId::TraitId(it) => it, 88 AssocContainerId::TraitId(it) => it,
89 _ => panic!("projection ty without parent trait"), 89 _ => panic!("projection ty without parent trait"),
90 } 90 }
@@ -93,7 +93,7 @@ impl ProjectionTy {
93 93
94impl TypeWalk for ProjectionTy { 94impl TypeWalk for ProjectionTy {
95 fn walk(&self, f: &mut impl FnMut(&Ty)) { 95 fn walk(&self, f: &mut impl FnMut(&Ty)) {
96 self.parameters.walk(f); 96 self.substitution.walk(f);
97 } 97 }
98 98
99 fn walk_mut_binders( 99 fn walk_mut_binders(
@@ -101,14 +101,11 @@ impl TypeWalk for ProjectionTy {
101 f: &mut impl FnMut(&mut Ty, DebruijnIndex), 101 f: &mut impl FnMut(&mut Ty, DebruijnIndex),
102 binders: DebruijnIndex, 102 binders: DebruijnIndex,
103 ) { 103 ) {
104 self.parameters.walk_mut_binders(f, binders); 104 self.substitution.walk_mut_binders(f, binders);
105 } 105 }
106} 106}
107 107
108#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] 108pub type FnSig = chalk_ir::FnSig<Interner>;
109pub struct FnSig {
110 pub variadic: bool,
111}
112 109
113#[derive(Clone, PartialEq, Eq, Debug, Hash)] 110#[derive(Clone, PartialEq, Eq, Debug, Hash)]
114pub struct FnPointer { 111pub struct FnPointer {
@@ -643,7 +640,7 @@ impl Ty {
643 pub fn fn_ptr(sig: CallableSig) -> Self { 640 pub fn fn_ptr(sig: CallableSig) -> Self {
644 TyKind::Function(FnPointer { 641 TyKind::Function(FnPointer {
645 num_args: sig.params().len(), 642 num_args: sig.params().len(),
646 sig: FnSig { variadic: sig.is_varargs }, 643 sig: FnSig { abi: (), safety: Safety::Safe, variadic: sig.is_varargs },
647 substs: Substs(sig.params_and_return), 644 substs: Substs(sig.params_and_return),
648 }) 645 })
649 .intern(&Interner) 646 .intern(&Interner)
@@ -906,7 +903,7 @@ impl Ty {
906 let data = (*it) 903 let data = (*it)
907 .as_ref() 904 .as_ref()
908 .map(|rpit| rpit.impl_traits[idx as usize].bounds.clone()); 905 .map(|rpit| rpit.impl_traits[idx as usize].bounds.clone());
909 data.subst(&opaque_ty.parameters) 906 data.subst(&opaque_ty.substitution)
910 }) 907 })
911 } 908 }
912 // It always has an parameter for Future::Output type. 909 // It always has an parameter for Future::Output type.
@@ -945,7 +942,9 @@ impl Ty {
945 } 942 }
946 } 943 }
947 TyKind::Alias(AliasTy::Projection(projection_ty)) => { 944 TyKind::Alias(AliasTy::Projection(projection_ty)) => {
948 match from_assoc_type_id(projection_ty.associated_ty).lookup(db.upcast()).container 945 match from_assoc_type_id(projection_ty.associated_ty_id)
946 .lookup(db.upcast())
947 .container
949 { 948 {
950 AssocContainerId::TraitId(trait_id) => Some(trait_id), 949 AssocContainerId::TraitId(trait_id) => Some(trait_id),
951 _ => None, 950 _ => None,
@@ -1055,12 +1054,12 @@ impl TypeWalk for Ty {
1055 fn walk(&self, f: &mut impl FnMut(&Ty)) { 1054 fn walk(&self, f: &mut impl FnMut(&Ty)) {
1056 match self.interned(&Interner) { 1055 match self.interned(&Interner) {
1057 TyKind::Alias(AliasTy::Projection(p_ty)) => { 1056 TyKind::Alias(AliasTy::Projection(p_ty)) => {
1058 for t in p_ty.parameters.iter() { 1057 for t in p_ty.substitution.iter() {
1059 t.walk(f); 1058 t.walk(f);
1060 } 1059 }
1061 } 1060 }
1062 TyKind::Alias(AliasTy::Opaque(o_ty)) => { 1061 TyKind::Alias(AliasTy::Opaque(o_ty)) => {
1063 for t in o_ty.parameters.iter() { 1062 for t in o_ty.substitution.iter() {
1064 t.walk(f); 1063 t.walk(f);
1065 } 1064 }
1066 } 1065 }
@@ -1087,7 +1086,7 @@ impl TypeWalk for Ty {
1087 ) { 1086 ) {
1088 match &mut self.0 { 1087 match &mut self.0 {
1089 TyKind::Alias(AliasTy::Projection(p_ty)) => { 1088 TyKind::Alias(AliasTy::Projection(p_ty)) => {
1090 p_ty.parameters.walk_mut_binders(f, binders); 1089 p_ty.substitution.walk_mut_binders(f, binders);
1091 } 1090 }
1092 TyKind::Dyn(predicates) => { 1091 TyKind::Dyn(predicates) => {
1093 for p in make_mut_slice(predicates) { 1092 for p in make_mut_slice(predicates) {
@@ -1095,7 +1094,7 @@ impl TypeWalk for Ty {
1095 } 1094 }
1096 } 1095 }
1097 TyKind::Alias(AliasTy::Opaque(o_ty)) => { 1096 TyKind::Alias(AliasTy::Opaque(o_ty)) => {
1098 o_ty.parameters.walk_mut_binders(f, binders); 1097 o_ty.substitution.walk_mut_binders(f, binders);
1099 } 1098 }
1100 _ => { 1099 _ => {
1101 if let Some(substs) = self.substs_mut() { 1100 if let Some(substs) = self.substs_mut() {