@@ -1241,7 +1241,7 @@ pub enum LvaluePreference {
12411241 NoPreference
12421242}
12431243
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 ,
12451245 expr_id : Option < ast:: NodeId > ,
12461246 mut lvalue_pref : LvaluePreference ,
12471247 should_stop: |ty:: t, uint| -> Option < T > )
@@ -1253,24 +1253,10 @@ pub fn autoderef<T>(fcx: @FnCtxt, sp: Span, t: ty::t,
12531253 * responsible for inserting an AutoAdjustment record into `tcx.adjustments`
12541254 * so that trans/borrowck/etc know about this autoderef. */
12551255
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( ) ) {
12591258 let resolved_t = structurally_resolved_type( fcx, sp, t) ;
12601259
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-
12741260 match should_stop( resolved_t, autoderefs) {
12751261 Some ( x) => return ( resolved_t, autoderefs, Some ( x) ) ,
12761262 None => { }
@@ -1291,11 +1277,16 @@ pub fn autoderef<T>(fcx: @FnCtxt, sp: Span, t: ty::t,
12911277 if mt. mutbl == ast:: MutImmutable {
12921278 lvalue_pref = NoPreference;
12931279 }
1294- autoderefs += 1 ;
12951280 }
12961281 None => return ( resolved_t, autoderefs, None )
12971282 }
12981283 }
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 )
12991290}
13001291
13011292fn try_overloaded_deref( fcx: @FnCtxt ,
0 commit comments