@@ -799,18 +799,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
799799 self . delegate_consume ( expr. id , expr. span , cmt_unadjusted) ;
800800 }
801801 ty:: AdjustDerefRef ( ref adj) => {
802- self . walk_autoderefs ( expr, adj. autoderefs ) ;
803- if let Some ( ref r) = adj. autoref {
804- self . walk_autoref ( expr, r, adj. autoderefs ) ;
805- } else if adj. unsize . is_some ( ) {
806- assert ! ( adj. autoderefs == 0 ,
807- format!( "Expected no derefs with \
808- unsize AutoRefs, found: {}",
809- adj. repr( self . tcx( ) ) ) ) ;
810- let cmt_unadjusted =
811- return_if_err ! ( self . mc. cat_expr_unadjusted( expr) ) ;
812- self . delegate_consume ( expr. id , expr. span , cmt_unadjusted) ;
813- }
802+ self . walk_autoderefref ( expr, adj) ;
814803 }
815804 }
816805 }
@@ -860,29 +849,29 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
860849 self . walk_autoderefs ( expr, adj. autoderefs ) ;
861850
862851 // Weird hacky special case: AutoUnsizeUniq, which converts
863- // from a ~T to a ~ Trait etc, always comes in a stylized
852+ // from a Box<T> to a Box< Trait> etc, always comes in a stylized
864853 // fashion. In particular, we want to consume the ~ pointer
865854 // being dereferenced, not the dereferenced content (as the
866855 // content is, at least for upcasts, unsized).
867- match adj. autoref {
868- Some ( ty:: AutoUnsizeUniq ( _) ) => {
869- assert ! ( adj. autoderefs == 1 ,
870- format!( "Expected exactly 1 deref with Uniq AutoRefs, found: {}" ,
871- adj. autoderefs ) ) ;
856+ if let Some ( ty ) = adj. unsize {
857+ if let ty:: ty_uniq ( _) = ty . sty {
858+ assert ! ( adj. autoderefs == 0 ,
859+ format!( "Expected no derefs with unsize AutoRefs, found: {}" ,
860+ adj. repr ( self . tcx ( ) ) ) ) ;
872861 let cmt_unadjusted =
873862 return_if_err ! ( self . mc. cat_expr_unadjusted( expr) ) ;
874863 self . delegate_consume ( expr. id , expr. span , cmt_unadjusted) ;
875864 return ;
876865 }
877- _ => { }
878866 }
879867
880- let autoref = adj. autoref . as_ref ( ) ;
868+ // let autoref = adj.autoref.as_ref();
881869 let cmt_derefd = return_if_err ! (
882870 self . mc. cat_expr_autoderefd( expr, adj. autoderefs) ) ;
883- self . walk_autoref ( expr, & cmt_derefd, autoref) ;
871+ self . walk_autoref ( expr, cmt_derefd, adj . autoref ) ;
884872 }
885873
874+
886875 /// Walks the autoref `opt_autoref` applied to the autoderef'd
887876 /// `expr`. `cmt_derefd` is the mem-categorized form of `expr`
888877 /// after all relevant autoderefs have occurred. Because AutoRefs
@@ -893,25 +882,25 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
893882 /// autoref.
894883 fn walk_autoref ( & mut self ,
895884 expr : & ast:: Expr ,
896- cmt_derefd : & mc:: cmt < ' tcx > ,
897- opt_autoref : Option < & ty:: AutoRef < ' tcx > > )
885+ cmt_base : mc:: cmt < ' tcx > ,
886+ opt_autoref : Option < ty:: AutoRef < ' tcx > > )
898887 -> mc:: cmt < ' tcx >
899888 {
900889 debug ! ( "walk_autoref(expr.id={} cmt_derefd={} opt_autoref={:?})" ,
901890 expr. id,
902- cmt_derefd . repr( self . tcx( ) ) ,
891+ cmt_base . repr( self . tcx( ) ) ,
903892 opt_autoref) ;
904893
894+ let cmt_base_ty = cmt_base. ty ;
895+
905896 let autoref = match opt_autoref {
906- Some ( autoref) => autoref,
897+ Some ( ref autoref) => autoref,
907898 None => {
908- // No recursive step here, this is a base case .
909- return cmt_derefd . clone ( ) ;
899+ // No AutoRef .
900+ return cmt_base ;
910901 }
911902 } ;
912903
913- let cmt_base = self . walk_autoref_recursively ( expr, cmt_derefd, baseref) ;
914-
915904 debug ! ( "walk_autoref: expr.id={} cmt_base={}" ,
916905 expr. id,
917906 cmt_base. repr( self . tcx( ) ) ) ;
@@ -920,15 +909,13 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
920909 ty:: AutoPtr ( r, m) => {
921910 self . delegate . borrow ( expr. id ,
922911 expr. span ,
923- cmt_derefd ,
912+ cmt_base ,
924913 * r,
925914 ty:: BorrowKind :: from_mutbl ( m) ,
926915 AutoRef ) ;
927916 }
928917
929- ty:: AutoUnsafe ( m, ref baseref) => {
930- let cmt_base = self . walk_autoref_recursively ( expr, cmt_derefd, baseref) ;
931-
918+ ty:: AutoUnsafe ( m) => {
932919 debug ! ( "walk_autoref: expr.id={} cmt_base={}" ,
933920 expr. id,
934921 cmt_base. repr( self . tcx( ) ) ) ;
@@ -953,24 +940,12 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
953940
954941 let adj_ty =
955942 ty:: adjust_ty_for_autoref ( self . tcx ( ) ,
956- expr. span ,
957- cmt_derefd. ty ,
943+ cmt_base_ty,
958944 opt_autoref) ;
959945
960946 self . mc . cat_rvalue_node ( expr. id , expr. span , adj_ty)
961947 }
962948
963- fn walk_autoref_recursively ( & mut self ,
964- expr : & ast:: Expr ,
965- cmt_derefd : & mc:: cmt < ' tcx > ,
966- autoref : & Option < Box < ty:: AutoRef < ' tcx > > > )
967- -> mc:: cmt < ' tcx >
968- {
969- // Shuffle from a ref to an optional box to an optional ref.
970- let autoref: Option < & ty:: AutoRef < ' tcx > > = autoref. as_ref ( ) . map ( |b| & * * b) ;
971- self . walk_autoref ( expr, cmt_derefd, autoref)
972- }
973-
974949
975950 // When this returns true, it means that the expression *is* a
976951 // method-call (i.e. via the operator-overload). This true result
0 commit comments