Skip to content

Commit c9eeb60

Browse files
committed
Deduplicate some code
1 parent 022c148 commit c9eeb60

File tree

1 file changed

+15
-24
lines changed
  • compiler/rustc_traits/src/chalk

1 file changed

+15
-24
lines changed

compiler/rustc_traits/src/chalk/db.rs

+15-24
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ impl<'tcx> RustIrDatabase<'tcx> {
5050
.map(|wc| wc.fold_with(&mut regions_substitutor))
5151
.filter_map(|wc| LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(wc, &self.interner)).collect()
5252
}
53+
54+
fn bounds_for<T>(&self, def_id: DefId, bound_vars: SubstsRef<'tcx>) -> Vec<T>
55+
where
56+
ty::Predicate<'tcx>: LowerInto<'tcx, std::option::Option<T>>,
57+
{
58+
self.interner
59+
.tcx
60+
.explicit_item_bounds(def_id)
61+
.iter()
62+
.map(|(bound, _)| bound.subst(self.interner.tcx, &bound_vars))
63+
.filter_map(|bound| LowerInto::<Option<_>>::lower_into(bound, &self.interner))
64+
.collect()
65+
}
5366
}
5467

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

7790
let where_clauses = self.where_clauses_for(def_id, bound_vars);
78-
79-
let bounds = self
80-
.interner
81-
.tcx
82-
.explicit_item_bounds(def_id)
83-
.iter()
84-
.map(|(bound, _)| bound.subst(self.interner.tcx, &bound_vars))
85-
.filter_map(|bound| {
86-
LowerInto::<
87-
Option<chalk_solve::rust_ir::QuantifiedInlineBound<RustInterner<'tcx>>>,
88-
>::lower_into(bound, &self.interner)
89-
})
90-
.collect();
91+
let bounds = self.bounds_for(def_id, bound_vars);
9192

9293
Arc::new(chalk_solve::rust_ir::AssociatedTyDatum {
9394
trait_id: chalk_ir::TraitId(trait_def_id),
@@ -453,17 +454,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
453454
let bound_vars = bound_vars_for_item(self.interner.tcx, opaque_ty_id.0);
454455
let binders = binders_for(&self.interner, bound_vars);
455456
let where_clauses = self.where_clauses_for(opaque_ty_id.0, bound_vars);
456-
457-
let bounds: Vec<_> = self
458-
.interner
459-
.tcx
460-
.explicit_item_bounds(opaque_ty_id.0)
461-
.iter()
462-
.map(|(bound, _)| bound.subst(self.interner.tcx, &bound_vars))
463-
.filter_map(|bound| {
464-
LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(bound, &self.interner)
465-
})
466-
.collect();
457+
let bounds = self.bounds_for(opaque_ty_id.0, bound_vars);
467458

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

0 commit comments

Comments
 (0)