Skip to content

Commit d9a02b0

Browse files
committed
Split out the actual predicate solving code into a separate function
1 parent 48ff6a9 commit d9a02b0

File tree

1 file changed

+17
-9
lines changed
  • compiler/rustc_trait_selection/src/traits

1 file changed

+17
-9
lines changed

compiler/rustc_trait_selection/src/traits/mod.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ pub fn predicates_for_generics<'tcx>(
136136
/// `bound` or is not known to meet bound (note that this is
137137
/// conservative towards *no impl*, which is the opposite of the
138138
/// `evaluate` methods).
139-
#[instrument(level = "debug", skip(infcx, param_env, span), ret)]
140139
pub fn type_known_to_meet_bound_modulo_regions<'tcx>(
141140
infcx: &InferCtxt<'tcx>,
142141
param_env: ty::ParamEnv<'tcx>,
@@ -146,31 +145,40 @@ pub fn type_known_to_meet_bound_modulo_regions<'tcx>(
146145
) -> bool {
147146
let trait_ref =
148147
ty::Binder::dummy(ty::TraitRef { def_id, substs: infcx.tcx.mk_substs_trait(ty, &[]) });
148+
pred_known_to_hold_modulo_regions(infcx, param_env, trait_ref.without_const(), span)
149+
}
150+
151+
#[instrument(level = "debug", skip(infcx, param_env, span, pred), ret)]
152+
fn pred_known_to_hold_modulo_regions<'tcx>(
153+
infcx: &InferCtxt<'tcx>,
154+
param_env: ty::ParamEnv<'tcx>,
155+
pred: impl ToPredicate<'tcx, ty::Predicate<'tcx>> + TypeVisitable<'tcx>,
156+
span: Span,
157+
) -> bool {
158+
let has_non_region_infer = pred.has_non_region_infer();
149159
let obligation = Obligation {
150160
param_env,
161+
// We can use a dummy node-id here because we won't pay any mind
162+
// to region obligations that arise (there shouldn't really be any
163+
// anyhow).
151164
cause: ObligationCause::misc(span, hir::CRATE_HIR_ID),
152165
recursion_depth: 0,
153-
predicate: trait_ref.without_const().to_predicate(infcx.tcx),
166+
predicate: pred.to_predicate(infcx.tcx),
154167
};
155168

156169
let result = infcx.predicate_must_hold_modulo_regions(&obligation);
157170
debug!(?result);
158171

159-
if result && ty.has_non_region_infer() {
172+
if result && has_non_region_infer {
160173
// Because of inference "guessing", selection can sometimes claim
161174
// to succeed while the success requires a guess. To ensure
162175
// this function's result remains infallible, we must confirm
163176
// that guess. While imperfect, I believe this is sound.
164177

165-
// We can use a dummy node-id here because we won't pay any mind
166-
// to region obligations that arise (there shouldn't really be any
167-
// anyhow).
168-
let cause = ObligationCause::misc(span, hir::CRATE_HIR_ID);
169-
170178
// The handling of regions in this area of the code is terrible,
171179
// see issue #29149. We should be able to improve on this with
172180
// NLL.
173-
let errors = fully_solve_bound(infcx, cause, param_env, ty, def_id);
181+
let errors = fully_solve_obligation(infcx, obligation);
174182

175183
// Note: we only assume something is `Copy` if we can
176184
// *definitively* show that it implements `Copy`. Otherwise,

0 commit comments

Comments
 (0)