From 42eba3edf7ab3992cb8a69f6bf80cc7654ffa946 Mon Sep 17 00:00:00 2001 From: Boxy Uwu Date: Sun, 28 Sep 2025 00:22:36 +0100 Subject: [PATCH] rename `select_where_possible` and `select_all_or_error` --- .../src/diagnostics/bound_region_errors.rs | 2 +- .../src/diagnostics/conflict_errors.rs | 4 ++-- .../src/diagnostics/region_errors.rs | 2 +- .../src/type_check/liveness/trace.rs | 2 +- compiler/rustc_codegen_ssa/src/base.rs | 2 +- .../rustc_const_eval/src/check_consts/check.rs | 2 +- .../rustc_const_eval/src/check_consts/qualifs.rs | 4 ++-- .../rustc_const_eval/src/util/compare_types.rs | 2 +- compiler/rustc_hir_analysis/src/autoderef.rs | 2 +- .../src/check/always_applicable.rs | 2 +- compiler/rustc_hir_analysis/src/check/check.rs | 6 +++--- .../src/check/compare_impl_item.rs | 12 ++++++------ .../src/check/compare_impl_item/refine.rs | 2 +- compiler/rustc_hir_analysis/src/check/entry.rs | 2 +- compiler/rustc_hir_analysis/src/check/mod.rs | 2 +- compiler/rustc_hir_analysis/src/check/wfcheck.rs | 14 +++++++++++--- .../rustc_hir_analysis/src/coherence/builtin.rs | 4 ++-- .../rustc_hir_analysis/src/coherence/orphan.rs | 2 +- compiler/rustc_hir_analysis/src/collect.rs | 2 +- compiler/rustc_hir_analysis/src/hir_wf_check.rs | 2 +- .../src/impl_wf_check/min_specialization.rs | 2 +- compiler/rustc_hir_typeck/src/coercion.rs | 10 +++++----- compiler/rustc_hir_typeck/src/expr.rs | 6 +++--- compiler/rustc_hir_typeck/src/fallback.rs | 2 +- compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs | 2 +- compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs | 2 +- compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs | 4 ++-- compiler/rustc_hir_typeck/src/method/probe.rs | 8 ++++---- compiler/rustc_hir_typeck/src/op.rs | 2 +- .../src/infer/canonical/query_response.rs | 2 +- compiler/rustc_infer/src/traits/engine.rs | 9 +++++---- .../rustc_lint/src/for_loops_over_fallibles.rs | 2 +- .../src/opaque_hidden_inferred_bound.rs | 4 ++-- compiler/rustc_mir_transform/src/coroutine.rs | 2 +- compiler/rustc_mir_transform/src/validate.rs | 2 +- compiler/rustc_passes/src/check_attr.rs | 4 ++-- compiler/rustc_passes/src/layout_test.rs | 2 +- .../src/error_reporting/traits/ambiguity.rs | 4 ++-- .../error_reporting/traits/fulfillment_errors.rs | 8 ++++---- .../src/error_reporting/traits/suggestions.rs | 4 ++-- compiler/rustc_trait_selection/src/infer.rs | 4 ++-- .../rustc_trait_selection/src/solve/fulfill.rs | 14 +++++++++++--- .../src/solve/inspect/analyse.rs | 2 +- .../rustc_trait_selection/src/solve/normalize.rs | 4 ++-- .../src/traits/auto_trait.rs | 2 +- .../src/traits/coherence.rs | 8 ++++---- .../src/traits/const_evaluatable.rs | 4 ++-- .../rustc_trait_selection/src/traits/engine.rs | 16 ++++++++++++---- .../rustc_trait_selection/src/traits/fulfill.rs | 14 +++++++++++--- .../rustc_trait_selection/src/traits/misc.rs | 8 ++++---- compiler/rustc_trait_selection/src/traits/mod.rs | 10 +++++----- .../src/traits/normalize.rs | 2 +- .../src/traits/query/dropck_outlives.rs | 2 +- .../src/traits/query/evaluate_obligation.rs | 2 +- .../src/traits/query/type_op/custom.rs | 2 +- .../src/traits/specialize/mod.rs | 10 +++++----- .../src/traits/structural_normalize.rs | 2 +- compiler/rustc_traits/src/codegen.rs | 2 +- compiler/rustc_traits/src/coroutine_witnesses.rs | 2 +- .../rustc_traits/src/normalize_projection_ty.rs | 2 +- compiler/rustc_ty_utils/src/structural_match.rs | 2 +- .../clippy/clippy_lints/src/future_not_send.rs | 2 +- .../clippy_utils/src/qualify_min_const_fn.rs | 2 +- .../rust-analyzer/crates/hir-ty/src/autoderef.rs | 2 +- .../crates/hir-ty/src/infer/coerce.rs | 6 +++--- .../crates/hir-ty/src/infer/expr.rs | 2 +- .../crates/hir-ty/src/infer/unify.rs | 2 +- .../crates/hir-ty/src/method_resolution.rs | 2 +- .../crates/hir-ty/src/next_solver/fulfill.rs | 14 +++++++------- .../crates/hir-ty/src/next_solver/inspect.rs | 2 +- .../crates/hir-ty/src/next_solver/normalize.rs | 4 ++-- .../hir-ty/src/next_solver/obligation_ctxt.rs | 8 ++++---- .../src/next_solver/structural_normalize.rs | 2 +- tests/ui/impl-trait/lazy_subtyping_of_opaques.rs | 2 +- 74 files changed, 175 insertions(+), 142 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs index 76da9dc883231..15b2a5ef2e213 100644 --- a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs @@ -420,7 +420,7 @@ fn try_extract_error_from_fulfill_cx<'a, 'tcx>( // We generally shouldn't have errors here because the query was // already run, but there's no point using `span_delayed_bug` // when we're going to emit an error here anyway. - let _errors = ocx.select_all_or_error(); + let _errors = ocx.evaluate_obligations_error_on_ambiguity(); let region_constraints = ocx.infcx.with_region_constraints(|r| r.clone()); try_extract_error_from_region_constraints( ocx.infcx, diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 7e20a5133e07f..9548710c12015 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -1313,7 +1313,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { let ocx = ObligationCtxt::new_with_diagnostics(self.infcx); let cause = ObligationCause::misc(expr.span, self.mir_def_id()); ocx.register_bound(cause, self.infcx.param_env, ty, clone_trait); - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if errors.iter().all(|error| { match error.obligation.predicate.as_clause().and_then(|c| c.as_trait_clause()) { Some(clause) => match clause.self_ty().skip_binder().kind() { @@ -1497,7 +1497,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { let cause = ObligationCause::misc(span, self.mir_def_id()); ocx.register_bound(cause, self.infcx.param_env, ty, def_id); - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); // Only emit suggestion if all required predicates are on generic let predicates: Result, _> = errors diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index bec4c934502d8..bad5f03e41274 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -1134,7 +1134,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { Obligation::misc(tcx, span, self.mir_def_id(), self.infcx.param_env, pred) })); - if ocx.select_all_or_error().is_empty() && count > 0 { + if ocx.evaluate_obligations_error_on_ambiguity().is_empty() && count > 0 { diag.span_suggestion_verbose( tcx.hir_body(*body).value.peel_blocks().span.shrink_to_lo(), fluent::borrowck_dereference_suggestion, diff --git a/compiler/rustc_borrowck/src/type_check/liveness/trace.rs b/compiler/rustc_borrowck/src/type_check/liveness/trace.rs index b704d8f0a7692..7ac94020de03b 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/trace.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/trace.rs @@ -657,7 +657,7 @@ impl<'tcx> LivenessContext<'_, '_, 'tcx> { let errors = match dropck_outlives::compute_dropck_outlives_with_errors( &ocx, op, span, ) { - Ok(_) => ocx.select_all_or_error(), + Ok(_) => ocx.evaluate_obligations_error_on_ambiguity(), Err(e) => e, }; diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 422b06350e1fc..ac3bcb1ea269f 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -139,7 +139,7 @@ pub fn validate_trivial_unsize<'tcx>( ) else { return false; }; - if !ocx.select_all_or_error().is_empty() { + if !ocx.evaluate_obligations_error_on_ambiguity().is_empty() { return false; } infcx.leak_check(universe, None).is_ok() diff --git a/compiler/rustc_const_eval/src/check_consts/check.rs b/compiler/rustc_const_eval/src/check_consts/check.rs index 3397bd9a68e4c..413aa5f8b8774 100644 --- a/compiler/rustc_const_eval/src/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/check_consts/check.rs @@ -415,7 +415,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> { ) })); - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if errors.is_empty() { Some(ConstConditionsHold::Yes) } else { diff --git a/compiler/rustc_const_eval/src/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/check_consts/qualifs.rs index 34d1fdd8c8694..0d21c333c3d27 100644 --- a/compiler/rustc_const_eval/src/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/check_consts/qualifs.rs @@ -119,7 +119,7 @@ impl Qualif for HasMutInterior { ty::TraitRef::new(cx.tcx, freeze_def_id, [ty::GenericArg::from(ty)]), ); ocx.register_obligation(obligation); - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); !errors.is_empty() } @@ -197,7 +197,7 @@ impl Qualif for NeedsNonConstDrop { }, ), )); - !ocx.select_all_or_error().is_empty() + !ocx.evaluate_obligations_error_on_ambiguity().is_empty() } fn is_structural_in_adt_value<'tcx>(cx: &ConstCx<'_, 'tcx>, adt: AdtDef<'tcx>) -> bool { diff --git a/compiler/rustc_const_eval/src/util/compare_types.rs b/compiler/rustc_const_eval/src/util/compare_types.rs index 9eed1a20f1523..8db056ed8737d 100644 --- a/compiler/rustc_const_eval/src/util/compare_types.rs +++ b/compiler/rustc_const_eval/src/util/compare_types.rs @@ -43,5 +43,5 @@ pub fn relate_types<'tcx>( Ok(()) => {} Err(_) => return false, }; - ocx.select_all_or_error().is_empty() + ocx.evaluate_obligations_error_on_ambiguity().is_empty() } diff --git a/compiler/rustc_hir_analysis/src/autoderef.rs b/compiler/rustc_hir_analysis/src/autoderef.rs index 88bd3339e4e18..1f06b1c94237d 100644 --- a/compiler/rustc_hir_analysis/src/autoderef.rs +++ b/compiler/rustc_hir_analysis/src/autoderef.rs @@ -199,7 +199,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> { // evaluate/fulfill mismatches, but that's not a reason for an ICE. return None; }; - let errors = ocx.select_where_possible(); + let errors = ocx.try_evaluate_obligations(); if !errors.is_empty() { if self.infcx.next_trait_solver() { unreachable!(); diff --git a/compiler/rustc_hir_analysis/src/check/always_applicable.rs b/compiler/rustc_hir_analysis/src/check/always_applicable.rs index 58c3020f60ede..0ff01477ff24c 100644 --- a/compiler/rustc_hir_analysis/src/check/always_applicable.rs +++ b/compiler/rustc_hir_analysis/src/check/always_applicable.rs @@ -235,7 +235,7 @@ fn ensure_impl_predicates_are_implied_by_item_defn<'tcx>( // They can probably get removed with better treatment of the new `DropImpl` // obligation cause code, and perhaps some custom logic in `report_region_errors`. - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { let mut guar = None; let mut root_predicates = FxHashSet::default(); diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 886ebddc75c97..2950b830eaf90 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -375,7 +375,7 @@ fn check_opaque_meets_bounds<'tcx>( // Check that all obligations are satisfied by the implementation's // version. - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { let guar = infcx.err_ctxt().report_fulfillment_errors(errors); return Err(guar); @@ -2028,7 +2028,7 @@ pub(super) fn check_coroutine_obligations( ocx.register_obligation(Obligation::new(tcx, cause.clone(), param_env, *predicate)); } - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); debug!(?errors); if !errors.is_empty() { return Err(infcx.err_ctxt().report_fulfillment_errors(errors)); @@ -2072,7 +2072,7 @@ pub(super) fn check_potentially_region_dependent_goals<'tcx>( ocx.register_obligation(Obligation::new(tcx, cause.clone(), param_env, predicate)); } - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); debug!(?errors); if errors.is_empty() { Ok(()) } else { Err(infcx.err_ctxt().report_fulfillment_errors(errors)) } } diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 946c4936bb64d..5b504cc246d85 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -363,7 +363,7 @@ fn compare_method_predicate_entailment<'tcx>( // Check that all obligations are satisfied by the implementation's // version. - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { let reported = infcx.err_ctxt().report_fulfillment_errors(errors); return Err(reported); @@ -669,7 +669,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( // Check that all obligations are satisfied by the implementation's // RPITs. - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { if let Err(guar) = try_report_async_mismatch(tcx, infcx, &errors, trait_m, impl_m, impl_sig) { @@ -1215,7 +1215,7 @@ fn check_region_late_boundedness<'tcx>( return None; }; - let errors = ocx.select_where_possible(); + let errors = ocx.try_evaluate_obligations(); if !errors.is_empty() { return None; } @@ -2106,7 +2106,7 @@ fn compare_const_predicate_entailment<'tcx>( // Check that all obligations are satisfied by the implementation's // version. - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { return Err(infcx.err_ctxt().report_fulfillment_errors(errors)); } @@ -2242,7 +2242,7 @@ fn compare_type_predicate_entailment<'tcx>( // Check that all obligations are satisfied by the implementation's // version. - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { let reported = infcx.err_ctxt().report_fulfillment_errors(errors); return Err(reported); @@ -2367,7 +2367,7 @@ pub(super) fn check_type_bounds<'tcx>( // Check that all obligations are satisfied by the implementation's // version. ocx.register_obligations(obligations); - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { let reported = infcx.err_ctxt().report_fulfillment_errors(errors); return Err(reported); diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs index 3db1c40228f6f..c20e5146546a2 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs @@ -164,7 +164,7 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>( param_env, trait_m_sig.inputs_and_output, )); - if !ocx.select_all_or_error().is_empty() { + if !ocx.evaluate_obligations_error_on_ambiguity().is_empty() { tcx.dcx().delayed_bug("encountered errors when checking RPITIT refinement (selection)"); return; } diff --git a/compiler/rustc_hir_analysis/src/check/entry.rs b/compiler/rustc_hir_analysis/src/check/entry.rs index 97787270be7c1..207cb83bcc8e4 100644 --- a/compiler/rustc_hir_analysis/src/check/entry.rs +++ b/compiler/rustc_hir_analysis/src/check/entry.rs @@ -138,7 +138,7 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) { let ocx = traits::ObligationCtxt::new_with_diagnostics(&infcx); let norm_return_ty = ocx.normalize(&cause, param_env, return_ty); ocx.register_bound(cause, param_env, norm_return_ty, term_did); - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { infcx.err_ctxt().report_fulfillment_errors(errors); error = true; diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs index e70d5505aae36..0166c3b980de3 100644 --- a/compiler/rustc_hir_analysis/src/check/mod.rs +++ b/compiler/rustc_hir_analysis/src/check/mod.rs @@ -660,7 +660,7 @@ pub fn check_function_signature<'tcx>( match ocx.eq(&cause, param_env, expected_sig, actual_sig) { Ok(()) => { - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { return Err(infcx.err_ctxt().report_fulfillment_errors(errors)); } diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 0a555c7f6e9df..7921e34ae4bd5 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -142,7 +142,7 @@ where } f(&mut wfcx)?; - let errors = wfcx.select_all_or_error(); + let errors = wfcx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { return Err(infcx.err_ctxt().report_fulfillment_errors(errors)); } @@ -1803,7 +1803,11 @@ fn receiver_is_valid<'tcx>( if let Ok(()) = wfcx.infcx.commit_if_ok(|_| { let ocx = ObligationCtxt::new(wfcx.infcx); ocx.eq(&cause, wfcx.param_env, self_ty, receiver_ty)?; - if ocx.select_all_or_error().is_empty() { Ok(()) } else { Err(NoSolution) } + if ocx.evaluate_obligations_error_on_ambiguity().is_empty() { + Ok(()) + } else { + Err(NoSolution) + } }) { return Ok(()); } @@ -1838,7 +1842,11 @@ fn receiver_is_valid<'tcx>( if let Ok(()) = wfcx.infcx.commit_if_ok(|_| { let ocx = ObligationCtxt::new(wfcx.infcx); ocx.eq(&cause, wfcx.param_env, self_ty, potential_self_ty)?; - if ocx.select_all_or_error().is_empty() { Ok(()) } else { Err(NoSolution) } + if ocx.evaluate_obligations_error_on_ambiguity().is_empty() { + Ok(()) + } else { + Err(NoSolution) + } }) { wfcx.register_obligations(autoderef.into_obligations()); return Ok(()); diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index 0b9a01d6042f1..b7a74ac445bfc 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -333,7 +333,7 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<() param_env, ty::TraitRef::new(tcx, trait_ref.def_id, [ty_a, ty_b]), )); - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { if is_from_coerce_pointee_derive(tcx, span) { return Err(tcx.dcx().emit_err(errors::CoerceFieldValidity { @@ -558,7 +558,7 @@ pub(crate) fn coerce_unsized_info<'tcx>( ty::TraitRef::new(tcx, trait_def_id, [source, target]), ); ocx.register_obligation(obligation); - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { if is_from_coerce_pointee_derive(tcx, span) { diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index 621431ae2343c..32cf35441987b 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -313,7 +313,7 @@ fn orphan_check<'tcx>( let ocx = traits::ObligationCtxt::new(&infcx); let ty = ocx.normalize(&cause, ty::ParamEnv::empty(), user_ty); let ty = infcx.resolve_vars_if_possible(ty); - let errors = ocx.select_where_possible(); + let errors = ocx.try_evaluate_obligations(); if !errors.is_empty() { return Ok(user_ty); } diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index b72e743f95b0f..b75a5443b8f8d 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -1267,7 +1267,7 @@ pub fn suggest_impl_trait<'tcx>( Ty::new_projection_from_args(infcx.tcx, assoc_item_def_id, args), ); // FIXME(compiler-errors): We may benefit from resolving regions here. - if ocx.select_where_possible().is_empty() + if ocx.try_evaluate_obligations().is_empty() && let item_ty = infcx.resolve_vars_if_possible(item_ty) && let Some(item_ty) = item_ty.make_suggestable(infcx.tcx, false, None) && let Some(sugg) = formatter( diff --git a/compiler/rustc_hir_analysis/src/hir_wf_check.rs b/compiler/rustc_hir_analysis/src/hir_wf_check.rs index d8578970adc94..f879153c5765a 100644 --- a/compiler/rustc_hir_analysis/src/hir_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/hir_wf_check.rs @@ -95,7 +95,7 @@ pub(super) fn diagnostic_hir_wf_check<'tcx>( ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(tcx_ty.into())), )); - for error in ocx.select_all_or_error() { + for error in ocx.evaluate_obligations_error_on_ambiguity() { debug!("Wf-check got error for {:?}: {:?}", ty, error); if error.obligation.predicate == self.predicate { // Save the cause from the greatest depth - this corresponds diff --git a/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs b/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs index b38639ed8c624..60a06cd8f7bc9 100644 --- a/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs +++ b/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs @@ -183,7 +183,7 @@ fn get_impl_args( &ObligationCause::misc(impl1_span, impl1_def_id), ); - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { let guar = ocx.infcx.err_ctxt().report_fulfillment_errors(errors); return Err(guar); diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index ced2cf2b57b14..1e5fea1db9fcc 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -140,7 +140,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { Ok(InferOk { value, obligations }) if self.next_trait_solver() => { let ocx = ObligationCtxt::new(self); ocx.register_obligations(obligations); - if ocx.select_where_possible().is_empty() { + if ocx.try_evaluate_obligations().is_empty() { Ok(InferOk { value, obligations: ocx.into_pending_obligations() }) } else { Err(TypeError::Mismatch) @@ -677,7 +677,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { Some(ty::PredicateKind::AliasRelate(..)) => { let ocx = ObligationCtxt::new(self); ocx.register_obligation(obligation); - if !ocx.select_where_possible().is_empty() { + if !ocx.try_evaluate_obligations().is_empty() { return Err(TypeError::Mismatch); } coercion.obligations.extend(ocx.into_pending_obligations()); @@ -1099,7 +1099,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return false; }; ocx.register_obligations(ok.obligations); - ocx.select_where_possible().is_empty() + ocx.try_evaluate_obligations().is_empty() }) } @@ -1203,7 +1203,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if self.next_trait_solver() { let ocx = ObligationCtxt::new(self); let value = ocx.lub(cause, self.param_env, prev_ty, new_ty)?; - if ocx.select_where_possible().is_empty() { + if ocx.try_evaluate_obligations().is_empty() { Ok(InferOk { value, obligations: ocx.into_pending_obligations(), @@ -1818,7 +1818,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { )) }), ); - ocx.select_where_possible().is_empty() + ocx.try_evaluate_obligations().is_empty() }) }; diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index d1ce0afddf91c..52525c6bd042d 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -2017,7 +2017,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.fudge_inference_if_ok(|| { let ocx = ObligationCtxt::new(self); ocx.sup(&self.misc(path_span), self.param_env, expected, adt_ty)?; - if !ocx.select_where_possible().is_empty() { + if !ocx.try_evaluate_obligations().is_empty() { return Err(TypeError::Mismatch); } Ok(self.resolve_vars_if_possible(adt_ty)) @@ -3678,7 +3678,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ), ); - let true_errors = ocx.select_where_possible(); + let true_errors = ocx.try_evaluate_obligations(); // Do a leak check -- we can't really report a useful error here, // but it at least avoids an ICE when the error has to do with higher-ranked @@ -3686,7 +3686,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.leak_check(outer_universe, Some(snapshot))?; // Bail if we have ambiguity errors, which we can't report in a useful way. - let ambiguity_errors = ocx.select_all_or_error(); + let ambiguity_errors = ocx.evaluate_obligations_error_on_ambiguity(); if true_errors.is_empty() && !ambiguity_errors.is_empty() { return Err(NoSolution); } diff --git a/compiler/rustc_hir_typeck/src/fallback.rs b/compiler/rustc_hir_typeck/src/fallback.rs index ef88e02fd98c2..be1c173ffbf6f 100644 --- a/compiler/rustc_hir_typeck/src/fallback.rs +++ b/compiler/rustc_hir_typeck/src/fallback.rs @@ -495,7 +495,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> { .expect("expected diverging var to be unconstrained"); } - ocx.select_where_possible() + ocx.try_evaluate_obligations() }) }; diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 833ce433d56f0..e51dd41c24542 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -660,7 +660,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, mutate_fulfillment_errors: impl Fn(&mut Vec>), ) { - let mut result = self.fulfillment_cx.borrow_mut().select_where_possible(self); + let mut result = self.fulfillment_cx.borrow_mut().try_evaluate_obligations(self); if !result.is_empty() { mutate_fulfillment_errors(&mut result); self.adjust_fulfillment_errors_for_expr_obligation(&mut result); diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 7ca8580e09866..d53f7e21a2b1c 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -255,7 +255,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // No argument expectations are produced if unification fails. let origin = self.misc(call_span); ocx.sup(&origin, self.param_env, expected_output, formal_output)?; - if !ocx.select_where_possible().is_empty() { + if !ocx.try_evaluate_obligations().is_empty() { return Err(TypeError::Mismatch); } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs index 7a060cafeab1c..e9f8bcd06be2d 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs @@ -199,7 +199,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ocx = ObligationCtxt::new(self); let normalized_fn_sig = ocx.normalize(&ObligationCause::dummy(), self.param_env, fn_sig); - if ocx.select_all_or_error().is_empty() { + if ocx.evaluate_obligations_error_on_ambiguity().is_empty() { let normalized_fn_sig = self.resolve_vars_if_possible(normalized_fn_sig); if !normalized_fn_sig.has_infer() { return normalized_fn_sig; @@ -347,7 +347,7 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> { ); ocx.register_obligations(impl_obligations); - let mut errors = ocx.select_where_possible(); + let mut errors = ocx.try_evaluate_obligations(); if !errors.is_empty() { fulfillment_errors.append(&mut errors); return false; diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 12f80a197b1b8..1ef1fdef6c99d 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -1906,7 +1906,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { // them to deal with defining uses in `method_autoderef_steps`. if self.next_trait_solver() { ocx.register_obligations(instantiate_self_ty_obligations.iter().cloned()); - let errors = ocx.select_where_possible(); + let errors = ocx.try_evaluate_obligations(); if !errors.is_empty() { unreachable!("unexpected autoderef error {errors:?}"); } @@ -2103,7 +2103,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { } // Evaluate those obligations to see if they might possibly hold. - for error in ocx.select_where_possible() { + for error in ocx.try_evaluate_obligations() { result = ProbeResult::NoMatch; let nested_predicate = self.resolve_vars_if_possible(error.obligation.predicate); if let Some(trait_predicate) = trait_predicate @@ -2143,7 +2143,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { } // Evaluate those obligations to see if they might possibly hold. - for error in ocx.select_where_possible() { + for error in ocx.try_evaluate_obligations() { result = ProbeResult::NoMatch; possibly_unsatisfied_predicates.push(( error.obligation.predicate, @@ -2230,7 +2230,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { }; let ocx = ObligationCtxt::new(self); let self_ty = ocx.register_infer_ok_obligations(ok); - if !ocx.select_where_possible().is_empty() { + if !ocx.try_evaluate_obligations().is_empty() { debug!("failed to prove instantiate self_ty obligations"); return false; } diff --git a/compiler/rustc_hir_typeck/src/op.rs b/compiler/rustc_hir_typeck/src/op.rs index a8e8582c51c49..d18aed00a6f6d 100644 --- a/compiler/rustc_hir_typeck/src/op.rs +++ b/compiler/rustc_hir_typeck/src/op.rs @@ -1030,7 +1030,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); let ocx = ObligationCtxt::new_with_diagnostics(&self.infcx); ocx.register_obligation(obligation); - Err(ocx.select_all_or_error()) + Err(ocx.evaluate_obligations_error_on_ambiguity()) } } } diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index b3959113d5dc9..05022e6f02561 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -125,7 +125,7 @@ impl<'tcx> InferCtxt<'tcx> { T: Debug + TypeFoldable>, { // Select everything, returning errors. - let errors = fulfill_cx.select_all_or_error(self); + let errors = fulfill_cx.evaluate_obligations_error_on_ambiguity(self); // True error! if errors.iter().any(|e| e.is_true_error()) { diff --git a/compiler/rustc_infer/src/traits/engine.rs b/compiler/rustc_infer/src/traits/engine.rs index 4a252719694d5..39fff48de6aa6 100644 --- a/compiler/rustc_infer/src/traits/engine.rs +++ b/compiler/rustc_infer/src/traits/engine.rs @@ -72,6 +72,7 @@ pub trait TraitEngine<'tcx, E: 'tcx>: 'tcx { self.register_predicate_obligation(infcx, obligation); } } + /// Go over the list of pending obligations and try to evaluate them. /// /// For each result: @@ -81,7 +82,7 @@ pub trait TraitEngine<'tcx, E: 'tcx>: 'tcx { /// /// Returns a list of errors from obligations that evaluated to Err. #[must_use] - fn select_where_possible(&mut self, infcx: &InferCtxt<'tcx>) -> Vec; + fn try_evaluate_obligations(&mut self, infcx: &InferCtxt<'tcx>) -> Vec; fn collect_remaining_errors(&mut self, infcx: &InferCtxt<'tcx>) -> Vec; @@ -94,8 +95,8 @@ pub trait TraitEngine<'tcx, E: 'tcx>: 'tcx { /// /// Returns a list of errors from obligations that evaluated to Ambiguous or Err. #[must_use] - fn select_all_or_error(&mut self, infcx: &InferCtxt<'tcx>) -> Vec { - let errors = self.select_where_possible(infcx); + fn evaluate_obligations_error_on_ambiguity(&mut self, infcx: &InferCtxt<'tcx>) -> Vec { + let errors = self.try_evaluate_obligations(infcx); if !errors.is_empty() { return errors; } @@ -108,7 +109,7 @@ pub trait TraitEngine<'tcx, E: 'tcx>: 'tcx { fn pending_obligations(&self) -> PredicateObligations<'tcx>; /// Among all pending obligations, collect those are stalled on a inference variable which has - /// changed since the last call to `select_where_possible`. Those obligations are marked as + /// changed since the last call to `try_evaluate_obligations`. Those obligations are marked as /// successful and returned. fn drain_stalled_obligations_for_coroutines( &mut self, diff --git a/compiler/rustc_lint/src/for_loops_over_fallibles.rs b/compiler/rustc_lint/src/for_loops_over_fallibles.rs index 9e1fc59817119..fe95a682c6376 100644 --- a/compiler/rustc_lint/src/for_loops_over_fallibles.rs +++ b/compiler/rustc_lint/src/for_loops_over_fallibles.rs @@ -180,5 +180,5 @@ fn suggest_question_mark<'tcx>( into_iterator_did, ); - ocx.select_all_or_error().is_empty() + ocx.evaluate_obligations_error_on_ambiguity().is_empty() } diff --git a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs index f836094191e1d..3f2ca92a021a6 100644 --- a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs +++ b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs @@ -151,7 +151,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { let ocx = ObligationCtxt::new(infcx); let assoc_pred = ocx.normalize(&traits::ObligationCause::dummy(), cx.param_env, assoc_pred); - if !ocx.select_all_or_error().is_empty() { + if !ocx.evaluate_obligations_error_on_ambiguity().is_empty() { // Can't normalize for some reason...? continue; } @@ -166,7 +166,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { // If that predicate doesn't hold modulo regions (but passed during type-check), // then we must've taken advantage of the hack in `project_and_unify_types` where // we replace opaques with inference vars. Emit a warning! - if !ocx.select_all_or_error().is_empty() { + if !ocx.evaluate_obligations_error_on_ambiguity().is_empty() { // If it's a trait bound and an opaque that doesn't satisfy it, // then we can emit a suggestion to add the bound. let add_bound = match (proj_term.kind(), assoc_pred.kind().skip_binder()) { diff --git a/compiler/rustc_mir_transform/src/coroutine.rs b/compiler/rustc_mir_transform/src/coroutine.rs index c5cd06f170c47..af437b6dbe01e 100644 --- a/compiler/rustc_mir_transform/src/coroutine.rs +++ b/compiler/rustc_mir_transform/src/coroutine.rs @@ -1429,7 +1429,7 @@ fn check_field_tys_sized<'tcx>( ); } - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); debug!(?errors); if !errors.is_empty() { infcx.err_ctxt().report_fulfillment_errors(errors); diff --git a/compiler/rustc_mir_transform/src/validate.rs b/compiler/rustc_mir_transform/src/validate.rs index c8a9a88dc3fe3..75722f0ea0bf3 100644 --- a/compiler/rustc_mir_transform/src/validate.rs +++ b/compiler/rustc_mir_transform/src/validate.rs @@ -623,7 +623,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { param_env, pred, )); - ocx.select_all_or_error().is_empty() + ocx.evaluate_obligations_error_on_ambiguity().is_empty() } } diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 007353f136d56..5cd3640fe3bf9 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -1972,7 +1972,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { let sig = ocx.normalize(&cause, param_env, sig); // proc macro is not WF. - let errors = ocx.select_where_possible(); + let errors = ocx.try_evaluate_obligations(); if !errors.is_empty() { return; } @@ -2040,7 +2040,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { self.abort.set(true); } - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { infcx.err_ctxt().report_fulfillment_errors(errors); self.abort.set(true); diff --git a/compiler/rustc_passes/src/layout_test.rs b/compiler/rustc_passes/src/layout_test.rs index a19faf0fa8367..4054cfa56330e 100644 --- a/compiler/rustc_passes/src/layout_test.rs +++ b/compiler/rustc_passes/src/layout_test.rs @@ -56,7 +56,7 @@ pub fn ensure_wf<'tcx>( pred, ); ocx.register_obligation(obligation); - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { infcx.err_ctxt().report_fulfillment_errors(errors); false diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs index af912227ce4e4..edb002c69e760 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs @@ -83,7 +83,7 @@ pub fn compute_applicable_impls_for_diagnostics<'tcx>( }); ocx.register_obligations(obligations); - ocx.select_where_possible().is_empty() + ocx.try_evaluate_obligations().is_empty() }) }; @@ -113,7 +113,7 @@ pub fn compute_applicable_impls_for_diagnostics<'tcx>( return false; } - ocx.select_where_possible().is_empty() + ocx.try_evaluate_obligations().is_empty() }) }; diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index d485eb7266b28..119bf3cb9ec65 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -1469,7 +1469,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { // // we intentionally drop errors from normalization here, // since the normalization is just done to improve the error message. - let _ = ocx.select_where_possible(); + let _ = ocx.try_evaluate_obligations(); if let Err(new_err) = ocx.eq(&obligation.cause, obligation.param_env, data.term, normalized_term) @@ -2070,7 +2070,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { ) }), ); - if !ocx.select_where_possible().is_empty() { + if !ocx.try_evaluate_obligations().is_empty() { return false; } @@ -2086,7 +2086,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { { terrs.push(terr); } - if !ocx.select_where_possible().is_empty() { + if !ocx.try_evaluate_obligations().is_empty() { return false; } } @@ -3352,7 +3352,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { ); let ocx = ObligationCtxt::new(self); ocx.register_obligation(obligation); - if ocx.select_all_or_error().is_empty() { + if ocx.evaluate_obligations_error_on_ambiguity().is_empty() { return Ok(( self.tcx .fn_trait_kind_from_def_id(trait_def_id) diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 37e622102e70f..b7d801f6774db 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -4572,7 +4572,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { param_env, projection, )); - if ocx.select_where_possible().is_empty() + if ocx.try_evaluate_obligations().is_empty() && let ty = self.resolve_vars_if_possible(ty) && !ty.is_ty_var() { @@ -4719,7 +4719,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { pred, )); }); - if !ocx.select_where_possible().is_empty() { + if !ocx.try_evaluate_obligations().is_empty() { // encountered errors. return; } diff --git a/compiler/rustc_trait_selection/src/infer.rs b/compiler/rustc_trait_selection/src/infer.rs index cd076d1cb692a..f55468d6324af 100644 --- a/compiler/rustc_trait_selection/src/infer.rs +++ b/compiler/rustc_trait_selection/src/infer.rs @@ -25,7 +25,7 @@ impl<'tcx> InferCtxt<'tcx> { let Ok(()) = ocx.eq(&ObligationCause::dummy(), param_env, a, b) else { return false; }; - ocx.select_where_possible().is_empty() + ocx.try_evaluate_obligations().is_empty() }) } @@ -124,7 +124,7 @@ impl<'tcx> InferCtxt<'tcx> { param_env, ty::TraitRef::new(self.tcx, trait_def_id, [ty]), )); - let errors = ocx.select_where_possible(); + let errors = ocx.try_evaluate_obligations(); // Find the original predicate in the list of predicates that could definitely not be fulfilled. // If it is in that list, then we know this doesn't even shallowly implement the trait. // If it is not in that list, it was fulfilled, but there may be nested obligations, which we don't care about here. diff --git a/compiler/rustc_trait_selection/src/solve/fulfill.rs b/compiler/rustc_trait_selection/src/solve/fulfill.rs index bff4f6ce3fc6b..6355bd761dfd6 100644 --- a/compiler/rustc_trait_selection/src/solve/fulfill.rs +++ b/compiler/rustc_trait_selection/src/solve/fulfill.rs @@ -60,7 +60,7 @@ struct ObligationStorage<'tcx> { /// Obligations which resulted in an overflow in fulfillment itself. /// /// We cannot eagerly return these as error so we instead store them here - /// to avoid recomputing them each time `select_where_possible` is called. + /// to avoid recomputing them each time `try_evaluate_obligations` is called. /// This also allows us to return the correct `FulfillmentError` for them. overflowed: Vec>, pending: PendingObligations<'tcx>, @@ -101,7 +101,7 @@ impl<'tcx> ObligationStorage<'tcx> { // IMPORTANT: we must not use solve any inference variables in the obligations // as this is all happening inside of a probe. We use a probe to make sure // we get all obligations involved in the overflow. We pretty much check: if - // we were to do another step of `select_where_possible`, which goals would + // we were to do another step of `try_evaluate_obligations`, which goals would // change. // FIXME: is merged, this can be removed. self.overflowed.extend( @@ -179,7 +179,15 @@ where .collect() } - fn select_where_possible(&mut self, infcx: &InferCtxt<'tcx>) -> Vec { + /// Go over the list of pending obligations and try to evaluate them. + /// + /// For each result: + /// Ok: remove the obligation from the list + /// Ambiguous: leave the obligation in the list to be evaluated later + /// Err: remove the obligation from the list and return an error + /// + /// Returns a list of errors from obligations that evaluated to Err. + fn try_evaluate_obligations(&mut self, infcx: &InferCtxt<'tcx>) -> Vec { assert_eq!(self.usable_in_snapshot, infcx.num_open_snapshots()); let mut errors = Vec::new(); loop { diff --git a/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs b/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs index c010add0fc50f..488315054c6aa 100644 --- a/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs +++ b/compiler/rustc_trait_selection/src/solve/inspect/analyse.rs @@ -76,7 +76,7 @@ impl<'tcx> NormalizesToTermHack<'tcx> { self.unconstrained_term, )?; f(&ocx); - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if errors.is_empty() { Ok(Certainty::Yes) } else if errors.iter().all(|e| !e.is_true_error()) { diff --git a/compiler/rustc_trait_selection/src/solve/normalize.rs b/compiler/rustc_trait_selection/src/solve/normalize.rs index 8f44c26b70dad..2e5c3fe00b9cb 100644 --- a/compiler/rustc_trait_selection/src/solve/normalize.rs +++ b/compiler/rustc_trait_selection/src/solve/normalize.rs @@ -79,7 +79,7 @@ where stalled_coroutine_goals: vec![], }; let value = value.try_fold_with(&mut folder)?; - let errors = folder.fulfill_cx.select_all_or_error(at.infcx); + let errors = folder.fulfill_cx.evaluate_obligations_error_on_ambiguity(at.infcx); if errors.is_empty() { Ok((value, folder.stalled_coroutine_goals)) } else { Err(errors) } } @@ -144,7 +144,7 @@ where } fn select_all_and_stall_coroutine_predicates(&mut self) -> Result<(), Vec> { - let errors = self.fulfill_cx.select_where_possible(self.at.infcx); + let errors = self.fulfill_cx.try_evaluate_obligations(self.at.infcx); if !errors.is_empty() { return Err(errors); } diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index c63cc0e17ab9f..09709291a4b95 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -155,7 +155,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { // an additional sanity check. let ocx = ObligationCtxt::new(&infcx); ocx.register_bound(ObligationCause::dummy(), full_env, ty, trait_did); - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { panic!("Unable to fulfill trait {trait_did:?} for '{ty:?}': {errors:?}"); } diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 8e8c7dd7c9d48..d81030ad7c492 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -371,7 +371,7 @@ fn impl_intersection_has_impossible_obligation<'a, 'cx, 'tcx>( let ocx = ObligationCtxt::new(infcx); ocx.register_obligations(obligations.iter().cloned()); - let hard_errors = ocx.select_where_possible(); + let hard_errors = ocx.try_evaluate_obligations(); if !hard_errors.is_empty() { assert!( hard_errors.iter().all(|e| e.is_true_error()), @@ -386,7 +386,7 @@ fn impl_intersection_has_impossible_obligation<'a, 'cx, 'tcx>( let ambiguities = ocx.into_pending_obligations(); let ocx = ObligationCtxt::new_with_diagnostics(infcx); ocx.register_obligations(ambiguities); - let errors_and_ambiguities = ocx.select_all_or_error(); + let errors_and_ambiguities = ocx.evaluate_obligations_error_on_ambiguity(); // We only care about the obligations that are *definitely* true errors. // Ambiguities do not prove the disjointness of two impls. let (errors, ambiguities): (Vec<_>, Vec<_>) = @@ -623,7 +623,7 @@ fn try_prove_negated_where_clause<'tcx>( param_env, negative_predicate, )); - if !ocx.select_all_or_error().is_empty() { + if !ocx.evaluate_obligations_error_on_ambiguity().is_empty() { return false; } @@ -743,7 +743,7 @@ impl<'a, 'tcx> ProofTreeVisitor<'tcx> for AmbiguityCausesVisitor<'a, 'tcx> { ty = ocx .structurally_normalize_ty(&ObligationCause::dummy(), param_env, ty) .map_err(|_| ())?; - if !ocx.select_where_possible().is_empty() { + if !ocx.try_evaluate_obligations().is_empty() { return Err(()); } } diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index 39333082acdff..45f30cd14c672 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -176,7 +176,7 @@ fn satisfied_from_param_env<'tcx>( if self.infcx.probe(|_| { let ocx = ObligationCtxt::new(self.infcx); ocx.eq(&ObligationCause::dummy(), self.param_env, c, self.ct).is_ok() - && ocx.select_all_or_error().is_empty() + && ocx.evaluate_obligations_error_on_ambiguity().is_empty() }) { self.single_match = match self.single_match { None => Some(Ok(c)), @@ -217,7 +217,7 @@ fn satisfied_from_param_env<'tcx>( if let Some(Ok(c)) = single_match { let ocx = ObligationCtxt::new(infcx); assert!(ocx.eq(&ObligationCause::dummy(), param_env, c, ct).is_ok()); - assert!(ocx.select_all_or_error().is_empty()); + assert!(ocx.evaluate_obligations_error_on_ambiguity().is_empty()); return true; } diff --git a/compiler/rustc_trait_selection/src/traits/engine.rs b/compiler/rustc_trait_selection/src/traits/engine.rs index 18f28d72f6f8f..604d1e9c82ba1 100644 --- a/compiler/rustc_trait_selection/src/traits/engine.rs +++ b/compiler/rustc_trait_selection/src/traits/engine.rs @@ -202,14 +202,22 @@ where .map(|infer_ok| self.register_infer_ok_obligations(infer_ok)) } + /// Go over the list of pending obligations and try to evaluate them. + /// + /// For each result: + /// Ok: remove the obligation from the list + /// Ambiguous: leave the obligation in the list to be evaluated later + /// Err: remove the obligation from the list and return an error + /// + /// Returns a list of errors from obligations that evaluated to Err. #[must_use] - pub fn select_where_possible(&self) -> Vec { - self.engine.borrow_mut().select_where_possible(self.infcx) + pub fn try_evaluate_obligations(&self) -> Vec { + self.engine.borrow_mut().try_evaluate_obligations(self.infcx) } #[must_use] - pub fn select_all_or_error(&self) -> Vec { - self.engine.borrow_mut().select_all_or_error(self.infcx) + pub fn evaluate_obligations_error_on_ambiguity(&self) -> Vec { + self.engine.borrow_mut().evaluate_obligations_error_on_ambiguity(self.infcx) } /// Returns the not-yet-processed and stalled obligations from the diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index 6b884b3608044..d2dc9418a3a5f 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -52,11 +52,11 @@ impl<'tcx> ForestObligation for PendingPredicateObligation<'tcx> { /// consists of a list of obligations that must be (eventually) /// satisfied. The job is to track which are satisfied, which yielded /// errors, and which are still pending. At any point, users can call -/// `select_where_possible`, and the fulfillment context will try to do +/// `try_evaluate_obligations`, and the fulfillment context will try to do /// selection, retaining only those obligations that remain /// ambiguous. This may be helpful in pushing type inference /// along. Once all type inference constraints have been generated, the -/// method `select_all_or_error` can be used to report any remaining +/// method `evaluate_obligations_error_on_ambiguity` can be used to report any remaining /// ambiguous cases as errors. pub struct FulfillmentContext<'tcx, E: 'tcx> { /// A list of all obligations that have been registered with this @@ -163,7 +163,15 @@ where .collect() } - fn select_where_possible(&mut self, infcx: &InferCtxt<'tcx>) -> Vec { + /// Go over the list of pending obligations and try to evaluate them. + /// + /// For each result: + /// Ok: remove the obligation from the list + /// Ambiguous: leave the obligation in the list to be evaluated later + /// Err: remove the obligation from the list and return an error + /// + /// Returns a list of errors from obligations that evaluated to Err. + fn try_evaluate_obligations(&mut self, infcx: &InferCtxt<'tcx>) -> Vec { let selcx = SelectionContext::new(infcx); self.select(selcx) } diff --git a/compiler/rustc_trait_selection/src/traits/misc.rs b/compiler/rustc_trait_selection/src/traits/misc.rs index 4c25882daa92f..f33196bab6470 100644 --- a/compiler/rustc_trait_selection/src/traits/misc.rs +++ b/compiler/rustc_trait_selection/src/traits/misc.rs @@ -156,7 +156,7 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>( ty::ClauseKind::UnstableFeature(sym::unsized_const_params), )); - if !ocx.select_all_or_error().is_empty() { + if !ocx.evaluate_obligations_error_on_ambiguity().is_empty() { return Err(ConstParamTyImplementationError::UnsizedConstParamsFeatureRequired); } } @@ -168,7 +168,7 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>( tcx.require_lang_item(LangItem::ConstParamTy, parent_cause.span), ); - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { infringing_inner_tys.push((inner_ty, InfringingFieldsReason::Fulfill(errors))); continue; @@ -235,7 +235,7 @@ pub fn all_fields_implement_trait<'tcx>( ObligationCause::dummy_with_span(field_ty_span) }; let ty = ocx.normalize(&normalization_cause, param_env, unnormalized_ty); - let normalization_errors = ocx.select_where_possible(); + let normalization_errors = ocx.try_evaluate_obligations(); // NOTE: The post-normalization type may also reference errors, // such as when we project to a missing type or we have a mismatch @@ -252,7 +252,7 @@ pub fn all_fields_implement_trait<'tcx>( ty, trait_def_id, ); - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { infringing.push((field, ty, InfringingFieldsReason::Fulfill(errors))); } diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 6fefac436994d..c6c2d70ef71f4 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -231,7 +231,7 @@ fn pred_known_to_hold_modulo_regions<'tcx>( let ocx = ObligationCtxt::new(infcx); ocx.register_obligation(obligation); - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); match errors.as_slice() { // Only known to hold if we did no inference. [] => infcx.resolve_vars_if_possible(goal) == goal, @@ -273,7 +273,7 @@ fn do_normalize_predicates<'tcx>( let ocx = ObligationCtxt::new_with_diagnostics(&infcx); let predicates = ocx.normalize(&cause, elaborated_env, predicates); - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { let reported = infcx.err_ctxt().report_fulfillment_errors(errors); return Err(reported); @@ -738,13 +738,13 @@ pub fn impossible_predicates<'tcx>(tcx: TyCtxt<'tcx>, predicates: Vec At<'_, 'tcx> { let value = self .normalize(value) .into_value_registering_obligations(self.infcx, &mut *fulfill_cx); - let errors = fulfill_cx.select_all_or_error(self.infcx); + let errors = fulfill_cx.evaluate_obligations_error_on_ambiguity(self.infcx); let value = self.infcx.resolve_vars_if_possible(value); if errors.is_empty() { Ok(value) diff --git a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs index 945ca7c37758f..2e60805cd10a5 100644 --- a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs +++ b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs @@ -199,7 +199,7 @@ where // Flush errors b/c `deeply_normalize` doesn't expect pending // obligations, and we may have pending obligations from the // branch above (from other types). - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { return Err(errors); } diff --git a/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs b/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs index 34e0176d213f1..d383cdc1aefa6 100644 --- a/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs +++ b/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs @@ -96,7 +96,7 @@ impl<'tcx> InferCtxt<'tcx> { let ocx = ObligationCtxt::new(self); ocx.register_obligation(obligation.clone()); let mut result = EvaluationResult::EvaluatedToOk; - for error in ocx.select_all_or_error() { + for error in ocx.evaluate_obligations_error_on_ambiguity() { if error.is_true_error() { return Ok(EvaluationResult::EvaluatedToErr); } else { diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs index a96cb738b81f0..2b58a65051e1a 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs @@ -94,7 +94,7 @@ where let value = op(&ocx).map_err(|_| { infcx.dcx().span_delayed_bug(span, format!("error performing operation: {name}")) })?; - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if errors.is_empty() { Ok(value) } else if let Err(guar) = infcx.tcx.check_potentially_region_dependent_goals(root_def_id) { diff --git a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs index 4bb12694c478a..ab01d0707e0f1 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs @@ -164,7 +164,7 @@ fn fulfill_implication<'tcx>( let ocx = ObligationCtxt::new(infcx); let source_trait_ref = ocx.normalize(cause, param_env, source_trait_ref); - if !ocx.select_all_or_error().is_empty() { + if !ocx.evaluate_obligations_error_on_ambiguity().is_empty() { infcx.dcx().span_delayed_bug( infcx.tcx.def_span(source_impl), format!("failed to fully normalize {source_trait_ref}"), @@ -197,7 +197,7 @@ fn fulfill_implication<'tcx>( let obligations = predicates_for_generics(|_, _| cause.clone(), param_env, predicates); ocx.register_obligations(obligations); - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { // no dice! debug!( @@ -295,7 +295,7 @@ pub(super) fn specializes( let ocx = ObligationCtxt::new(&infcx); let specializing_impl_trait_ref = ocx.normalize(cause, param_env, specializing_impl_trait_ref); - if !ocx.select_all_or_error().is_empty() { + if !ocx.evaluate_obligations_error_on_ambiguity().is_empty() { infcx.dcx().span_delayed_bug( infcx.tcx.def_span(specializing_impl_def_id), format!("failed to fully normalize {specializing_impl_trait_ref}"), @@ -331,7 +331,7 @@ pub(super) fn specializes( let obligations = predicates_for_generics(|_, _| cause.clone(), param_env, predicates); ocx.register_obligations(obligations); - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { // no dice! debug!( @@ -367,7 +367,7 @@ pub(super) fn specializes( ) })); - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { // no dice! debug!( diff --git a/compiler/rustc_trait_selection/src/traits/structural_normalize.rs b/compiler/rustc_trait_selection/src/traits/structural_normalize.rs index 2e20ede2f50a8..ebeab8eddc6f5 100644 --- a/compiler/rustc_trait_selection/src/traits/structural_normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/structural_normalize.rs @@ -52,7 +52,7 @@ impl<'tcx> At<'_, 'tcx> { ); fulfill_cx.register_predicate_obligation(self.infcx, obligation); - let errors = fulfill_cx.select_where_possible(self.infcx); + let errors = fulfill_cx.try_evaluate_obligations(self.infcx); if !errors.is_empty() { return Err(errors); } diff --git a/compiler/rustc_traits/src/codegen.rs b/compiler/rustc_traits/src/codegen.rs index 4b05e2cc38118..f3b43541b7cbe 100644 --- a/compiler/rustc_traits/src/codegen.rs +++ b/compiler/rustc_traits/src/codegen.rs @@ -59,7 +59,7 @@ pub(crate) fn codegen_select_candidate<'tcx>( // In principle, we only need to do this so long as `impl_source` // contains unbound type parameters. It could be a slight // optimization to stop iterating early. - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if !errors.is_empty() { // `rustc_monomorphize::collector` assumes there are no type errors. // Cycle errors are the only post-monomorphization errors possible; emit them now so diff --git a/compiler/rustc_traits/src/coroutine_witnesses.rs b/compiler/rustc_traits/src/coroutine_witnesses.rs index 20f9b01372482..2544cd8a13cd8 100644 --- a/compiler/rustc_traits/src/coroutine_witnesses.rs +++ b/compiler/rustc_traits/src/coroutine_witnesses.rs @@ -63,7 +63,7 @@ fn compute_assumptions<'tcx>( ty::ClauseKind::WellFormed(ty.into()), ) })); - let _errors = ocx.select_all_or_error(); + let _errors = ocx.evaluate_obligations_error_on_ambiguity(); let region_obligations = infcx.take_registered_region_obligations(); let region_assumptions = infcx.take_registered_region_assumptions(); diff --git a/compiler/rustc_traits/src/normalize_projection_ty.rs b/compiler/rustc_traits/src/normalize_projection_ty.rs index e52898cc6e242..db871d4b0aaad 100644 --- a/compiler/rustc_traits/src/normalize_projection_ty.rs +++ b/compiler/rustc_traits/src/normalize_projection_ty.rs @@ -45,7 +45,7 @@ fn normalize_canonicalized_projection_ty<'tcx>( // are recursive (given some generic parameters of the opaque's type variables). // In that case, we may only realize a cycle error when calling // `normalize_erasing_regions` in mono. - let errors = ocx.select_where_possible(); + let errors = ocx.try_evaluate_obligations(); if !errors.is_empty() { // Rustdoc may attempt to normalize type alias types which are not // well-formed. Rustdoc also normalizes types that are just not diff --git a/compiler/rustc_ty_utils/src/structural_match.rs b/compiler/rustc_ty_utils/src/structural_match.rs index e900264a76c7e..80d9c53b108f5 100644 --- a/compiler/rustc_ty_utils/src/structural_match.rs +++ b/compiler/rustc_ty_utils/src/structural_match.rs @@ -28,7 +28,7 @@ fn has_structural_eq_impl<'tcx>(tcx: TyCtxt<'tcx>, adt_ty: Ty<'tcx>) -> bool { // // 2. We are sometimes doing future-incompatibility lints for // now, so we do not want unconditional errors here. - ocx.select_all_or_error().is_empty() + ocx.evaluate_obligations_error_on_ambiguity().is_empty() } pub(crate) fn provide(providers: &mut Providers) { diff --git a/src/tools/clippy/clippy_lints/src/future_not_send.rs b/src/tools/clippy/clippy_lints/src/future_not_send.rs index 596047977a9b1..221107ba4b93e 100644 --- a/src/tools/clippy/clippy_lints/src/future_not_send.rs +++ b/src/tools/clippy/clippy_lints/src/future_not_send.rs @@ -90,7 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { let ocx = ObligationCtxt::new_with_diagnostics(&infcx); let cause = traits::ObligationCause::misc(span, fn_def_id); ocx.register_bound(cause, cx.param_env, ret_ty, send_trait); - let send_errors = ocx.select_all_or_error(); + let send_errors = ocx.evaluate_obligations_error_on_ambiguity(); // Allow errors that try to prove `Send` for types that "mention" a generic parameter at the "top // level". diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs index 2bda6d50373cd..ff4ad547a8df0 100644 --- a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs +++ b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs @@ -475,7 +475,7 @@ fn is_ty_const_destruct<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, body: &Body<'tcx> let ocx = ObligationCtxt::new(&infcx); ocx.register_obligations(impl_src.nested_obligations()); - ocx.select_all_or_error().is_empty() + ocx.evaluate_obligations_error_on_ambiguity().is_empty() } !ty.needs_drop(tcx, ConstCx::new(tcx, body).typing_env) diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs b/src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs index fd60ffcf24b0a..62e4c9d3fb347 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/autoderef.rs @@ -304,7 +304,7 @@ fn structurally_normalize_ty<'db>( // evaluate/fulfill mismatches, but that's not a reason for an ICE. return None; }; - let errors = ocx.select_where_possible(); + let errors = ocx.try_evaluate_obligations(); if !errors.is_empty() { unreachable!(); } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer/coerce.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/coerce.rs index 7930d8b0ed68f..1a8c7976c086e 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/coerce.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer/coerce.rs @@ -160,7 +160,7 @@ impl<'a, 'b, 'db> Coerce<'a, 'b, 'db> { Ok(InferOk { value, obligations }) => { let mut ocx = ObligationCtxt::new(this.infer_ctxt()); ocx.register_obligations(obligations); - if ocx.select_where_possible().is_empty() { + if ocx.try_evaluate_obligations().is_empty() { Ok(InferOk { value, obligations: ocx.into_pending_obligations() }) } else { Err(TypeError::Mismatch) @@ -744,7 +744,7 @@ impl<'a, 'b, 'db> Coerce<'a, 'b, 'db> { Some(PredicateKind::AliasRelate(..)) => { let mut ocx = ObligationCtxt::new(self.infer_ctxt()); ocx.register_obligation(obligation); - if !ocx.select_where_possible().is_empty() { + if !ocx.try_evaluate_obligations().is_empty() { return Err(TypeError::Mismatch); } coercion.obligations.extend(ocx.into_pending_obligations()); @@ -1116,7 +1116,7 @@ impl<'db> InferenceContext<'db> { let mut ocx = ObligationCtxt::new(&table.infer_ctxt); let value = ocx.lub(&ObligationCause::new(), table.param_env, prev_ty, new_ty)?; - if ocx.select_where_possible().is_empty() { + if ocx.try_evaluate_obligations().is_empty() { Ok(InferOk { value, obligations: ocx.into_pending_obligations() }) } else { Err(TypeError::Mismatch) diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs index c5a51dfc4cf92..254fa24323ef4 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs @@ -2136,7 +2136,7 @@ impl<'db> InferenceContext<'db> { expected_output.to_nextsolver(interner), formal_output, )?; - if !ocx.select_where_possible().is_empty() { + if !ocx.try_evaluate_obligations().is_empty() { return Err(crate::next_solver::TypeError::Mismatch); } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs b/src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs index 1687857ae1ac2..4d3f543d10a04 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/infer/unify.rs @@ -938,7 +938,7 @@ impl<'db> InferenceTable<'db> { } pub(crate) fn select_obligations_where_possible(&mut self) { - self.fulfillment_cx.select_where_possible(&self.infer_ctxt); + self.fulfillment_cx.try_evaluate_obligations(&self.infer_ctxt); } pub(super) fn register_predicate( diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs b/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs index 7fa3d31fe5fdc..1d52ed65fbb3e 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs @@ -1772,7 +1772,7 @@ fn is_valid_trait_method_candidate( ctxt.register_predicate_obligation(&table.infer_ctxt, pred); } // FIXME: Are we doing this correctly? Probably better to follow rustc more closely. - check_that!(ctxt.select_where_possible(&table.infer_ctxt).is_empty()); + check_that!(ctxt.try_evaluate_obligations(&table.infer_ctxt).is_empty()); } check_that!(table.unify(receiver_ty, &expected_receiver)); diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/fulfill.rs b/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/fulfill.rs index 34dff37972e7e..262da858d466a 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/fulfill.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/fulfill.rs @@ -54,7 +54,7 @@ struct ObligationStorage<'db> { /// Obligations which resulted in an overflow in fulfillment itself. /// /// We cannot eagerly return these as error so we instead store them here - /// to avoid recomputing them each time `select_where_possible` is called. + /// to avoid recomputing them each time `try_evaluate_obligations` is called. /// This also allows us to return the correct `FulfillmentError` for them. overflowed: Vec>, pending: PendingObligations<'db>, @@ -95,7 +95,7 @@ impl<'db> ObligationStorage<'db> { // IMPORTANT: we must not use solve any inference variables in the obligations // as this is all happening inside of a probe. We use a probe to make sure // we get all obligations involved in the overflow. We pretty much check: if - // we were to do another step of `select_where_possible`, which goals would + // we were to do another step of `try_evaluate_obligations`, which goals would // change. // FIXME: is merged, this can be removed. self.overflowed.extend( @@ -131,7 +131,7 @@ impl<'db> FulfillmentCtxt<'db> { infcx: &InferCtxt<'db>, obligation: PredicateObligation<'db>, ) { - // FIXME: See the comment in `select_where_possible()`. + // FIXME: See the comment in `try_evaluate_obligations()`. // assert_eq!(self.usable_in_snapshot, infcx.num_open_snapshots()); self.obligations.register(obligation, None); } @@ -141,7 +141,7 @@ impl<'db> FulfillmentCtxt<'db> { infcx: &InferCtxt<'db>, obligations: impl IntoIterator>, ) { - // FIXME: See the comment in `select_where_possible()`. + // FIXME: See the comment in `try_evaluate_obligations()`. // assert_eq!(self.usable_in_snapshot, infcx.num_open_snapshots()); obligations.into_iter().for_each(|obligation| self.obligations.register(obligation, None)); } @@ -158,7 +158,7 @@ impl<'db> FulfillmentCtxt<'db> { .collect() } - pub(crate) fn select_where_possible( + pub(crate) fn try_evaluate_obligations( &mut self, infcx: &InferCtxt<'db>, ) -> Vec> { @@ -223,11 +223,11 @@ impl<'db> FulfillmentCtxt<'db> { errors } - pub(crate) fn select_all_or_error( + pub(crate) fn evaluate_obligations_error_on_ambiguity( &mut self, infcx: &InferCtxt<'db>, ) -> Vec> { - let errors = self.select_where_possible(infcx); + let errors = self.try_evaluate_obligations(infcx); if !errors.is_empty() { return errors; } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/inspect.rs b/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/inspect.rs index bc19d51d23e32..0db4746721752 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/inspect.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/inspect.rs @@ -92,7 +92,7 @@ impl<'db> NormalizesToTermHack<'db> { let mut ocx = ObligationCtxt::new(infcx); ocx.eq(&ObligationCause::dummy(), param_env, self.term, self.unconstrained_term)?; f(&mut ocx); - let errors = ocx.select_all_or_error(); + let errors = ocx.evaluate_obligations_error_on_ambiguity(); if errors.is_empty() { Ok(Certainty::Yes) } else if errors.iter().all(|e| !matches!(e, NextSolverError::TrueError(_))) { diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/normalize.rs b/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/normalize.rs index 41cb4884404f1..2f241f8fecbe7 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/normalize.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/normalize.rs @@ -77,7 +77,7 @@ where stalled_coroutine_goals: vec![], }; let value = value.try_fold_with(&mut folder)?; - let errors = folder.fulfill_cx.select_all_or_error(at.infcx); + let errors = folder.fulfill_cx.evaluate_obligations_error_on_ambiguity(at.infcx); if errors.is_empty() { Ok((value, folder.stalled_coroutine_goals)) } else { Err(errors) } } @@ -138,7 +138,7 @@ impl<'db> NormalizationFolder<'_, 'db> { fn select_all_and_stall_coroutine_predicates( &mut self, ) -> Result<(), Vec>> { - let errors = self.fulfill_cx.select_where_possible(self.at.infcx); + let errors = self.fulfill_cx.try_evaluate_obligations(self.at.infcx); if !errors.is_empty() { return Err(errors); } diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/obligation_ctxt.rs b/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/obligation_ctxt.rs index 8e2dc0dec4ed3..e85574a8826ff 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/obligation_ctxt.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/obligation_ctxt.rs @@ -144,13 +144,13 @@ impl<'a, 'db> ObligationCtxt<'a, 'db> { } #[must_use] - pub fn select_where_possible(&mut self) -> Vec> { - self.engine.select_where_possible(self.infcx) + pub fn try_evaluate_obligations(&mut self) -> Vec> { + self.engine.try_evaluate_obligations(self.infcx) } #[must_use] - pub fn select_all_or_error(&mut self) -> Vec> { - self.engine.select_all_or_error(self.infcx) + pub fn evaluate_obligations_error_on_ambiguity(&mut self) -> Vec> { + self.engine.evaluate_obligations_error_on_ambiguity(self.infcx) } /// Returns the not-yet-processed and stalled obligations from the diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/structural_normalize.rs b/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/structural_normalize.rs index 18859d8b79707..00c3708358b92 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/structural_normalize.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/structural_normalize.rs @@ -47,7 +47,7 @@ impl<'db> At<'_, 'db> { ); fulfill_cx.register_predicate_obligation(self.infcx, obligation); - let errors = fulfill_cx.select_where_possible(self.infcx); + let errors = fulfill_cx.try_evaluate_obligations(self.infcx); if !errors.is_empty() { return Err(errors); } diff --git a/tests/ui/impl-trait/lazy_subtyping_of_opaques.rs b/tests/ui/impl-trait/lazy_subtyping_of_opaques.rs index 8fd1f35645a8a..8921090d98af5 100644 --- a/tests/ui/impl-trait/lazy_subtyping_of_opaques.rs +++ b/tests/ui/impl-trait/lazy_subtyping_of_opaques.rs @@ -13,7 +13,7 @@ fn foo() -> impl Default + Copy { // Make a tuple `(?x, ?y)` and equate it with `(impl Default, u32)`. // For us to try and prove a `Subtype(impl Default, u32)` obligation, // we have to instantiate both `?x` and `?y` without any - // `select_where_possible` calls inbetween. + // `try_evaluate_obligations` calls inbetween. let mut tup = &mut (x, y); let assign_tup = &mut (foo(), 1u32); tup = assign_tup;