Skip to content

Commit 90df86f

Browse files
Remove bound_{explicit,}_item_bounds
1 parent e1533a2 commit 90df86f

File tree

6 files changed

+40
-64
lines changed

6 files changed

+40
-64
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+21-27
Original file line numberDiff line numberDiff line change
@@ -673,40 +673,34 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
673673
let tcx = self.infcx.tcx;
674674

675675
// Find out if the predicates show that the type is a Fn or FnMut
676-
let find_fn_kind_from_did = |predicates: ty::EarlyBinder<
677-
&[(ty::Predicate<'tcx>, Span)],
678-
>,
679-
substs| {
680-
predicates.0.iter().find_map(|(pred, _)| {
681-
let pred = if let Some(substs) = substs {
682-
predicates.rebind(*pred).subst(tcx, substs).kind().skip_binder()
683-
} else {
684-
pred.kind().skip_binder()
685-
};
686-
if let ty::PredicateKind::Clause(ty::Clause::Trait(pred)) = pred && pred.self_ty() == ty {
687-
if Some(pred.def_id()) == tcx.lang_items().fn_trait() {
688-
return Some(hir::Mutability::Not);
689-
} else if Some(pred.def_id()) == tcx.lang_items().fn_mut_trait() {
690-
return Some(hir::Mutability::Mut);
691-
}
676+
let find_fn_kind_from_did = |(pred, _): (ty::Predicate<'tcx>, _)| {
677+
if let ty::PredicateKind::Clause(ty::Clause::Trait(pred)) = pred.kind().skip_binder()
678+
&& pred.self_ty() == ty
679+
{
680+
if Some(pred.def_id()) == tcx.lang_items().fn_trait() {
681+
return Some(hir::Mutability::Not);
682+
} else if Some(pred.def_id()) == tcx.lang_items().fn_mut_trait() {
683+
return Some(hir::Mutability::Mut);
692684
}
693-
None
694-
})
685+
}
686+
None
695687
};
696688

697689
// If the type is opaque/param/closure, and it is Fn or FnMut, let's suggest (mutably)
698690
// borrowing the type, since `&mut F: FnMut` iff `F: FnMut` and similarly for `Fn`.
699691
// These types seem reasonably opaque enough that they could be substituted with their
700692
// borrowed variants in a function body when we see a move error.
701-
let borrow_level = match ty.kind() {
702-
ty::Param(_) => find_fn_kind_from_did(
703-
tcx.bound_explicit_predicates_of(self.mir_def_id().to_def_id())
704-
.map_bound(|p| p.predicates),
705-
None,
706-
),
707-
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => {
708-
find_fn_kind_from_did(tcx.bound_explicit_item_bounds(*def_id), Some(*substs))
709-
}
693+
let borrow_level = match *ty.kind() {
694+
ty::Param(_) => tcx
695+
.explicit_predicates_of(self.mir_def_id().to_def_id())
696+
.predicates
697+
.iter()
698+
.copied()
699+
.find_map(find_fn_kind_from_did),
700+
ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs, .. }) => tcx
701+
.bound_explicit_item_bounds(def_id)
702+
.subst_iter_copied(tcx, substs)
703+
.find_map(find_fn_kind_from_did),
710704
ty::Closure(_, substs) => match substs.as_closure().kind() {
711705
ty::ClosureKind::Fn => Some(hir::Mutability::Not),
712706
ty::ClosureKind::FnMut => Some(hir::Mutability::Mut),

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
13091309
let infcx = wfcx.infcx;
13101310
let tcx = wfcx.tcx();
13111311

1312-
let predicates = tcx.bound_predicates_of(def_id.to_def_id());
1312+
let predicates = tcx.predicates_of(def_id.to_def_id());
13131313
let generics = tcx.generics_of(def_id);
13141314

13151315
let is_our_default = |def: &ty::GenericParamDef| match def.kind {
@@ -1410,7 +1410,6 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
14101410

14111411
// Now we build the substituted predicates.
14121412
let default_obligations = predicates
1413-
.0
14141413
.predicates
14151414
.iter()
14161415
.flat_map(|&(pred, sp)| {
@@ -1441,13 +1440,13 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
14411440
}
14421441
let mut param_count = CountParams::default();
14431442
let has_region = pred.visit_with(&mut param_count).is_break();
1444-
let substituted_pred = predicates.rebind(pred).subst(tcx, substs);
1443+
let substituted_pred = ty::EarlyBinder(pred).subst(tcx, substs);
14451444
// Don't check non-defaulted params, dependent defaults (including lifetimes)
14461445
// or preds with multiple params.
14471446
if substituted_pred.has_non_region_param() || param_count.params.len() > 1 || has_region
14481447
{
14491448
None
1450-
} else if predicates.0.predicates.iter().any(|&(p, _)| p == substituted_pred) {
1449+
} else if predicates.predicates.iter().any(|&(p, _)| p == substituted_pred) {
14511450
// Avoid duplication of predicates that contain no parameters, for example.
14521451
None
14531452
} else {
@@ -1473,7 +1472,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
14731472
traits::Obligation::new(tcx, cause, wfcx.param_env, pred)
14741473
});
14751474

1476-
let predicates = predicates.0.instantiate_identity(tcx);
1475+
let predicates = predicates.instantiate_identity(tcx);
14771476

14781477
let predicates = wfcx.normalize(span, None, predicates);
14791478

compiler/rustc_infer/src/infer/error_reporting/note.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
330330

331331
let Ok(trait_predicates) = self
332332
.tcx
333-
.bound_explicit_predicates_of(trait_item_def_id)
334-
.map_bound(|p| p.predicates)
335-
.subst_iter_copied(self.tcx, trait_item_substs)
333+
.explicit_predicates_of(trait_item_def_id)
334+
.instantiate_own(self.tcx, trait_item_substs)
336335
.map(|(pred, _)| {
337336
if pred.is_suggestable(self.tcx, false) {
338337
Ok(pred.to_string())

compiler/rustc_middle/src/ty/util.rs

-14
Original file line numberDiff line numberDiff line change
@@ -666,20 +666,6 @@ impl<'tcx> TyCtxt<'tcx> {
666666
ty::EarlyBinder(self.item_bounds(def_id))
667667
}
668668

669-
pub fn bound_predicates_of(
670-
self,
671-
def_id: DefId,
672-
) -> ty::EarlyBinder<ty::generics::GenericPredicates<'tcx>> {
673-
ty::EarlyBinder(self.predicates_of(def_id))
674-
}
675-
676-
pub fn bound_explicit_predicates_of(
677-
self,
678-
def_id: DefId,
679-
) -> ty::EarlyBinder<ty::generics::GenericPredicates<'tcx>> {
680-
ty::EarlyBinder(self.explicit_predicates_of(def_id))
681-
}
682-
683669
pub fn bound_impl_subject(self, def_id: DefId) -> ty::EarlyBinder<ty::ImplSubject<'tcx>> {
684670
ty::EarlyBinder(self.impl_subject(def_id))
685671
}

compiler/rustc_trait_selection/src/traits/select/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -2558,12 +2558,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
25582558
// obligation will normalize to `<$0 as Iterator>::Item = $1` and
25592559
// `$1: Copy`, so we must ensure the obligations are emitted in
25602560
// that order.
2561-
let predicates = tcx.bound_predicates_of(def_id);
2562-
debug!(?predicates);
2563-
assert_eq!(predicates.0.parent, None);
2564-
let mut obligations = Vec::with_capacity(predicates.0.predicates.len());
2565-
for (predicate, span) in predicates.0.predicates {
2566-
let span = *span;
2561+
let predicates = tcx.predicates_of(def_id);
2562+
assert_eq!(predicates.parent, None);
2563+
let predicates = predicates.instantiate_own(tcx, substs);
2564+
let mut obligations = Vec::with_capacity(predicates.len());
2565+
for (predicate, span) in predicates {
25672566
let cause = cause.clone().derived_cause(parent_trait_pred, |derived| {
25682567
ImplDerivedObligation(Box::new(ImplDerivedObligationCause {
25692568
derived,
@@ -2576,7 +2575,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
25762575
param_env,
25772576
cause.clone(),
25782577
recursion_depth,
2579-
predicates.rebind(*predicate).subst(tcx, substs),
2578+
predicate,
25802579
&mut obligations,
25812580
);
25822581
obligations.push(Obligation { cause, recursion_depth, param_env, predicate });

compiler/rustc_traits/src/chalk/db.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! `crate::chalk::lowering` (to lower rustc types into Chalk types).
88
99
use rustc_middle::traits::ChalkRustInterner as RustInterner;
10-
use rustc_middle::ty::{self, AssocKind, EarlyBinder, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable};
10+
use rustc_middle::ty::{self, AssocKind, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable};
1111
use rustc_middle::ty::{InternalSubsts, SubstsRef};
1212
use rustc_target::abi::{Integer, IntegerType};
1313

@@ -38,13 +38,12 @@ impl<'tcx> RustIrDatabase<'tcx> {
3838
def_id: DefId,
3939
bound_vars: SubstsRef<'tcx>,
4040
) -> Vec<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>> {
41-
let predicates = self.interner.tcx.predicates_defined_on(def_id).predicates;
42-
predicates
43-
.iter()
44-
.map(|(wc, _)| EarlyBinder(*wc).subst(self.interner.tcx, bound_vars))
45-
.filter_map(|wc| LowerInto::<
46-
Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>
47-
>::lower_into(wc, self.interner)).collect()
41+
self.interner
42+
.tcx
43+
.predicates_defined_on(def_id)
44+
.instantiate_own(self.interner.tcx, bound_vars)
45+
.filter_map(|(wc, _)| LowerInto::lower_into(wc, self.interner))
46+
.collect()
4847
}
4948

5049
fn bounds_for<T>(&self, def_id: DefId, bound_vars: SubstsRef<'tcx>) -> Vec<T>

0 commit comments

Comments
 (0)