88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11- use astconv:: AstConv ;
12-
1311use super :: { FnCtxt , PlaceOp , Needs } ;
1412use super :: method:: MethodCallee ;
1513
16- use rustc:: infer:: InferOk ;
14+ use rustc:: infer:: { InferCtxt , InferOk } ;
1715use rustc:: session:: DiagnosticMessageId ;
1816use rustc:: traits:: { self , TraitEngine } ;
1917use rustc:: ty:: { self , Ty , TraitRef } ;
2018use rustc:: ty:: { ToPredicate , TypeFoldable } ;
2119use rustc:: ty:: adjustment:: { Adjustment , Adjust , OverloadedDeref } ;
2220
2321use syntax_pos:: Span ;
24- use syntax:: ast:: Ident ;
22+ use syntax:: ast:: { NodeId , Ident } ;
2523
2624use std:: iter;
2725
@@ -32,7 +30,9 @@ enum AutoderefKind {
3230}
3331
3432pub 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 > ,
3636 steps : Vec < ( Ty < ' tcx > , AutoderefKind ) > ,
3737 cur_ty : Ty < ' tcx > ,
3838 obligations : Vec < traits:: PredicateObligation < ' tcx > > ,
@@ -45,7 +45,7 @@ impl<'a, 'gcx, 'tcx> Iterator for Autoderef<'a, 'gcx, 'tcx> {
4545 type Item = ( Ty < ' tcx > , usize ) ;
4646
4747 fn next ( & mut self ) -> Option < Self :: Item > {
48- let tcx = self . fcx . tcx ;
48+ let tcx = self . infcx . tcx ;
4949
5050 debug ! ( "autoderef: steps={:?}, cur_ty={:?}" ,
5151 self . steps,
@@ -110,35 +110,35 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> {
110110 fn overloaded_deref_ty ( & mut self , ty : Ty < ' tcx > ) -> Option < Ty < ' tcx > > {
111111 debug ! ( "overloaded_deref_ty({:?})" , ty) ;
112112
113- let tcx = self . fcx . tcx ( ) ;
113+ let tcx = self . infcx . tcx ;
114114
115115 // <cur_ty as Deref>
116116 let trait_ref = TraitRef {
117117 def_id : tcx. lang_items ( ) . deref_trait ( ) ?,
118118 substs : tcx. mk_substs_trait ( self . cur_ty , & [ ] ) ,
119119 } ;
120120
121- let cause = traits:: ObligationCause :: misc ( self . span , self . fcx . body_id ) ;
121+ let cause = traits:: ObligationCause :: misc ( self . span , self . body_id ) ;
122122
123123 let obligation = traits:: Obligation :: new ( cause. clone ( ) ,
124- self . fcx . param_env ,
124+ self . param_env ,
125125 trait_ref. to_predicate ( ) ) ;
126- if !self . fcx . predicate_may_hold ( & obligation) {
126+ if !self . infcx . predicate_may_hold ( & obligation) {
127127 debug ! ( "overloaded_deref_ty: cannot match obligation" ) ;
128128 return None ;
129129 }
130130
131131 let mut fulfillcx = traits:: FulfillmentContext :: new_in_snapshot ( ) ;
132132 let normalized_ty = fulfillcx. normalize_projection_type (
133- & self . fcx ,
134- self . fcx . param_env ,
133+ & self . infcx ,
134+ self . param_env ,
135135 ty:: ProjectionTy :: from_ref_and_name (
136136 tcx,
137137 trait_ref,
138138 Ident :: from_str ( "Target" ) ,
139139 ) ,
140140 cause) ;
141- if let Err ( e) = fulfillcx. select_where_possible ( & self . fcx ) {
141+ if let Err ( e) = fulfillcx. select_where_possible ( & self . infcx ) {
142142 // This shouldn't happen, except for evaluate/fulfill mismatches,
143143 // but that's not a reason for an ICE (`predicate_may_hold` is conservative
144144 // by design).
@@ -151,39 +151,39 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> {
151151 ty, normalized_ty, obligations) ;
152152 self . obligations . extend ( obligations) ;
153153
154- Some ( self . fcx . resolve_type_vars_if_possible ( & normalized_ty) )
154+ Some ( self . infcx . resolve_type_vars_if_possible ( & normalized_ty) )
155155 }
156156
157157 /// Returns the final type, generating an error if it is an
158158 /// 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 )
161161 }
162162
163163 /// Returns the final type we ended up with, which may well be an
164164 /// inference variable (we will resolve it first, if possible).
165165 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 )
167167 }
168168
169169 pub fn step_count ( & self ) -> usize {
170170 self . steps . len ( )
171171 }
172172
173173 /// 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 )
175175 -> 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) )
177177 }
178178
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 )
180180 -> InferOk < ' tcx , Vec < Adjustment < ' tcx > > > {
181181 let mut obligations = vec ! [ ] ;
182182 let targets = self . steps . iter ( ) . skip ( 1 ) . map ( |& ( ty, _) | ty)
183183 . chain ( iter:: once ( self . cur_ty ) ) ;
184184 let steps: Vec < _ > = self . steps . iter ( ) . map ( |& ( source, kind) | {
185185 if let AutoderefKind :: Overloaded = kind {
186- self . fcx . try_overloaded_deref ( self . span , source, needs)
186+ fcx. try_overloaded_deref ( self . span , source, needs)
187187 . and_then ( |InferOk { value : method, obligations : o } | {
188188 obligations. extend ( o) ;
189189 if let ty:: Ref ( region, _, mutbl) = method. sig . output ( ) . sty {
@@ -220,8 +220,7 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> {
220220 self
221221 }
222222
223- pub fn finalize ( self ) {
224- let fcx = self . fcx ;
223+ pub fn finalize ( self , fcx : & FnCtxt < ' a , ' gcx , ' tcx > ) {
225224 fcx. register_predicates ( self . into_obligations ( ) ) ;
226225 }
227226
@@ -233,7 +232,9 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> {
233232impl < ' a , ' gcx , ' tcx > FnCtxt < ' a , ' gcx , ' tcx > {
234233 pub fn autoderef ( & ' a self , span : Span , base_ty : Ty < ' tcx > ) -> Autoderef < ' a , ' gcx , ' tcx > {
235234 Autoderef {
236- fcx : self ,
235+ infcx : & self . infcx ,
236+ body_id : self . body_id ,
237+ param_env : self . param_env ,
237238 steps : vec ! [ ] ,
238239 cur_ty : self . resolve_type_vars_if_possible ( & base_ty) ,
239240 obligations : vec ! [ ] ,
0 commit comments