Skip to content

Commit

Permalink
Deduplicate some code
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed Oct 6, 2020
1 parent 022c148 commit c9eeb60
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions compiler/rustc_traits/src/chalk/db.rs
Expand Up @@ -50,6 +50,19 @@ impl<'tcx> RustIrDatabase<'tcx> {
.map(|wc| wc.fold_with(&mut regions_substitutor))
.filter_map(|wc| LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(wc, &self.interner)).collect()
}

fn bounds_for<T>(&self, def_id: DefId, bound_vars: SubstsRef<'tcx>) -> Vec<T>
where
ty::Predicate<'tcx>: LowerInto<'tcx, std::option::Option<T>>,
{
self.interner
.tcx
.explicit_item_bounds(def_id)
.iter()
.map(|(bound, _)| bound.subst(self.interner.tcx, &bound_vars))
.filter_map(|bound| LowerInto::<Option<_>>::lower_into(bound, &self.interner))
.collect()
}
}

impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'tcx> {
Expand All @@ -75,19 +88,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
let binders = binders_for(&self.interner, bound_vars);

let where_clauses = self.where_clauses_for(def_id, bound_vars);

let bounds = self
.interner
.tcx
.explicit_item_bounds(def_id)
.iter()
.map(|(bound, _)| bound.subst(self.interner.tcx, &bound_vars))
.filter_map(|bound| {
LowerInto::<
Option<chalk_solve::rust_ir::QuantifiedInlineBound<RustInterner<'tcx>>>,
>::lower_into(bound, &self.interner)
})
.collect();
let bounds = self.bounds_for(def_id, bound_vars);

Arc::new(chalk_solve::rust_ir::AssociatedTyDatum {
trait_id: chalk_ir::TraitId(trait_def_id),
Expand Down Expand Up @@ -453,17 +454,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
let bound_vars = bound_vars_for_item(self.interner.tcx, opaque_ty_id.0);
let binders = binders_for(&self.interner, bound_vars);
let where_clauses = self.where_clauses_for(opaque_ty_id.0, bound_vars);

let bounds: Vec<_> = self
.interner
.tcx
.explicit_item_bounds(opaque_ty_id.0)
.iter()
.map(|(bound, _)| bound.subst(self.interner.tcx, &bound_vars))
.filter_map(|bound| {
LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(bound, &self.interner)
})
.collect();
let bounds = self.bounds_for(opaque_ty_id.0, bound_vars);

let value = chalk_solve::rust_ir::OpaqueTyDatumBound {
bounds: chalk_ir::Binders::new(binders.clone(), bounds),
Expand Down

0 comments on commit c9eeb60

Please sign in to comment.