1
1
use rustc_hir as hir;
2
- use rustc_infer:: traits:: TraitEngineExt as _;
3
2
use rustc_middle:: ty:: { self , Ty } ;
4
3
use rustc_span:: source_map:: Span ;
5
- use rustc_trait_selection:: infer:: canonical:: OriginalQueryValues ;
6
4
use rustc_trait_selection:: infer:: InferCtxt ;
5
+ use rustc_trait_selection:: traits:: query:: type_op:: { self , TypeOp , TypeOpOutput } ;
7
6
use rustc_trait_selection:: traits:: query:: NoSolution ;
8
7
use rustc_trait_selection:: traits:: { FulfillmentContext , ObligationCause , TraitEngine } ;
9
8
@@ -41,18 +40,18 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
41
40
/// - `ty`, the type that we are supposed to assume is WF.
42
41
/// - `span`, a span to use when normalizing, hopefully not important,
43
42
/// might be useful if a `bug!` occurs.
43
+ #[ instrument( level = "debug" , skip( self , param_env, body_id, span) ) ]
44
44
fn implied_outlives_bounds (
45
45
& self ,
46
46
param_env : ty:: ParamEnv < ' tcx > ,
47
47
body_id : hir:: HirId ,
48
48
ty : Ty < ' tcx > ,
49
49
span : Span ,
50
50
) -> Vec < OutlivesBound < ' tcx > > {
51
- debug ! ( "implied_outlives_bounds(ty = {:?})" , ty) ;
52
-
53
- let mut orig_values = OriginalQueryValues :: default ( ) ;
54
- let key = self . canonicalize_query ( param_env. and ( ty) , & mut orig_values) ;
55
- let result = match self . tcx . implied_outlives_bounds ( key) {
51
+ let result = param_env
52
+ . and ( type_op:: implied_outlives_bounds:: ImpliedOutlivesBounds { ty } )
53
+ . fully_perform ( self ) ;
54
+ let result = match result {
56
55
Ok ( r) => r,
57
56
Err ( NoSolution ) => {
58
57
self . tcx . sess . delay_span_bug (
@@ -62,32 +61,34 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
62
61
return vec ! [ ] ;
63
62
}
64
63
} ;
65
- assert ! ( result. value. is_proven( ) ) ;
66
64
67
- let result = self . instantiate_query_response_and_region_obligations (
68
- & ObligationCause :: misc ( span, body_id) ,
69
- param_env,
70
- & orig_values,
71
- result,
72
- ) ;
73
- debug ! ( "implied_outlives_bounds for {:?}: {:#?}" , ty, result) ;
74
- let Ok ( result) = result else {
75
- self . tcx . sess . delay_span_bug ( span, "implied_outlives_bounds failed to instantiate" ) ;
76
- return vec ! [ ] ;
77
- } ;
65
+ let TypeOpOutput { output, constraints, .. } = result;
78
66
79
- // Instantiation may have produced new inference variables and constraints on those
80
- // variables. Process these constraints.
81
- let mut fulfill_cx = FulfillmentContext :: new ( ) ;
82
- fulfill_cx. register_predicate_obligations ( self , result. obligations ) ;
83
- let errors = fulfill_cx. select_all_or_error ( self ) ;
84
- if !errors. is_empty ( ) {
85
- self . tcx . sess . delay_span_bug (
86
- span,
87
- "implied_outlives_bounds failed to solve obligations from instantiation" ,
88
- ) ;
89
- }
67
+ if let Some ( constraints) = constraints {
68
+ // Instantiation may have produced new inference variables and constraints on those
69
+ // variables. Process these constraints.
70
+ let mut fulfill_cx = FulfillmentContext :: new ( ) ;
71
+ let cause = ObligationCause :: misc ( span, body_id) ;
72
+ for & constraint in & constraints. outlives {
73
+ let obligation = self . query_outlives_constraint_to_obligation (
74
+ constraint,
75
+ cause. clone ( ) ,
76
+ param_env,
77
+ ) ;
78
+ fulfill_cx. register_predicate_obligation ( self , obligation) ;
79
+ }
80
+ if !constraints. member_constraints . is_empty ( ) {
81
+ span_bug ! ( span, "{:#?}" , constraints. member_constraints) ;
82
+ }
83
+ let errors = fulfill_cx. select_all_or_error ( self ) ;
84
+ if !errors. is_empty ( ) {
85
+ self . tcx . sess . delay_span_bug (
86
+ span,
87
+ "implied_outlives_bounds failed to solve obligations from instantiation" ,
88
+ ) ;
89
+ }
90
+ } ;
90
91
91
- result . value
92
+ output
92
93
}
93
94
}
0 commit comments