Skip to content

Commit 4a88598

Browse files
committed
Add stopgap solution for builtin traits
1 parent 93aef02 commit 4a88598

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

chalk-solve/src/clauses.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ fn program_clauses_that_could_match<I: Interner>(
238238
}
239239

240240
if let Some(well_known) = trait_datum.well_known {
241-
builtin_traits::add_builtin_program_clauses(well_known, trait_ref, builder);
241+
builtin_traits::add_builtin_program_clauses(db, builder, well_known, trait_ref, self_ty.data(interner));
242242
}
243243
}
244244
DomainGoal::Holds(WhereClause::AliasEq(alias_predicate)) => {

chalk-solve/src/clauses/builtin_traits.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
use chalk_ir::TyData;
12
use super::builder::ClauseBuilder;
2-
use crate::Interner;
3-
use crate::{TraitRef, WellKnownTrait};
3+
use crate::{Interner, RustIrDatabase, TraitRef, WellKnownTrait};
44

55
/// For well known traits we have special hard-coded impls, either as an
66
/// optimization or to enforce special rules for correctness.
77
pub fn add_builtin_program_clauses<I: Interner>(
8+
db: &dyn RustIrDatabase<I>,
9+
builder: &mut ClauseBuilder<'_, I>,
810
well_known: WellKnownTrait,
9-
_trait_ref: &TraitRef<I>,
10-
_builder: &mut ClauseBuilder<'_, I>,
11+
trait_ref: &TraitRef<I>,
12+
ty: &TyData<I>,
1113
) {
14+
if db.force_impl_for(well_known, ty) {
15+
builder.push_fact(trait_ref.clone());
16+
}
17+
1218
match well_known {
1319
WellKnownTrait::SizedTrait => { /* TODO */ }
1420
}

chalk-solve/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ pub trait RustIrDatabase<I: Interner>: Debug {
6868
/// user gave).
6969
fn impl_provided_for(&self, auto_trait_id: TraitId<I>, struct_id: StructId<I>) -> bool;
7070

71+
/// A stop-gap solution to force an impl for a given well-known trait.
72+
/// Useful when the logic for a given trait is absent or incomplete.
73+
#[allow(unused_variables)]
74+
fn force_impl_for(&self, well_known: WellKnownTrait, ty: &TyData<I>) -> bool {
75+
false
76+
}
77+
7178
fn interner(&self) -> &I;
7279
}
7380

0 commit comments

Comments
 (0)