@@ -1241,7 +1241,7 @@ pub enum LvaluePreference {
1241
1241
NoPreference
1242
1242
}
1243
1243
1244
- pub fn autoderef < T > ( fcx : @FnCtxt , sp : Span , t : ty:: t ,
1244
+ pub fn autoderef < T > ( fcx : @FnCtxt , sp : Span , base_ty : ty:: t ,
1245
1245
expr_id : Option < ast:: NodeId > ,
1246
1246
mut lvalue_pref : LvaluePreference ,
1247
1247
should_stop: |ty:: t, uint| -> Option < T > )
@@ -1253,24 +1253,10 @@ pub fn autoderef<T>(fcx: @FnCtxt, sp: Span, t: ty::t,
1253
1253
* responsible for inserting an AutoAdjustment record into `tcx.adjustments`
1254
1254
* so that trans/borrowck/etc know about this autoderef. */
1255
1255
1256
- let mut t = t;
1257
- let mut autoderefs = 0 ;
1258
- loop {
1256
+ let mut t = base_ty;
1257
+ for autoderefs in range( 0 , fcx. tcx( ) . sess. recursion_limit. get( ) ) {
1259
1258
let resolved_t = structurally_resolved_type( fcx, sp, t) ;
1260
1259
1261
- // Some extra checks to detect weird cycles and so forth:
1262
- match ty:: get( resolved_t) . sty {
1263
- ty : : ty_box( _) | ty:: ty_uniq( _) | ty:: ty_rptr( _, _) => {
1264
- match ty:: get( t) . sty {
1265
- ty : : ty_infer( ty:: TyVar ( v1) ) => {
1266
- ty : : occurs_check( fcx. ccx. tcx, sp, v1, resolved_t) ;
1267
- }
1268
- _ => { }
1269
- }
1270
- }
1271
- _ => { /*ok*/ }
1272
- }
1273
-
1274
1260
match should_stop( resolved_t, autoderefs) {
1275
1261
Some ( x) => return ( resolved_t, autoderefs, Some ( x) ) ,
1276
1262
None => { }
@@ -1291,11 +1277,16 @@ pub fn autoderef<T>(fcx: @FnCtxt, sp: Span, t: ty::t,
1291
1277
if mt. mutbl == ast:: MutImmutable {
1292
1278
lvalue_pref = NoPreference;
1293
1279
}
1294
- autoderefs += 1 ;
1295
1280
}
1296
1281
None => return ( resolved_t, autoderefs, None )
1297
1282
}
1298
1283
}
1284
+
1285
+ // We've reached the recursion limit, error gracefully.
1286
+ fcx. tcx( ) . sess. span_err( sp,
1287
+ format ! ( "reached the recursion limit while auto-dereferencing {}" ,
1288
+ base_ty. repr( fcx. tcx( ) ) ) ) ;
1289
+ ( ty:: mk_err( ) , 0 , None )
1299
1290
}
1300
1291
1301
1292
fn try_overloaded_deref( fcx: @FnCtxt ,
0 commit comments