mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-25 06:03:16 +00:00
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>
This commit is contained in:
commit
09b730d1e1
@ -8,7 +8,7 @@ use hir_def::{
|
||||
use crate::{
|
||||
db::HirDatabase, from_assoc_type_id, from_chalk_trait_id, from_foreign_def_id,
|
||||
from_placeholder_idx, to_chalk_trait_id, AdtId, AliasEq, AliasTy, Binders, CallableDefId,
|
||||
CallableSig, ImplTraitId, Interner, Lifetime, ProjectionTy, QuantifiedWhereClause,
|
||||
CallableSig, FnPointer, ImplTraitId, Interner, Lifetime, ProjectionTy, QuantifiedWhereClause,
|
||||
Substitution, TraitRef, Ty, TyBuilder, TyKind, WhereClause,
|
||||
};
|
||||
|
||||
@ -34,6 +34,9 @@ pub trait TyExt {
|
||||
|
||||
fn impl_trait_bounds(&self, db: &dyn HirDatabase) -> Option<Vec<QuantifiedWhereClause>>;
|
||||
fn associated_type_parent_trait(&self, db: &dyn HirDatabase) -> Option<TraitId>;
|
||||
|
||||
/// FIXME: Get rid of this, it's not a good abstraction
|
||||
fn equals_ctor(&self, other: &Ty) -> bool;
|
||||
}
|
||||
|
||||
impl TyExt for Ty {
|
||||
@ -238,6 +241,36 @@ impl TyExt for Ty {
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn equals_ctor(&self, other: &Ty) -> bool {
|
||||
match (self.kind(&Interner), other.kind(&Interner)) {
|
||||
(TyKind::Adt(adt, ..), TyKind::Adt(adt2, ..)) => adt == adt2,
|
||||
(TyKind::Slice(_), TyKind::Slice(_)) | (TyKind::Array(_, _), TyKind::Array(_, _)) => {
|
||||
true
|
||||
}
|
||||
(TyKind::FnDef(def_id, ..), TyKind::FnDef(def_id2, ..)) => def_id == def_id2,
|
||||
(TyKind::OpaqueType(ty_id, ..), TyKind::OpaqueType(ty_id2, ..)) => ty_id == ty_id2,
|
||||
(TyKind::AssociatedType(ty_id, ..), TyKind::AssociatedType(ty_id2, ..)) => {
|
||||
ty_id == ty_id2
|
||||
}
|
||||
(TyKind::Foreign(ty_id, ..), TyKind::Foreign(ty_id2, ..)) => ty_id == ty_id2,
|
||||
(TyKind::Closure(id1, _), TyKind::Closure(id2, _)) => id1 == id2,
|
||||
(TyKind::Ref(mutability, ..), TyKind::Ref(mutability2, ..))
|
||||
| (TyKind::Raw(mutability, ..), TyKind::Raw(mutability2, ..)) => {
|
||||
mutability == mutability2
|
||||
}
|
||||
(
|
||||
TyKind::Function(FnPointer { num_binders, sig, .. }),
|
||||
TyKind::Function(FnPointer { num_binders: num_binders2, sig: sig2, .. }),
|
||||
) => num_binders == num_binders2 && sig == sig2,
|
||||
(TyKind::Tuple(cardinality, _), TyKind::Tuple(cardinality2, _)) => {
|
||||
cardinality == cardinality2
|
||||
}
|
||||
(TyKind::Str, TyKind::Str) | (TyKind::Never, TyKind::Never) => true,
|
||||
(TyKind::Scalar(scalar), TyKind::Scalar(scalar2)) => scalar == scalar2,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ProjectionTyExt {
|
||||
|
@ -8,7 +8,8 @@ use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue};
|
||||
use super::{DomainGoal, InferenceContext};
|
||||
use crate::{
|
||||
AliasEq, AliasTy, BoundVar, Canonical, CanonicalVarKinds, DebruijnIndex, FnPointer, FnSubst,
|
||||
InEnvironment, InferenceVar, Interner, Scalar, Substitution, Ty, TyKind, TypeWalk, WhereClause,
|
||||
InEnvironment, InferenceVar, Interner, Scalar, Substitution, Ty, TyExt, TyKind, TypeWalk,
|
||||
WhereClause,
|
||||
};
|
||||
|
||||
impl<'a> InferenceContext<'a> {
|
||||
|
@ -168,37 +168,7 @@ impl CallableSig {
|
||||
}
|
||||
}
|
||||
|
||||
impl Ty {
|
||||
pub fn equals_ctor(&self, other: &Ty) -> bool {
|
||||
match (self.kind(&Interner), other.kind(&Interner)) {
|
||||
(TyKind::Adt(adt, ..), TyKind::Adt(adt2, ..)) => adt == adt2,
|
||||
(TyKind::Slice(_), TyKind::Slice(_)) | (TyKind::Array(_, _), TyKind::Array(_, _)) => {
|
||||
true
|
||||
}
|
||||
(TyKind::FnDef(def_id, ..), TyKind::FnDef(def_id2, ..)) => def_id == def_id2,
|
||||
(TyKind::OpaqueType(ty_id, ..), TyKind::OpaqueType(ty_id2, ..)) => ty_id == ty_id2,
|
||||
(TyKind::AssociatedType(ty_id, ..), TyKind::AssociatedType(ty_id2, ..)) => {
|
||||
ty_id == ty_id2
|
||||
}
|
||||
(TyKind::Foreign(ty_id, ..), TyKind::Foreign(ty_id2, ..)) => ty_id == ty_id2,
|
||||
(TyKind::Closure(id1, _), TyKind::Closure(id2, _)) => id1 == id2,
|
||||
(TyKind::Ref(mutability, ..), TyKind::Ref(mutability2, ..))
|
||||
| (TyKind::Raw(mutability, ..), TyKind::Raw(mutability2, ..)) => {
|
||||
mutability == mutability2
|
||||
}
|
||||
(
|
||||
TyKind::Function(FnPointer { num_binders, sig, .. }),
|
||||
TyKind::Function(FnPointer { num_binders: num_binders2, sig: sig2, .. }),
|
||||
) => num_binders == num_binders2 && sig == sig2,
|
||||
(TyKind::Tuple(cardinality, _), TyKind::Tuple(cardinality2, _)) => {
|
||||
cardinality == cardinality2
|
||||
}
|
||||
(TyKind::Str, TyKind::Str) | (TyKind::Never, TyKind::Never) => true,
|
||||
(TyKind::Scalar(scalar), TyKind::Scalar(scalar2)) => scalar == scalar2,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Ty {}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
|
||||
pub enum ImplTraitId {
|
||||
|
Loading…
Reference in New Issue
Block a user