Skip to content

Commit

Permalink
Simplify edge-case handling
Browse files Browse the repository at this point in the history
  • Loading branch information
memoryleak47 committed Sep 19, 2020
1 parent 17eb26e commit c35689c
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions chalk-solve/src/clauses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ pub fn push_auto_trait_impls<I: Interner>(
// we assume that the builder has no binders so far.
assert!(builder.placeholders_in_scope().is_empty());

// auto traits are not implemented for foreign types
if let TypeName::Foreign(_) = app_ty.name {
return;
}

// 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 All @@ -132,21 +127,29 @@ pub fn push_auto_trait_impls<I: Interner>(

let consequence = mk_ref(app_ty.clone().intern(interner));

// closures require binders, while the other types do not
if let TypeName::Closure(closure_id) = app_ty.name {
let binders = builder
.db
.closure_upvars(closure_id, &Substitution::empty(interner));
builder.push_binders(&binders, |builder, upvar_ty| {
let conditions = iter::once(mk_ref(upvar_ty));
builder.push_clause(consequence, conditions);
});
} else {
let conditions = constituent_types(builder.db, app_ty)
.into_iter()
.map(mk_ref);
match app_ty.name {
// auto traits are not implemented for foreign types
TypeName::Foreign(_) => return,

// closures require binders, while the other types do not
TypeName::Closure(closure_id) => {
let binders = builder
.db
.closure_upvars(closure_id, &Substitution::empty(interner));
builder.push_binders(&binders, |builder, upvar_ty| {
let conditions = iter::once(mk_ref(upvar_ty));
builder.push_clause(consequence, conditions);
});
}

// app_ty implements AutoTrait if all constituents of app_ty implement AutoTrait
_ => {
let conditions = constituent_types(builder.db, app_ty)
.into_iter()
.map(mk_ref);

builder.push_clause(consequence, conditions);
builder.push_clause(consequence, conditions);
}
}
}

Expand Down

0 comments on commit c35689c

Please sign in to comment.