8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use astconv:: AstConv ;
12
-
13
11
use super :: { FnCtxt , PlaceOp , Needs } ;
14
12
use super :: method:: MethodCallee ;
15
13
16
- use rustc:: infer:: InferOk ;
14
+ use rustc:: infer:: { InferCtxt , InferOk } ;
17
15
use rustc:: session:: DiagnosticMessageId ;
18
16
use rustc:: traits:: { self , TraitEngine } ;
19
17
use rustc:: ty:: { self , Ty , TraitRef } ;
20
18
use rustc:: ty:: { ToPredicate , TypeFoldable } ;
21
19
use rustc:: ty:: adjustment:: { Adjustment , Adjust , OverloadedDeref } ;
22
20
23
21
use syntax_pos:: Span ;
24
- use syntax:: ast:: Ident ;
22
+ use syntax:: ast:: { NodeId , Ident } ;
25
23
26
24
use std:: iter;
27
25
@@ -32,7 +30,9 @@ enum AutoderefKind {
32
30
}
33
31
34
32
pub struct Autoderef < ' a , ' gcx : ' tcx , ' tcx : ' a > {
35
- fcx : & ' a FnCtxt < ' a , ' gcx , ' tcx > ,
33
+ infcx : & ' a InferCtxt < ' a , ' gcx , ' tcx > ,
34
+ body_id : NodeId ,
35
+ param_env : ty:: ParamEnv < ' tcx > ,
36
36
steps : Vec < ( Ty < ' tcx > , AutoderefKind ) > ,
37
37
cur_ty : Ty < ' tcx > ,
38
38
obligations : Vec < traits:: PredicateObligation < ' tcx > > ,
@@ -45,7 +45,7 @@ impl<'a, 'gcx, 'tcx> Iterator for Autoderef<'a, 'gcx, 'tcx> {
45
45
type Item = ( Ty < ' tcx > , usize ) ;
46
46
47
47
fn next ( & mut self ) -> Option < Self :: Item > {
48
- let tcx = self . fcx . tcx ;
48
+ let tcx = self . infcx . tcx ;
49
49
50
50
debug ! ( "autoderef: steps={:?}, cur_ty={:?}" ,
51
51
self . steps,
@@ -110,35 +110,35 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> {
110
110
fn overloaded_deref_ty ( & mut self , ty : Ty < ' tcx > ) -> Option < Ty < ' tcx > > {
111
111
debug ! ( "overloaded_deref_ty({:?})" , ty) ;
112
112
113
- let tcx = self . fcx . tcx ( ) ;
113
+ let tcx = self . infcx . tcx ;
114
114
115
115
// <cur_ty as Deref>
116
116
let trait_ref = TraitRef {
117
117
def_id : tcx. lang_items ( ) . deref_trait ( ) ?,
118
118
substs : tcx. mk_substs_trait ( self . cur_ty , & [ ] ) ,
119
119
} ;
120
120
121
- let cause = traits:: ObligationCause :: misc ( self . span , self . fcx . body_id ) ;
121
+ let cause = traits:: ObligationCause :: misc ( self . span , self . body_id ) ;
122
122
123
123
let obligation = traits:: Obligation :: new ( cause. clone ( ) ,
124
- self . fcx . param_env ,
124
+ self . param_env ,
125
125
trait_ref. to_predicate ( ) ) ;
126
- if !self . fcx . predicate_may_hold ( & obligation) {
126
+ if !self . infcx . predicate_may_hold ( & obligation) {
127
127
debug ! ( "overloaded_deref_ty: cannot match obligation" ) ;
128
128
return None ;
129
129
}
130
130
131
131
let mut fulfillcx = traits:: FulfillmentContext :: new_in_snapshot ( ) ;
132
132
let normalized_ty = fulfillcx. normalize_projection_type (
133
- & self . fcx ,
134
- self . fcx . param_env ,
133
+ & self . infcx ,
134
+ self . param_env ,
135
135
ty:: ProjectionTy :: from_ref_and_name (
136
136
tcx,
137
137
trait_ref,
138
138
Ident :: from_str ( "Target" ) ,
139
139
) ,
140
140
cause) ;
141
- if let Err ( e) = fulfillcx. select_where_possible ( & self . fcx ) {
141
+ if let Err ( e) = fulfillcx. select_where_possible ( & self . infcx ) {
142
142
// This shouldn't happen, except for evaluate/fulfill mismatches,
143
143
// but that's not a reason for an ICE (`predicate_may_hold` is conservative
144
144
// by design).
@@ -151,39 +151,39 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> {
151
151
ty, normalized_ty, obligations) ;
152
152
self . obligations . extend ( obligations) ;
153
153
154
- Some ( self . fcx . resolve_type_vars_if_possible ( & normalized_ty) )
154
+ Some ( self . infcx . resolve_type_vars_if_possible ( & normalized_ty) )
155
155
}
156
156
157
157
/// Returns the final type, generating an error if it is an
158
158
/// unresolved inference variable.
159
- pub fn unambiguous_final_ty ( & self ) -> Ty < ' tcx > {
160
- self . fcx . structurally_resolved_type ( self . span , self . cur_ty )
159
+ pub fn unambiguous_final_ty ( & self , fcx : & FnCtxt < ' a , ' gcx , ' tcx > ) -> Ty < ' tcx > {
160
+ fcx. structurally_resolved_type ( self . span , self . cur_ty )
161
161
}
162
162
163
163
/// Returns the final type we ended up with, which may well be an
164
164
/// inference variable (we will resolve it first, if possible).
165
165
pub fn maybe_ambiguous_final_ty ( & self ) -> Ty < ' tcx > {
166
- self . fcx . resolve_type_vars_if_possible ( & self . cur_ty )
166
+ self . infcx . resolve_type_vars_if_possible ( & self . cur_ty )
167
167
}
168
168
169
169
pub fn step_count ( & self ) -> usize {
170
170
self . steps . len ( )
171
171
}
172
172
173
173
/// Returns the adjustment steps.
174
- pub fn adjust_steps ( & self , needs : Needs )
174
+ pub fn adjust_steps ( & self , fcx : & FnCtxt < ' a , ' gcx , ' tcx > , needs : Needs )
175
175
-> Vec < Adjustment < ' tcx > > {
176
- self . fcx . register_infer_ok_obligations ( self . adjust_steps_as_infer_ok ( needs) )
176
+ fcx. register_infer_ok_obligations ( self . adjust_steps_as_infer_ok ( fcx , needs) )
177
177
}
178
178
179
- pub fn adjust_steps_as_infer_ok ( & self , needs : Needs )
179
+ pub fn adjust_steps_as_infer_ok ( & self , fcx : & FnCtxt < ' a , ' gcx , ' tcx > , needs : Needs )
180
180
-> InferOk < ' tcx , Vec < Adjustment < ' tcx > > > {
181
181
let mut obligations = vec ! [ ] ;
182
182
let targets = self . steps . iter ( ) . skip ( 1 ) . map ( |& ( ty, _) | ty)
183
183
. chain ( iter:: once ( self . cur_ty ) ) ;
184
184
let steps: Vec < _ > = self . steps . iter ( ) . map ( |& ( source, kind) | {
185
185
if let AutoderefKind :: Overloaded = kind {
186
- self . fcx . try_overloaded_deref ( self . span , source, needs)
186
+ fcx. try_overloaded_deref ( self . span , source, needs)
187
187
. and_then ( |InferOk { value : method, obligations : o } | {
188
188
obligations. extend ( o) ;
189
189
if let ty:: Ref ( region, _, mutbl) = method. sig . output ( ) . sty {
@@ -220,8 +220,7 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> {
220
220
self
221
221
}
222
222
223
- pub fn finalize ( self ) {
224
- let fcx = self . fcx ;
223
+ pub fn finalize ( self , fcx : & FnCtxt < ' a , ' gcx , ' tcx > ) {
225
224
fcx. register_predicates ( self . into_obligations ( ) ) ;
226
225
}
227
226
@@ -233,7 +232,9 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> {
233
232
impl < ' a , ' gcx , ' tcx > FnCtxt < ' a , ' gcx , ' tcx > {
234
233
pub fn autoderef ( & ' a self , span : Span , base_ty : Ty < ' tcx > ) -> Autoderef < ' a , ' gcx , ' tcx > {
235
234
Autoderef {
236
- fcx : self ,
235
+ infcx : & self . infcx ,
236
+ body_id : self . body_id ,
237
+ param_env : self . param_env ,
237
238
steps : vec ! [ ] ,
238
239
cur_ty : self . resolve_type_vars_if_possible ( & base_ty) ,
239
240
obligations : vec ! [ ] ,
0 commit comments