remove pred_known_to_hold_modulo_regions

This commit is contained in:
lcnr 2024-01-29 10:11:30 +01:00
parent 486c7b6a50
commit 399a258f46

View File

@ -119,9 +119,7 @@ pub fn predicates_for_generics<'tcx>(
/// Determines whether the type `ty` is known to meet `bound` and /// Determines whether the type `ty` is known to meet `bound` and
/// returns true if so. Returns false if `ty` either does not meet /// returns true if so. Returns false if `ty` either does not meet
/// `bound` or is not known to meet bound (note that this is /// `bound` or is not known to meet bound.
/// conservative towards *no impl*, which is the opposite of the
/// `evaluate` methods).
pub fn type_known_to_meet_bound_modulo_regions<'tcx>( pub fn type_known_to_meet_bound_modulo_regions<'tcx>(
infcx: &InferCtxt<'tcx>, infcx: &InferCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
@ -129,50 +127,8 @@ pub fn type_known_to_meet_bound_modulo_regions<'tcx>(
def_id: DefId, def_id: DefId,
) -> bool { ) -> bool {
let trait_ref = ty::TraitRef::new(infcx.tcx, def_id, [ty]); let trait_ref = ty::TraitRef::new(infcx.tcx, def_id, [ty]);
pred_known_to_hold_modulo_regions(infcx, param_env, trait_ref) let obligation = Obligation::new(infcx.tcx, ObligationCause::dummy(), param_env, trait_ref);
} infcx.predicate_must_hold_modulo_regions(&obligation)
/// FIXME(@lcnr): this function doesn't seem right and shouldn't exist?
///
/// Ping me on zulip if you want to use this method and need help with finding
/// an appropriate replacement.
#[instrument(level = "debug", skip(infcx, param_env, pred), ret)]
fn pred_known_to_hold_modulo_regions<'tcx>(
infcx: &InferCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
pred: impl ToPredicate<'tcx>,
) -> bool {
let obligation = Obligation::new(infcx.tcx, ObligationCause::dummy(), param_env, pred);
let result = infcx.evaluate_obligation_no_overflow(&obligation);
debug!(?result);
if result.must_apply_modulo_regions() {
true
} else if result.may_apply() {
// Sometimes obligations are ambiguous because the recursive evaluator
// is not smart enough, so we fall back to fulfillment when we're not certain
// that an obligation holds or not. Even still, we must make sure that
// the we do no inference in the process of checking this obligation.
let goal = infcx.resolve_vars_if_possible((obligation.predicate, obligation.param_env));
infcx.probe(|_| {
let ocx = ObligationCtxt::new(infcx);
ocx.register_obligation(obligation);
let errors = ocx.select_all_or_error();
match errors.as_slice() {
// Only known to hold if we did no inference.
[] => infcx.shallow_resolve(goal) == goal,
errors => {
debug!(?errors);
false
}
}
})
} else {
false
}
} }
#[instrument(level = "debug", skip(tcx, elaborated_env))] #[instrument(level = "debug", skip(tcx, elaborated_env))]