@@ -5191,28 +5191,12 @@ impl<'tcx> TyS<'tcx> {
5191
5191
5192
5192
if !adjusted_ty. references_error ( ) {
5193
5193
for i in 0 ..adj. autoderefs {
5194
- let method_call = MethodCall :: autoderef ( expr_id, i as u32 ) ;
5195
- match method_type ( method_call) {
5196
- Some ( method_ty) => {
5197
- // Overloaded deref operators have all late-bound
5198
- // regions fully instantiated and coverge.
5199
- let fn_ret =
5200
- cx. no_late_bound_regions ( & method_ty. fn_ret ( ) ) . unwrap ( ) ;
5201
- adjusted_ty = fn_ret. unwrap ( ) ;
5202
- }
5203
- None => { }
5204
- }
5205
- match adjusted_ty. builtin_deref ( true , NoPreference ) {
5206
- Some ( mt) => { adjusted_ty = mt. ty ; }
5207
- None => {
5208
- cx. sess . span_bug (
5209
- span,
5210
- & format ! ( "the {}th autoderef failed: {}" ,
5211
- i,
5212
- adjusted_ty)
5213
- ) ;
5214
- }
5215
- }
5194
+ adjusted_ty =
5195
+ adjusted_ty. adjust_for_autoderef ( cx,
5196
+ expr_id,
5197
+ span,
5198
+ i as u32 ,
5199
+ & mut method_type) ;
5216
5200
}
5217
5201
}
5218
5202
@@ -5228,6 +5212,39 @@ impl<'tcx> TyS<'tcx> {
5228
5212
} ;
5229
5213
}
5230
5214
5215
+ pub fn adjust_for_autoderef < F > ( & ' tcx self ,
5216
+ cx : & ctxt < ' tcx > ,
5217
+ expr_id : ast:: NodeId ,
5218
+ expr_span : Span ,
5219
+ autoderef : u32 , // how many autoderefs so far?
5220
+ mut method_type : F )
5221
+ -> Ty < ' tcx > where
5222
+ F : FnMut ( MethodCall ) -> Option < Ty < ' tcx > > ,
5223
+ {
5224
+ let method_call = MethodCall :: autoderef ( expr_id, autoderef) ;
5225
+ let mut adjusted_ty = self ;
5226
+ match method_type ( method_call) {
5227
+ Some ( method_ty) => {
5228
+ // Method calls always have all late-bound regions
5229
+ // fully instantiated.
5230
+ let fn_ret = cx. no_late_bound_regions ( & method_ty. fn_ret ( ) ) . unwrap ( ) ;
5231
+ adjusted_ty = fn_ret. unwrap ( ) ;
5232
+ }
5233
+ None => { }
5234
+ }
5235
+ match adjusted_ty. builtin_deref ( true , NoPreference ) {
5236
+ Some ( mt) => mt. ty ,
5237
+ None => {
5238
+ cx. sess . span_bug (
5239
+ expr_span,
5240
+ & format ! ( "the {}th autoderef failed: {}" ,
5241
+ autoderef,
5242
+ adjusted_ty)
5243
+ ) ;
5244
+ }
5245
+ }
5246
+ }
5247
+
5231
5248
pub fn adjust_for_autoref ( & ' tcx self , cx : & ctxt < ' tcx > ,
5232
5249
autoref : Option < AutoRef < ' tcx > > )
5233
5250
-> Ty < ' tcx > {
0 commit comments