Skip to content

Commit 09b730d

Browse files
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 <flodiebold@gmail.com>
2 parents eb248d8 + 4c35df4 commit 09b730d

File tree

3 files changed

+37
-33
lines changed

3 files changed

+37
-33
lines changed

crates/hir_ty/src/chalk_ext.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use hir_def::{
88
use crate::{
99
db::HirDatabase, from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id,
1010
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,
1212
Substitution, TraitRef, Ty, TyBuilder, TyKind, WhereClause,
1313
};
1414

@@ -34,6 +34,9 @@ pub trait TyExt {
3434

3535
fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<QuantifiedWhereClause>>;
3636
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;
3740
}
3841

3942
impl TyExt for Ty {
@@ -238,6 +241,36 @@ impl TyExt for Ty {
238241
_ => None,
239242
}
240243
}
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+
}
241274
}
242275

243276
pub trait ProjectionTyExt {

crates/hir_ty/src/infer/unify.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue};
88
use super::{DomainGoal, InferenceContext};
99
use crate::{
1010
AliasEq, AliasTy, BoundVar, Canonical, CanonicalVarKinds, DebruijnIndex, FnPointer, FnSubst,
11-
InEnvironment, InferenceVar, Interner, Scalar, Substitution, Ty, TyKind, TypeWalk, WhereClause,
11+
InEnvironment, InferenceVar, Interner, Scalar, Substitution, Ty, TyExt, TyKind, TypeWalk,
12+
WhereClause,
1213
};
1314

1415
impl<'a> InferenceContext<'a> {

crates/hir_ty/src/lib.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -168,37 +168,7 @@ impl CallableSig {
168168
}
169169
}
170170

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-
}
171+
impl Ty {}
202172

203173
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
204174
pub enum ImplTraitId {

0 commit comments

Comments
 (0)