@@ -17,7 +17,7 @@ use hair::cx::to_ref::ToRef;
1717use rustc:: hir:: def:: { Def , CtorKind } ;
1818use rustc:: middle:: const_val:: ConstVal ;
1919use rustc:: ty:: { self , AdtKind , VariantDef , Ty } ;
20- use rustc:: ty:: adjustment:: { Adjustment , Adjust , AutoBorrow } ;
20+ use rustc:: ty:: adjustment:: { Adjustment , Adjust , AutoBorrow , AutoBorrowMutability } ;
2121use rustc:: ty:: cast:: CastKind as TyCastKind ;
2222use rustc:: hir;
2323use rustc:: hir:: def_id:: LocalDefId ;
@@ -112,7 +112,7 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
112112 span,
113113 kind : ExprKind :: Borrow {
114114 region : deref. region ,
115- borrow_kind : to_borrow_kind ( deref. mutbl , true ) ,
115+ borrow_kind : deref. mutbl . to_borrow_kind ( ) ,
116116 arg : expr. to_ref ( ) ,
117117 } ,
118118 } ;
@@ -122,7 +122,7 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
122122 Adjust :: Borrow ( AutoBorrow :: Ref ( r, m) ) => {
123123 ExprKind :: Borrow {
124124 region : r,
125- borrow_kind : to_borrow_kind ( m , true ) ,
125+ borrow_kind : m . to_borrow_kind ( ) ,
126126 arg : expr. to_ref ( ) ,
127127 }
128128 }
@@ -142,7 +142,7 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
142142 span,
143143 kind : ExprKind :: Borrow {
144144 region,
145- borrow_kind : to_borrow_kind ( m , true ) ,
145+ borrow_kind : m . to_borrow_kind ( ) ,
146146 arg : expr. to_ref ( ) ,
147147 } ,
148148 } ;
@@ -288,7 +288,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
288288 } ;
289289 ExprKind :: Borrow {
290290 region,
291- borrow_kind : to_borrow_kind ( mutbl , false ) ,
291+ borrow_kind : mutbl . to_borrow_kind ( ) ,
292292 arg : expr. to_ref ( ) ,
293293 }
294294 }
@@ -643,10 +643,25 @@ fn method_callee<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
643643 }
644644}
645645
646- fn to_borrow_kind ( m : hir:: Mutability , allow_two_phase_borrow : bool ) -> BorrowKind {
647- match m {
648- hir:: MutMutable => BorrowKind :: Mut { allow_two_phase_borrow } ,
649- hir:: MutImmutable => BorrowKind :: Shared ,
646+ trait ToBorrowKind { fn to_borrow_kind ( & self ) -> BorrowKind ; }
647+
648+ impl ToBorrowKind for AutoBorrowMutability {
649+ fn to_borrow_kind ( & self ) -> BorrowKind {
650+ match * self {
651+ AutoBorrowMutability :: Mutable { allow_two_phase_borrow } =>
652+ BorrowKind :: Mut { allow_two_phase_borrow } ,
653+ AutoBorrowMutability :: Immutable =>
654+ BorrowKind :: Shared ,
655+ }
656+ }
657+ }
658+
659+ impl ToBorrowKind for hir:: Mutability {
660+ fn to_borrow_kind ( & self ) -> BorrowKind {
661+ match * self {
662+ hir:: MutMutable => BorrowKind :: Mut { allow_two_phase_borrow : false } ,
663+ hir:: MutImmutable => BorrowKind :: Shared ,
664+ }
650665 }
651666}
652667
0 commit comments