66
77use crate :: infer:: outlives:: env:: OutlivesEnvironment ;
88use crate :: infer:: InferOk ;
9- use crate :: regions:: InferCtxtRegionExt ;
109use crate :: solve:: inspect:: { InspectGoal , ProofTreeInferCtxtExt , ProofTreeVisitor } ;
11- use crate :: solve:: { deeply_normalize_for_diagnostics, inspect, FulfillmentCtxt } ;
12- use crate :: traits:: engine:: TraitEngineExt as _;
10+ use crate :: solve:: { deeply_normalize_for_diagnostics, inspect} ;
1311use crate :: traits:: select:: IntercrateAmbiguityCause ;
14- use crate :: traits:: structural_normalize:: StructurallyNormalizeExt ;
1512use crate :: traits:: NormalizeExt ;
1613use crate :: traits:: SkipLeakCheck ;
1714use crate :: traits:: {
@@ -22,7 +19,7 @@ use rustc_errors::{Diag, EmissionGuarantee};
2219use rustc_hir:: def:: DefKind ;
2320use rustc_hir:: def_id:: DefId ;
2421use rustc_infer:: infer:: { DefineOpaqueTypes , InferCtxt , TyCtxtInferExt } ;
25- use rustc_infer:: traits:: { util, FulfillmentErrorCode , TraitEngine , TraitEngineExt } ;
22+ use rustc_infer:: traits:: { util, FulfillmentErrorCode } ;
2623use rustc_middle:: traits:: query:: NoSolution ;
2724use rustc_middle:: traits:: solve:: { CandidateSource , Certainty , Goal } ;
2825use rustc_middle:: traits:: specialization_graph:: OverlapMode ;
@@ -35,6 +32,7 @@ use std::fmt::Debug;
3532use std:: ops:: ControlFlow ;
3633
3734use super :: error_reporting:: suggest_new_overflow_limit;
35+ use super :: ObligationCtxt ;
3836
3937/// Whether we do the orphan check relative to this crate or to some remote crate.
4038#[ derive( Copy , Clone , Debug ) ]
@@ -361,23 +359,27 @@ fn impl_intersection_has_impossible_obligation<'a, 'cx, 'tcx>(
361359 let infcx = selcx. infcx ;
362360
363361 if infcx. next_trait_solver ( ) {
364- let mut fulfill_cx = FulfillmentCtxt :: new ( infcx) ;
365- fulfill_cx . register_predicate_obligations ( infcx , obligations. iter ( ) . cloned ( ) ) ;
366-
362+ let ocx = ObligationCtxt :: new ( infcx) ;
363+ ocx . register_obligations ( obligations. iter ( ) . cloned ( ) ) ;
364+ let errors_and_ambiguities = ocx . select_all_or_error ( ) ;
367365 // We only care about the obligations that are *definitely* true errors.
368366 // Ambiguities do not prove the disjointness of two impls.
369- let errors = fulfill_cx. select_where_possible ( infcx) ;
367+ let ( errors, ambiguities) : ( Vec < _ > , Vec < _ > ) =
368+ errors_and_ambiguities. into_iter ( ) . partition ( |error| error. is_true_error ( ) ) ;
369+
370370 if errors. is_empty ( ) {
371- let overflow_errors = fulfill_cx. collect_remaining_errors ( infcx) ;
372- let overflowing_predicates = overflow_errors
373- . into_iter ( )
374- . filter ( |e| match e. code {
375- FulfillmentErrorCode :: Ambiguity { overflow : Some ( true ) } => true ,
376- _ => false ,
377- } )
378- . map ( |e| infcx. resolve_vars_if_possible ( e. obligation . predicate ) )
379- . collect ( ) ;
380- IntersectionHasImpossibleObligations :: No { overflowing_predicates }
371+ IntersectionHasImpossibleObligations :: No {
372+ overflowing_predicates : ambiguities
373+ . into_iter ( )
374+ . filter ( |error| {
375+ matches ! (
376+ error. code,
377+ FulfillmentErrorCode :: Ambiguity { overflow: Some ( true ) }
378+ )
379+ } )
380+ . map ( |e| infcx. resolve_vars_if_possible ( e. obligation . predicate ) )
381+ . collect ( ) ,
382+ }
381383 } else {
382384 IntersectionHasImpossibleObligations :: Yes
383385 }
@@ -589,22 +591,22 @@ fn try_prove_negated_where_clause<'tcx>(
589591 // Without this, we over-eagerly register coherence ambiguity candidates when
590592 // impl candidates do exist.
591593 let ref infcx = root_infcx. fork_with_intercrate ( false ) ;
592- let mut fulfill_cx = FulfillmentCtxt :: new ( infcx) ;
593-
594- fulfill_cx. register_predicate_obligation (
595- infcx,
596- Obligation :: new ( infcx. tcx , ObligationCause :: dummy ( ) , param_env, negative_predicate) ,
597- ) ;
598- if !fulfill_cx. select_all_or_error ( infcx) . is_empty ( ) {
594+ let ocx = ObligationCtxt :: new ( infcx) ;
595+ ocx. register_obligation ( Obligation :: new (
596+ infcx. tcx ,
597+ ObligationCause :: dummy ( ) ,
598+ param_env,
599+ negative_predicate,
600+ ) ) ;
601+ if !ocx. select_all_or_error ( ) . is_empty ( ) {
599602 return false ;
600603 }
601604
602605 // FIXME: We could use the assumed_wf_types from both impls, I think,
603606 // if that wasn't implemented just for LocalDefId, and we'd need to do
604607 // the normalization ourselves since this is totally fallible...
605608 let outlives_env = OutlivesEnvironment :: new ( param_env) ;
606-
607- let errors = infcx. resolve_regions ( & outlives_env) ;
609+ let errors = ocx. resolve_regions ( & outlives_env) ;
608610 if !errors. is_empty ( ) {
609611 return false ;
610612 }
@@ -1129,22 +1131,17 @@ impl<'a, 'tcx> ProofTreeVisitor<'tcx> for AmbiguityCausesVisitor<'a, 'tcx> {
11291131 result : Ok ( _) ,
11301132 } = cand. kind ( )
11311133 {
1132- let lazily_normalize_ty = |ty : Ty < ' tcx > | {
1133- let mut fulfill_cx = <dyn TraitEngine < ' tcx > >:: new ( infcx) ;
1134+ let lazily_normalize_ty = |mut ty : Ty < ' tcx > | {
11341135 if matches ! ( ty. kind( ) , ty:: Alias ( ..) ) {
1135- // FIXME(-Znext-solver=coherence): we currently don't
1136- // normalize opaque types here, resulting in diverging behavior
1137- // for TAITs.
1138- match infcx
1139- . at ( & ObligationCause :: dummy ( ) , param_env)
1140- . structurally_normalize ( ty, & mut * fulfill_cx)
1141- {
1142- Ok ( ty) => Ok ( ty) ,
1143- Err ( _errs) => Err ( ( ) ) ,
1136+ let ocx = ObligationCtxt :: new ( infcx) ;
1137+ ty = ocx
1138+ . structurally_normalize ( & ObligationCause :: dummy ( ) , param_env, ty)
1139+ . map_err ( |_| ( ) ) ?;
1140+ if !ocx. select_where_possible ( ) . is_empty ( ) {
1141+ return Err ( ( ) ) ;
11441142 }
1145- } else {
1146- Ok ( ty)
11471143 }
1144+ Ok ( ty)
11481145 } ;
11491146
11501147 infcx. probe ( |_| {
0 commit comments