@@ -57,6 +57,10 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
57
57
self . result . map ( |c| c. value . certainty )
58
58
}
59
59
60
+ pub fn goal ( & self ) -> & ' a InspectGoal < ' a , ' tcx > {
61
+ self . goal
62
+ }
63
+
60
64
/// Certainty passed into `evaluate_added_goals_and_make_canonical_response`.
61
65
///
62
66
/// If this certainty is `Yes`, then we must be confident that the candidate
@@ -74,46 +78,55 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
74
78
/// the state of the `infcx`.
75
79
pub fn visit_nested_no_probe < V : ProofTreeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> V :: Result {
76
80
if self . goal . depth < visitor. config ( ) . max_depth {
77
- let infcx = self . goal . infcx ;
78
- let param_env = self . goal . goal . param_env ;
79
- let mut orig_values = self . goal . orig_values . to_vec ( ) ;
80
- let mut instantiated_goals = vec ! [ ] ;
81
- for goal in & self . nested_goals {
82
- let goal = canonical:: instantiate_canonical_state (
81
+ for goal in self . instantiate_nested_goals ( visitor. span ( ) ) {
82
+ try_visit ! ( visitor. visit_goal( & goal) ) ;
83
+ }
84
+ }
85
+
86
+ V :: Result :: output ( )
87
+ }
88
+
89
+ /// Instantiate the nested goals for the candidate without rolling back their
90
+ /// inference constraints. This function modifies the state of the `infcx`.
91
+ pub fn instantiate_nested_goals ( & self , span : Span ) -> Vec < InspectGoal < ' a , ' tcx > > {
92
+ let infcx = self . goal . infcx ;
93
+ let param_env = self . goal . goal . param_env ;
94
+ let mut orig_values = self . goal . orig_values . to_vec ( ) ;
95
+ let instantiated_goals: Vec < _ > = self
96
+ . nested_goals
97
+ . iter ( )
98
+ . map ( |goal| {
99
+ canonical:: instantiate_canonical_state (
83
100
infcx,
84
- visitor . span ( ) ,
101
+ span,
85
102
param_env,
86
103
& mut orig_values,
87
104
* goal,
88
- ) ;
89
- instantiated_goals . push ( goal ) ;
90
- }
105
+ )
106
+ } )
107
+ . collect ( ) ;
91
108
92
- let ( ) = canonical:: instantiate_canonical_state (
93
- infcx,
94
- visitor . span ( ) ,
95
- param_env,
96
- & mut orig_values,
97
- self . final_state ,
98
- ) ;
109
+ let ( ) = canonical:: instantiate_canonical_state (
110
+ infcx,
111
+ span,
112
+ param_env,
113
+ & mut orig_values,
114
+ self . final_state ,
115
+ ) ;
99
116
100
- for & goal in & instantiated_goals {
117
+ instantiated_goals
118
+ . into_iter ( )
119
+ . map ( |goal| {
101
120
let proof_tree = match goal. predicate . kind ( ) . no_bound_vars ( ) {
102
121
Some ( ty:: PredicateKind :: NormalizesTo ( ty:: NormalizesTo { alias, term } ) ) => {
103
122
let unconstrained_term = match term. unpack ( ) {
104
123
ty:: TermKind :: Ty ( _) => infcx
105
- . next_ty_var ( TypeVariableOrigin {
106
- param_def_id : None ,
107
- span : visitor. span ( ) ,
108
- } )
124
+ . next_ty_var ( TypeVariableOrigin { param_def_id : None , span } )
109
125
. into ( ) ,
110
126
ty:: TermKind :: Const ( ct) => infcx
111
127
. next_const_var (
112
128
ct. ty ( ) ,
113
- ConstVariableOrigin {
114
- param_def_id : None ,
115
- span : visitor. span ( ) ,
116
- } ,
129
+ ConstVariableOrigin { param_def_id : None , span } ,
117
130
)
118
131
. into ( ) ,
119
132
} ;
@@ -129,22 +142,16 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
129
142
} )
130
143
. 1 ;
131
144
let InferOk { value : ( ) , obligations : _ } = infcx
132
- . at ( & ObligationCause :: dummy ( ) , param_env)
145
+ . at ( & ObligationCause :: dummy_with_span ( span ) , param_env)
133
146
. eq ( DefineOpaqueTypes :: Yes , term, unconstrained_term)
134
147
. unwrap ( ) ;
135
148
proof_tree
136
149
}
137
150
_ => infcx. evaluate_root_goal ( goal, GenerateProofTree :: Yes ) . 1 ,
138
151
} ;
139
- try_visit ! ( visitor. visit_goal( & InspectGoal :: new(
140
- infcx,
141
- self . goal. depth + 1 ,
142
- proof_tree. unwrap( ) ,
143
- ) ) ) ;
144
- }
145
- }
146
-
147
- V :: Result :: output ( )
152
+ InspectGoal :: new ( infcx, self . goal . depth + 1 , proof_tree. unwrap ( ) )
153
+ } )
154
+ . collect ( )
148
155
}
149
156
150
157
/// Visit all nested goals of this candidate, rolling back
0 commit comments