Skip to content

Commit 56d3cc5

Browse files
committed
add struct_id accessor, refactor unnecessary skip_binders calls
1 parent 4866423 commit 56d3cc5

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

chalk-integration/src/program.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use chalk_ir::tls;
66
use chalk_ir::{
77
debug::SeparatorTraitRef, AliasTy, ApplicationTy, AssocTypeId, Goal, Goals, ImplId, Lifetime,
88
Parameter, ProgramClause, ProgramClauseImplication, ProgramClauses, StructId, Substitution,
9-
TraitId, Ty, TyData, TypeName,
9+
TraitId, Ty, TypeName,
1010
};
1111
use chalk_rust_ir::{
1212
AssociatedTyDatum, AssociatedTyValue, AssociatedTyValueId, ImplDatum, ImplType, StructDatum,
@@ -308,16 +308,8 @@ impl RustIrDatabase<ChalkIr> for Program {
308308
// Look for an impl like `impl Send for Foo` where `Foo` is
309309
// the struct. See `push_auto_trait_impls` for more.
310310
self.impl_data.values().any(|impl_datum| {
311-
let impl_trait_ref = &impl_datum.binders.skip_binders().trait_ref;
312-
impl_trait_ref.trait_id == auto_trait_id
313-
&& match impl_trait_ref.self_type_parameter(interner).data(interner) {
314-
TyData::Apply(apply) => match apply.name {
315-
TypeName::Struct(id) => id == struct_id,
316-
_ => false,
317-
},
318-
319-
_ => false,
320-
}
311+
impl_datum.trait_id() == auto_trait_id
312+
&& impl_datum.self_type_struct_id(interner) == Some(struct_id)
321313
})
322314
}
323315

chalk-rust-ir/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ impl<I: Interner> ImplDatum<I> {
3737
pub fn trait_id(&self) -> TraitId<I> {
3838
self.binders.skip_binders().trait_ref.trait_id
3939
}
40+
41+
pub fn self_type_struct_id(&self, interner: &I) -> Option<StructId<I>> {
42+
match self
43+
.binders
44+
.skip_binders()
45+
.trait_ref
46+
.self_type_parameter(interner)
47+
.data(interner)
48+
{
49+
TyData::Apply(apply) => match apply.name {
50+
TypeName::Struct(id) => Some(id),
51+
_ => None,
52+
},
53+
_ => None,
54+
}
55+
}
4056
}
4157

4258
#[derive(Clone, Debug, PartialEq, Eq, Hash, HasInterner, Fold)]

chalk-solve/src/wf.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -612,20 +612,10 @@ impl WfWellKnownGoals {
612612
) -> Option<Goal<I>> {
613613
let interner = db.interner();
614614

615-
let struct_id = if let TyData::Apply(ApplicationTy {
616-
name: TypeName::Struct(struct_id),
617-
..
618-
}) = impl_datum
619-
.binders
620-
.skip_binders()
621-
.trait_ref
622-
.self_type_parameter(interner)
623-
.data(interner)
624-
{
625-
*struct_id
626-
} else {
615+
let struct_id = match impl_datum.self_type_struct_id(interner) {
616+
Some(id) => id,
627617
// Drop can only be implemented on a nominal type
628-
return Some(GoalData::CannotProve(()).intern(interner));
618+
None => return Some(GoalData::CannotProve(()).intern(interner)),
629619
};
630620

631621
let mut gb = GoalBuilder::new(db);

0 commit comments

Comments
 (0)