@@ -799,18 +799,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
799
799
self . delegate_consume ( expr. id , expr. span , cmt_unadjusted) ;
800
800
}
801
801
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) ;
814
803
}
815
804
}
816
805
}
@@ -860,29 +849,29 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
860
849
self . walk_autoderefs ( expr, adj. autoderefs ) ;
861
850
862
851
// 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
864
853
// fashion. In particular, we want to consume the ~ pointer
865
854
// being dereferenced, not the dereferenced content (as the
866
855
// 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 ( ) ) ) ) ;
872
861
let cmt_unadjusted =
873
862
return_if_err ! ( self . mc. cat_expr_unadjusted( expr) ) ;
874
863
self . delegate_consume ( expr. id , expr. span , cmt_unadjusted) ;
875
864
return ;
876
865
}
877
- _ => { }
878
866
}
879
867
880
- let autoref = adj. autoref . as_ref ( ) ;
868
+ // let autoref = adj.autoref.as_ref();
881
869
let cmt_derefd = return_if_err ! (
882
870
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 ) ;
884
872
}
885
873
874
+
886
875
/// Walks the autoref `opt_autoref` applied to the autoderef'd
887
876
/// `expr`. `cmt_derefd` is the mem-categorized form of `expr`
888
877
/// 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> {
893
882
/// autoref.
894
883
fn walk_autoref ( & mut self ,
895
884
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 > > )
898
887
-> mc:: cmt < ' tcx >
899
888
{
900
889
debug ! ( "walk_autoref(expr.id={} cmt_derefd={} opt_autoref={:?})" ,
901
890
expr. id,
902
- cmt_derefd . repr( self . tcx( ) ) ,
891
+ cmt_base . repr( self . tcx( ) ) ,
903
892
opt_autoref) ;
904
893
894
+ let cmt_base_ty = cmt_base. ty ;
895
+
905
896
let autoref = match opt_autoref {
906
- Some ( autoref) => autoref,
897
+ Some ( ref autoref) => autoref,
907
898
None => {
908
- // No recursive step here, this is a base case .
909
- return cmt_derefd . clone ( ) ;
899
+ // No AutoRef .
900
+ return cmt_base ;
910
901
}
911
902
} ;
912
903
913
- let cmt_base = self . walk_autoref_recursively ( expr, cmt_derefd, baseref) ;
914
-
915
904
debug ! ( "walk_autoref: expr.id={} cmt_base={}" ,
916
905
expr. id,
917
906
cmt_base. repr( self . tcx( ) ) ) ;
@@ -920,15 +909,13 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
920
909
ty:: AutoPtr ( r, m) => {
921
910
self . delegate . borrow ( expr. id ,
922
911
expr. span ,
923
- cmt_derefd ,
912
+ cmt_base ,
924
913
* r,
925
914
ty:: BorrowKind :: from_mutbl ( m) ,
926
915
AutoRef ) ;
927
916
}
928
917
929
- ty:: AutoUnsafe ( m, ref baseref) => {
930
- let cmt_base = self . walk_autoref_recursively ( expr, cmt_derefd, baseref) ;
931
-
918
+ ty:: AutoUnsafe ( m) => {
932
919
debug ! ( "walk_autoref: expr.id={} cmt_base={}" ,
933
920
expr. id,
934
921
cmt_base. repr( self . tcx( ) ) ) ;
@@ -953,24 +940,12 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
953
940
954
941
let adj_ty =
955
942
ty:: adjust_ty_for_autoref ( self . tcx ( ) ,
956
- expr. span ,
957
- cmt_derefd. ty ,
943
+ cmt_base_ty,
958
944
opt_autoref) ;
959
945
960
946
self . mc . cat_rvalue_node ( expr. id , expr. span , adj_ty)
961
947
}
962
948
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
-
974
949
975
950
// When this returns true, it means that the expression *is* a
976
951
// method-call (i.e. via the operator-overload). This true result
0 commit comments