@@ -460,7 +460,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
460
460
autoderefs,
461
461
cmt. repr( self . tcx( ) ) ) ;
462
462
for deref in range ( 1 u, autoderefs + 1 ) {
463
- cmt = try!( self . cat_deref ( expr, cmt, deref, false ) ) ;
463
+ cmt = try!( self . cat_deref ( expr, cmt, deref) ) ;
464
464
}
465
465
return Ok ( cmt) ;
466
466
}
@@ -472,7 +472,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
472
472
match expr. node {
473
473
ast:: ExprUnary ( ast:: UnDeref , ref e_base) => {
474
474
let base_cmt = try!( self . cat_expr ( & * * e_base) ) ;
475
- self . cat_deref ( expr, base_cmt, 0 , false )
475
+ self . cat_deref ( expr, base_cmt, 0 )
476
476
}
477
477
478
478
ast:: ExprField ( ref base, f_name) => {
@@ -496,10 +496,23 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
496
496
// If this is an index implemented by a method call, then it
497
497
// will include an implicit deref of the result.
498
498
let ret_ty = self . overloaded_method_return_ty ( method_ty) ;
499
- self . cat_deref ( expr,
500
- self . cat_rvalue_node ( expr. id ( ) ,
501
- expr. span ( ) ,
502
- ret_ty) , 1 , true )
499
+
500
+ // The index method always returns an `&T`, so
501
+ // dereference it to find the result type.
502
+ let elem_ty = match ret_ty. sty {
503
+ ty:: ty_rptr( _, mt) => mt. ty ,
504
+ _ => {
505
+ debug ! ( "cat_expr_unadjusted: return type of overloaded index is {}?" ,
506
+ ret_ty. repr( self . tcx( ) ) ) ;
507
+ return Err ( ( ) ) ;
508
+ }
509
+ } ;
510
+
511
+ // The call to index() returns a `&T` value, which
512
+ // is an rvalue. That is what we will be
513
+ // dereferencing.
514
+ let base_cmt = self . cat_rvalue_node ( expr. id ( ) , expr. span ( ) , ret_ty) ;
515
+ self . cat_deref_common ( expr, base_cmt, 1 , elem_ty, true )
503
516
}
504
517
None => {
505
518
self . cat_index ( expr, try!( self . cat_expr ( & * * base) ) )
@@ -844,8 +857,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
844
857
fn cat_deref < N : ast_node > ( & self ,
845
858
node : & N ,
846
859
base_cmt : cmt < ' tcx > ,
847
- deref_cnt : uint ,
848
- implicit : bool )
860
+ deref_cnt : uint )
849
861
-> McResult < cmt < ' tcx > > {
850
862
let adjustment = match self . typer . adjustments ( ) . borrow ( ) . get ( & node. id ( ) ) {
851
863
Some ( adj) if ty:: adjust_is_object ( adj) => ty:: AutoObject ,
@@ -873,7 +885,8 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
873
885
} ;
874
886
let base_cmt_ty = base_cmt. ty ;
875
887
match ty:: deref ( base_cmt_ty, true ) {
876
- Some ( mt) => self . cat_deref_common ( node, base_cmt, deref_cnt, mt. ty , implicit) ,
888
+ Some ( mt) => self . cat_deref_common ( node, base_cmt, deref_cnt, mt. ty ,
889
+ /* implicit: */ false ) ,
877
890
None => {
878
891
debug ! ( "Explicit deref of non-derefable type: {}" ,
879
892
base_cmt_ty. repr( self . tcx( ) ) ) ;
@@ -1243,7 +1256,7 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
1243
1256
// box p1, &p1, &mut p1. we can ignore the mutability of
1244
1257
// PatRegion since that information is already contained
1245
1258
// in the type.
1246
- let subcmt = try!( self . cat_deref ( pat, cmt, 0 , false ) ) ;
1259
+ let subcmt = try!( self . cat_deref ( pat, cmt, 0 ) ) ;
1247
1260
try!( self . cat_pattern_ ( subcmt, & * * subpat, op) ) ;
1248
1261
}
1249
1262
0 commit comments