diff --git a/compiler/rustc_trait_selection/src/solve/fulfill.rs b/compiler/rustc_trait_selection/src/solve/fulfill.rs index 7d3c0a4a6c1f1..5e834c8c4059d 100644 --- a/compiler/rustc_trait_selection/src/solve/fulfill.rs +++ b/compiler/rustc_trait_selection/src/solve/fulfill.rs @@ -18,7 +18,7 @@ use self::derive_errors::*; use super::Certainty; use super::delegate::SolverDelegate; use crate::error_reporting::InferCtxtErrorExt; -use crate::traits::{FulfillmentError, FulfillmentErrorCode, ScrubbedTraitError}; +use crate::traits::{FulfillmentError, ScrubbedTraitError}; mod derive_errors; @@ -157,8 +157,7 @@ where // the other case. TraitErrors::NoErrors } else { - let errors = collect_remaining_errors_impl(self, infcx); - TraitErrors::from_iter(errors.into_iter()) + TraitErrors::HasErrors(collect_remaining_errors_impl(self, infcx)) } } @@ -367,26 +366,14 @@ where cx.obligations .pending .drain(..) - .filter_map(|(obligation, _)| { - try_ambiguity_error_for_stalled(infcx, obligation).map(NextSolverError::Ambiguity) - }) + .map(|(obligation, _)| NextSolverError::Ambiguity(obligation)) .map(|e| E::from_solver_error(infcx, e)) .collect() } -// We evaluate stalled obligations while collecting remaining errors because a -// previously ambiguous goal may have become successful. In that case we emit a -// delayed bug instead of producing a fulfillment error. Store the diagnostic -// information here so error conversion does not reevaluate the goal. -pub struct NextSolverAmbiguityError<'tcx> { - root_obligation: PredicateObligation<'tcx>, - code: FulfillmentErrorCode<'tcx>, - refine_obligation: bool, -} - pub enum NextSolverError<'tcx> { TrueError(PredicateObligation<'tcx>), - Ambiguity(NextSolverAmbiguityError<'tcx>), + Ambiguity(PredicateObligation<'tcx>), } impl<'tcx> FromSolverError<'tcx, NextSolverError<'tcx>> for FulfillmentError<'tcx> { @@ -395,8 +382,8 @@ impl<'tcx> FromSolverError<'tcx, NextSolverError<'tcx>> for FulfillmentError<'tc NextSolverError::TrueError(obligation) => { fulfillment_error_for_no_solution(infcx, obligation) } - NextSolverError::Ambiguity(ambiguity) => { - fulfillment_error_for_stalled(infcx, ambiguity) + NextSolverError::Ambiguity(obligation) => { + fulfillment_error_for_stalled(infcx, obligation) } } } diff --git a/compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs b/compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs index 5ccd7ff7ef55b..7df3fa41a1df2 100644 --- a/compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs +++ b/compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs @@ -14,7 +14,6 @@ use rustc_next_trait_solver::solve::{GoalEvaluation, MaybeInfo, SolverDelegateEv use rustc_span::{bug, span_bug}; use tracing::{instrument, trace}; -use super::NextSolverAmbiguityError; use crate::solve::delegate::SolverDelegate; use crate::solve::inspect::{self, InferCtxtProofTreeExt, ProofTreeVisitor}; use crate::solve::{Certainty, deeply_normalize_for_diagnostics}; @@ -84,25 +83,10 @@ pub(super) fn fulfillment_error_for_no_solution<'tcx>( } pub(super) fn fulfillment_error_for_stalled<'tcx>( - infcx: &InferCtxt<'tcx>, - ambiguity: NextSolverAmbiguityError<'tcx>, -) -> FulfillmentError<'tcx> { - let NextSolverAmbiguityError { root_obligation, code, refine_obligation } = ambiguity; - - let obligation = if refine_obligation { - find_best_leaf_obligation(infcx, &root_obligation, true) - } else { - root_obligation.clone() - }; - - FulfillmentError { obligation, code, root_obligation } -} - -pub(super) fn try_ambiguity_error_for_stalled<'tcx>( infcx: &InferCtxt<'tcx>, root_obligation: PredicateObligation<'tcx>, -) -> Option> { - let evaluation = infcx.probe(|_| { +) -> FulfillmentError<'tcx> { + let (code, refine_obligation) = infcx.probe(|_| { match <&SolverDelegate<'tcx>>::from(infcx).evaluate_root_goal( root_obligation.as_goal(), root_obligation.cause.span, @@ -116,7 +100,7 @@ pub(super) fn try_ambiguity_error_for_stalled<'tcx>( stalled_on_coroutines: _, }), .. - }) => Some((FulfillmentErrorCode::Ambiguity { overflow: None }, true)), + }) => (FulfillmentErrorCode::Ambiguity { overflow: None }, true), Ok(GoalEvaluation { certainty: Certainty::Maybe(MaybeInfo { @@ -126,7 +110,7 @@ pub(super) fn try_ambiguity_error_for_stalled<'tcx>( stalled_on_coroutines: _, }), .. - }) => Some(( + }) => ( FulfillmentErrorCode::Ambiguity { overflow: Some(suggest_increasing_limit) }, // Don't look into overflows because we treat overflows weirdly anyways. // We discard the inference constraints from overflowing goals, so @@ -135,17 +119,13 @@ pub(super) fn try_ambiguity_error_for_stalled<'tcx>( // // FIXME: We should probably just look into overflows here. false, - )), + ), Ok(GoalEvaluation { certainty: Certainty::Yes, .. }) => { - infcx.dcx().span_delayed_bug( - root_obligation.cause.span, - format!( - "did not expect successful goal when collecting ambiguity errors for `{:?}`", - infcx.deeply_resolve_ignoring_regions(root_obligation.predicate), - ), - ); - None - }, + // FIXME: We should ICE here. See the following links for details + // - + // - + (FulfillmentErrorCode::Ambiguity { overflow: None }, false) + } Err(_) => { span_bug!( root_obligation.cause.span, @@ -156,9 +136,15 @@ pub(super) fn try_ambiguity_error_for_stalled<'tcx>( } }); - let (code, refine_obligation) = evaluation?; - - Some(NextSolverAmbiguityError { root_obligation, code, refine_obligation }) + FulfillmentError { + obligation: if refine_obligation { + find_best_leaf_obligation(infcx, &root_obligation, true) + } else { + root_obligation.clone() + }, + code, + root_obligation, + } } #[instrument(level = "debug", skip(infcx), ret)] diff --git a/tests/rustdoc-json/impls/blanket-ambig-on-nonrigid-assoc-next-solver.rs b/tests/rustdoc-json/impls/blanket-ambig-on-nonrigid-assoc-next-solver.rs new file mode 100644 index 0000000000000..8f3af90a2598e --- /dev/null +++ b/tests/rustdoc-json/impls/blanket-ambig-on-nonrigid-assoc-next-solver.rs @@ -0,0 +1,23 @@ +//@ compile-flags: -Znext-solver + +// Regression test for + +pub trait Service { + type Future; +} + +pub trait ZebraService: Service {} + +impl ZebraService for MaybeVerify where + MaybeVerify: Service +{ +} + +pub struct Verifier; + +impl Service<()> for Verifier { + type Future = &'static (); +} + +//@ set blanket = "$.index[?(@.inner.impl.blanket_impl.generic=='MaybeVerify')].id" +//@ has "$.index[?(@.name=='Verifier')].inner.struct.impls[*]" $blanket