diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-11-17 10:36:18 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-11-21 20:31:34 +0000 |
| commit | d9a02b0fb728ac994883845b1c53630c2dec4657 (patch) | |
| tree | d3e081d35aa51848c53b9463b7555b5575204e3d /compiler/rustc_trait_selection/src | |
| parent | 48ff6a95b559e0c293f4c118145964332994dcc0 (diff) | |
| download | rust-d9a02b0fb728ac994883845b1c53630c2dec4657.tar.gz rust-d9a02b0fb728ac994883845b1c53630c2dec4657.zip | |
Split out the actual predicate solving code into a separate function
Diffstat (limited to 'compiler/rustc_trait_selection/src')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/mod.rs | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index ddc9b768f07..4da19bb4a6a 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -136,7 +136,6 @@ pub fn predicates_for_generics<'tcx>( /// `bound` or is not known to meet bound (note that this is /// conservative towards *no impl*, which is the opposite of the /// `evaluate` methods). -#[instrument(level = "debug", skip(infcx, param_env, span), ret)] pub fn type_known_to_meet_bound_modulo_regions<'tcx>( infcx: &InferCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, @@ -146,31 +145,40 @@ pub fn type_known_to_meet_bound_modulo_regions<'tcx>( ) -> bool { let trait_ref = ty::Binder::dummy(ty::TraitRef { def_id, substs: infcx.tcx.mk_substs_trait(ty, &[]) }); + pred_known_to_hold_modulo_regions(infcx, param_env, trait_ref.without_const(), span) +} + +#[instrument(level = "debug", skip(infcx, param_env, span, pred), ret)] +fn pred_known_to_hold_modulo_regions<'tcx>( + infcx: &InferCtxt<'tcx>, + param_env: ty::ParamEnv<'tcx>, + pred: impl ToPredicate<'tcx, ty::Predicate<'tcx>> + TypeVisitable<'tcx>, + span: Span, +) -> bool { + let has_non_region_infer = pred.has_non_region_infer(); let obligation = Obligation { param_env, + // We can use a dummy node-id here because we won't pay any mind + // to region obligations that arise (there shouldn't really be any + // anyhow). cause: ObligationCause::misc(span, hir::CRATE_HIR_ID), recursion_depth: 0, - predicate: trait_ref.without_const().to_predicate(infcx.tcx), + predicate: pred.to_predicate(infcx.tcx), }; let result = infcx.predicate_must_hold_modulo_regions(&obligation); debug!(?result); - if result && ty.has_non_region_infer() { + if result && has_non_region_infer { // Because of inference "guessing", selection can sometimes claim // to succeed while the success requires a guess. To ensure // this function's result remains infallible, we must confirm // that guess. While imperfect, I believe this is sound. - // We can use a dummy node-id here because we won't pay any mind - // to region obligations that arise (there shouldn't really be any - // anyhow). - let cause = ObligationCause::misc(span, hir::CRATE_HIR_ID); - // The handling of regions in this area of the code is terrible, // see issue #29149. We should be able to improve on this with // NLL. - let errors = fully_solve_bound(infcx, cause, param_env, ty, def_id); + let errors = fully_solve_obligation(infcx, obligation); // Note: we only assume something is `Copy` if we can // *definitively* show that it implements `Copy`. Otherwise, |
