diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-04-07 19:10:39 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-04-07 19:10:39 +0100 |
commit | 09b730d1e1b485ff582f3f237d39136ce50ea0cc (patch) | |
tree | 5c8162da0bd04ddf319ca27226b5f55c4665d5e6 /crates/hir_ty/src/chalk_ext.rs | |
parent | eb248d85a0eb91bae7bafcd69ffe4dfed3e32fce (diff) | |
parent | 4c35df47e84b0eff51faa95b4c9636bb5f3da5eb (diff) |
Merge #8407
8407: Move `equals_ctor` to `TyExt` r=flodiebold a=flodiebold
I'd prefer getting rid of it, but it's used in the impl search and not super easy to replace there (I think ideally the impl search would do proper unification, but that's a bit more complicated).
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/chalk_ext.rs')
-rw-r--r-- | crates/hir_ty/src/chalk_ext.rs | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/crates/hir_ty/src/chalk_ext.rs b/crates/hir_ty/src/chalk_ext.rs index 8e8a1aa48..6a353423a 100644 --- a/crates/hir_ty/src/chalk_ext.rs +++ b/crates/hir_ty/src/chalk_ext.rs | |||
@@ -8,7 +8,7 @@ use hir_def::{ | |||
8 | use crate::{ | 8 | use crate::{ |
9 | db::HirDatabase, from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id, | 9 | db::HirDatabase, from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id, |
10 | from_placeholder_idx, to_chalk_trait_id, AdtId, AliasEq, AliasTy, Binders, CallableDefId, | 10 | from_placeholder_idx, to_chalk_trait_id, AdtId, AliasEq, AliasTy, Binders, CallableDefId, |
11 | CallableSig, ImplTraitId, Interner, Lifetime, ProjectionTy, QuantifiedWhereClause, | 11 | CallableSig, FnPointer, ImplTraitId, Interner, Lifetime, ProjectionTy, QuantifiedWhereClause, |
12 | Substitution, TraitRef, Ty, TyBuilder, TyKind, WhereClause, | 12 | Substitution, TraitRef, Ty, TyBuilder, TyKind, WhereClause, |
13 | }; | 13 | }; |
14 | 14 | ||
@@ -34,6 +34,9 @@ pub trait TyExt { | |||
34 | 34 | ||
35 | fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<QuantifiedWhereClause>>; | 35 | fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<QuantifiedWhereClause>>; |
36 | fn associated_type_parent_trait(&self, db: &dyn HirDatabase) -> Option<TraitId>; | 36 | fn associated_type_parent_trait(&self, db: &dyn HirDatabase) -> Option<TraitId>; |
37 | |||
38 | /// FIXME: Get rid of this, it's not a good abstraction | ||
39 | fn equals_ctor(&self, other: &Ty) -> bool; | ||
37 | } | 40 | } |
38 | 41 | ||
39 | impl TyExt for Ty { | 42 | impl TyExt for Ty { |
@@ -238,6 +241,36 @@ impl TyExt for Ty { | |||
238 | _ => None, | 241 | _ => None, |
239 | } | 242 | } |
240 | } | 243 | } |
244 | |||
245 | fn equals_ctor(&self, other: &Ty) -> bool { | ||
246 | match (self.kind(&Interner), other.kind(&Interner)) { | ||
247 | (TyKind::Adt(adt, ..), TyKind::Adt(adt2, ..)) => adt == adt2, | ||
248 | (TyKind::Slice(_), TyKind::Slice(_)) | (TyKind::Array(_, _), TyKind::Array(_, _)) => { | ||
249 | true | ||
250 | } | ||
251 | (TyKind::FnDef(def_id, ..), TyKind::FnDef(def_id2, ..)) => def_id == def_id2, | ||
252 | (TyKind::OpaqueType(ty_id, ..), TyKind::OpaqueType(ty_id2, ..)) => ty_id == ty_id2, | ||
253 | (TyKind::AssociatedType(ty_id, ..), TyKind::AssociatedType(ty_id2, ..)) => { | ||
254 | ty_id == ty_id2 | ||
255 | } | ||
256 | (TyKind::Foreign(ty_id, ..), TyKind::Foreign(ty_id2, ..)) => ty_id == ty_id2, | ||
257 | (TyKind::Closure(id1, _), TyKind::Closure(id2, _)) => id1 == id2, | ||
258 | (TyKind::Ref(mutability, ..), TyKind::Ref(mutability2, ..)) | ||
259 | | (TyKind::Raw(mutability, ..), TyKind::Raw(mutability2, ..)) => { | ||
260 | mutability == mutability2 | ||
261 | } | ||
262 | ( | ||
263 | TyKind::Function(FnPointer { num_binders, sig, .. }), | ||
264 | TyKind::Function(FnPointer { num_binders: num_binders2, sig: sig2, .. }), | ||
265 | ) => num_binders == num_binders2 && sig == sig2, | ||
266 | (TyKind::Tuple(cardinality, _), TyKind::Tuple(cardinality2, _)) => { | ||
267 | cardinality == cardinality2 | ||
268 | } | ||
269 | (TyKind::Str, TyKind::Str) | (TyKind::Never, TyKind::Never) => true, | ||
270 | (TyKind::Scalar(scalar), TyKind::Scalar(scalar2)) => scalar == scalar2, | ||
271 | _ => false, | ||
272 | } | ||
273 | } | ||
241 | } | 274 | } |
242 | 275 | ||
243 | pub trait ProjectionTyExt { | 276 | pub trait ProjectionTyExt { |