diff options
Diffstat (limited to 'crates/hir_ty/src/lib.rs')
-rw-r--r-- | crates/hir_ty/src/lib.rs | 60 |
1 files changed, 1 insertions, 59 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index ae3987752..2e851d3e0 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs | |||
@@ -168,65 +168,7 @@ impl CallableSig { | |||
168 | } | 168 | } |
169 | } | 169 | } |
170 | 170 | ||
171 | impl Ty { | 171 | impl Ty {} |
172 | pub fn equals_ctor(&self, other: &Ty) -> bool { | ||
173 | match (self.kind(&Interner), other.kind(&Interner)) { | ||
174 | (TyKind::Adt(adt, ..), TyKind::Adt(adt2, ..)) => adt == adt2, | ||
175 | (TyKind::Slice(_), TyKind::Slice(_)) | (TyKind::Array(_, _), TyKind::Array(_, _)) => { | ||
176 | true | ||
177 | } | ||
178 | (TyKind::FnDef(def_id, ..), TyKind::FnDef(def_id2, ..)) => def_id == def_id2, | ||
179 | (TyKind::OpaqueType(ty_id, ..), TyKind::OpaqueType(ty_id2, ..)) => ty_id == ty_id2, | ||
180 | (TyKind::AssociatedType(ty_id, ..), TyKind::AssociatedType(ty_id2, ..)) => { | ||
181 | ty_id == ty_id2 | ||
182 | } | ||
183 | (TyKind::Foreign(ty_id, ..), TyKind::Foreign(ty_id2, ..)) => ty_id == ty_id2, | ||
184 | (TyKind::Closure(id1, _), TyKind::Closure(id2, _)) => id1 == id2, | ||
185 | (TyKind::Ref(mutability, ..), TyKind::Ref(mutability2, ..)) | ||
186 | | (TyKind::Raw(mutability, ..), TyKind::Raw(mutability2, ..)) => { | ||
187 | mutability == mutability2 | ||
188 | } | ||
189 | ( | ||
190 | TyKind::Function(FnPointer { num_binders, sig, .. }), | ||
191 | TyKind::Function(FnPointer { num_binders: num_binders2, sig: sig2, .. }), | ||
192 | ) => num_binders == num_binders2 && sig == sig2, | ||
193 | (TyKind::Tuple(cardinality, _), TyKind::Tuple(cardinality2, _)) => { | ||
194 | cardinality == cardinality2 | ||
195 | } | ||
196 | (TyKind::Str, TyKind::Str) | (TyKind::Never, TyKind::Never) => true, | ||
197 | (TyKind::Scalar(scalar), TyKind::Scalar(scalar2)) => scalar == scalar2, | ||
198 | _ => false, | ||
199 | } | ||
200 | } | ||
201 | |||
202 | /// Returns the type parameters of this type if it has some (i.e. is an ADT | ||
203 | /// or function); so if `self` is `Option<u32>`, this returns the `u32`. | ||
204 | pub fn substs(&self) -> Option<&Substitution> { | ||
205 | match self.kind(&Interner) { | ||
206 | TyKind::Adt(_, substs) | ||
207 | | TyKind::FnDef(_, substs) | ||
208 | | TyKind::Tuple(_, substs) | ||
209 | | TyKind::OpaqueType(_, substs) | ||
210 | | TyKind::AssociatedType(_, substs) | ||
211 | | TyKind::Closure(.., substs) => Some(substs), | ||
212 | TyKind::Function(FnPointer { substitution: substs, .. }) => Some(&substs.0), | ||
213 | _ => None, | ||
214 | } | ||
215 | } | ||
216 | |||
217 | fn substs_mut(&mut self) -> Option<&mut Substitution> { | ||
218 | match self.interned_mut() { | ||
219 | TyKind::Adt(_, substs) | ||
220 | | TyKind::FnDef(_, substs) | ||
221 | | TyKind::Tuple(_, substs) | ||
222 | | TyKind::OpaqueType(_, substs) | ||
223 | | TyKind::AssociatedType(_, substs) | ||
224 | | TyKind::Closure(.., substs) => Some(substs), | ||
225 | TyKind::Function(FnPointer { substitution: substs, .. }) => Some(&mut substs.0), | ||
226 | _ => None, | ||
227 | } | ||
228 | } | ||
229 | } | ||
230 | 172 | ||
231 | #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] | 173 | #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] |
232 | pub enum ImplTraitId { | 174 | pub enum ImplTraitId { |