6
6
7
7
use crate :: infer:: outlives:: env:: OutlivesEnvironment ;
8
8
use crate :: infer:: InferOk ;
9
- use crate :: regions:: InferCtxtRegionExt ;
10
9
use 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} ;
13
11
use crate :: traits:: select:: IntercrateAmbiguityCause ;
14
- use crate :: traits:: structural_normalize:: StructurallyNormalizeExt ;
15
12
use crate :: traits:: NormalizeExt ;
16
13
use crate :: traits:: SkipLeakCheck ;
17
14
use crate :: traits:: {
@@ -22,7 +19,7 @@ use rustc_errors::{Diag, EmissionGuarantee};
22
19
use rustc_hir:: def:: DefKind ;
23
20
use rustc_hir:: def_id:: DefId ;
24
21
use rustc_infer:: infer:: { DefineOpaqueTypes , InferCtxt , TyCtxtInferExt } ;
25
- use rustc_infer:: traits:: { util, FulfillmentErrorCode , TraitEngine , TraitEngineExt } ;
22
+ use rustc_infer:: traits:: { util, FulfillmentErrorCode } ;
26
23
use rustc_middle:: traits:: query:: NoSolution ;
27
24
use rustc_middle:: traits:: solve:: { CandidateSource , Certainty , Goal } ;
28
25
use rustc_middle:: traits:: specialization_graph:: OverlapMode ;
@@ -35,6 +32,7 @@ use std::fmt::Debug;
35
32
use std:: ops:: ControlFlow ;
36
33
37
34
use super :: error_reporting:: suggest_new_overflow_limit;
35
+ use super :: ObligationCtxt ;
38
36
39
37
/// Whether we do the orphan check relative to this crate or to some remote crate.
40
38
#[ derive( Copy , Clone , Debug ) ]
@@ -361,23 +359,27 @@ fn impl_intersection_has_impossible_obligation<'a, 'cx, 'tcx>(
361
359
let infcx = selcx. infcx ;
362
360
363
361
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 ( ) ;
367
365
// We only care about the obligations that are *definitely* true errors.
368
366
// 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
+
370
370
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
+ }
381
383
} else {
382
384
IntersectionHasImpossibleObligations :: Yes
383
385
}
@@ -589,22 +591,22 @@ fn try_prove_negated_where_clause<'tcx>(
589
591
// Without this, we over-eagerly register coherence ambiguity candidates when
590
592
// impl candidates do exist.
591
593
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 ( ) {
599
602
return false ;
600
603
}
601
604
602
605
// FIXME: We could use the assumed_wf_types from both impls, I think,
603
606
// if that wasn't implemented just for LocalDefId, and we'd need to do
604
607
// the normalization ourselves since this is totally fallible...
605
608
let outlives_env = OutlivesEnvironment :: new ( param_env) ;
606
-
607
- let errors = infcx. resolve_regions ( & outlives_env) ;
609
+ let errors = ocx. resolve_regions ( & outlives_env) ;
608
610
if !errors. is_empty ( ) {
609
611
return false ;
610
612
}
@@ -1129,22 +1131,17 @@ impl<'a, 'tcx> ProofTreeVisitor<'tcx> for AmbiguityCausesVisitor<'a, 'tcx> {
1129
1131
result : Ok ( _) ,
1130
1132
} = cand. kind ( )
1131
1133
{
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 > | {
1134
1135
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 ( ( ) ) ;
1144
1142
}
1145
- } else {
1146
- Ok ( ty)
1147
1143
}
1144
+ Ok ( ty)
1148
1145
} ;
1149
1146
1150
1147
infcx. probe ( |_| {
0 commit comments