Skip to content

Commit

Permalink
Auto merge of #613 - nathanwhit:solver-fix, r=jackh726
Browse files Browse the repository at this point in the history
Fix assertion failure during recursive solving

Fixes the breakage due to the recent auto-trait changes.

[rust-analyzer issue](rust-lang/rust-analyzer#6078).
  • Loading branch information
bors committed Sep 28, 2020
2 parents a6d2e43 + 34c426d commit 2d60a13
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions chalk-solve/src/clauses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ pub fn push_auto_trait_impls<I: Interner>(
1
);

// we assume that the builder has no binders so far.
assert!(builder.placeholders_in_scope().is_empty());

// If there is a `impl AutoTrait for Foo<..>` or `impl !AutoTrait
// for Foo<..>`, where `Foo` is the adt we're looking at, then
// we don't generate our own rules.
Expand Down Expand Up @@ -299,25 +296,28 @@ fn program_clauses_that_could_match<I: Interner>(
// the automatic impls for `Foo`.
let trait_datum = db.trait_datum(trait_id);
if trait_datum.is_auto_trait() {
let ty = trait_ref.self_type_parameter(interner);
match ty.data(interner) {
TyData::Apply(apply) => {
push_auto_trait_impls(builder, trait_id, apply);
}
// function-types implement auto traits unconditionally
TyData::Function(_) => {
let auto_trait_ref = TraitRef {
trait_id,
substitution: Substitution::from1(interner, ty.cast(interner)),
};

builder.push_fact(auto_trait_ref);
}
TyData::InferenceVar(_, _) | TyData::BoundVar(_) => {
return Err(Floundered);
let generalized = generalize::Generalize::apply(db.interner(), trait_ref);
builder.push_binders(&generalized, |builder, trait_ref| {
let ty = trait_ref.self_type_parameter(interner);
match ty.data(interner) {
TyData::Apply(apply) => {
push_auto_trait_impls(builder, trait_id, apply);
Ok(())
}
// function-types implement auto traits unconditionally
TyData::Function(_) => {
let auto_trait_ref = TraitRef {
trait_id,
substitution: Substitution::from1(interner, ty.cast(interner)),
};

builder.push_fact(auto_trait_ref);
Ok(())
}
TyData::InferenceVar(_, _) | TyData::BoundVar(_) => Err(Floundered),
_ => Ok(()),
}
_ => {}
}
})?;
}

// If the self type is a `dyn trait` type, generate program-clauses
Expand Down

0 comments on commit 2d60a13

Please sign in to comment.