@@ -242,6 +242,7 @@ impl OverloadedCallType {
242242pub struct ExprUseVisitor < ' a , ' gcx : ' a +' tcx , ' tcx : ' a > {
243243 mc : mc:: MemCategorizationContext < ' a , ' gcx , ' tcx > ,
244244 delegate : & ' a mut Delegate < ' tcx > ,
245+ param_env : ty:: ParamEnv < ' tcx > ,
245246}
246247
247248// If the TYPER results in an error, it's because the type check
@@ -266,24 +267,28 @@ macro_rules! return_if_err {
266267impl < ' a , ' gcx , ' tcx > ExprUseVisitor < ' a , ' gcx , ' tcx > {
267268 pub fn new ( delegate : & ' a mut ( Delegate < ' tcx > +' a ) ,
268269 region_maps : & ' a RegionMaps ,
269- infcx : & ' a InferCtxt < ' a , ' gcx , ' tcx > )
270+ infcx : & ' a InferCtxt < ' a , ' gcx , ' tcx > ,
271+ param_env : ty:: ParamEnv < ' tcx > )
270272 -> Self
271273 {
272274 ExprUseVisitor :: with_options ( delegate,
273275 infcx,
276+ param_env,
274277 region_maps,
275278 mc:: MemCategorizationOptions :: default ( ) )
276279 }
277280
278281 pub fn with_options ( delegate : & ' a mut ( Delegate < ' tcx > +' a ) ,
279282 infcx : & ' a InferCtxt < ' a , ' gcx , ' tcx > ,
283+ param_env : ty:: ParamEnv < ' tcx > ,
280284 region_maps : & ' a RegionMaps ,
281285 options : mc:: MemCategorizationOptions )
282286 -> Self
283287 {
284288 ExprUseVisitor {
285289 mc : mc:: MemCategorizationContext :: with_options ( infcx, region_maps, options) ,
286- delegate : delegate
290+ delegate,
291+ param_env,
287292 }
288293 }
289294
@@ -318,7 +323,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
318323 debug ! ( "delegate_consume(consume_id={}, cmt={:?})" ,
319324 consume_id, cmt) ;
320325
321- let mode = copy_or_move ( self . mc . infcx , & cmt, DirectRefMove ) ;
326+ let mode = copy_or_move ( self . mc . infcx , self . param_env , & cmt, DirectRefMove ) ;
322327 self . delegate . consume ( consume_id, consume_span, cmt, mode) ;
323328 }
324329
@@ -797,7 +802,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
797802 PatKind :: Binding ( hir:: BindByRef ( ..) , ..) =>
798803 mode. lub( BorrowingMatch ) ,
799804 PatKind :: Binding ( hir:: BindByValue ( ..) , ..) => {
800- match copy_or_move( self . mc. infcx, & cmt_pat, PatBindingMove ) {
805+ match copy_or_move( self . mc. infcx, self . param_env , & cmt_pat, PatBindingMove ) {
801806 Copy => mode. lub( CopyingMatch ) ,
802807 Move ( ..) => mode. lub( MovingMatch ) ,
803808 }
@@ -813,10 +818,9 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
813818 fn walk_pat ( & mut self , cmt_discr : mc:: cmt < ' tcx > , pat : & hir:: Pat , match_mode : MatchMode ) {
814819 debug ! ( "walk_pat cmt_discr={:?} pat={:?}" , cmt_discr, pat) ;
815820
816- let tcx = & self . tcx ( ) ;
817- let mc = & self . mc ;
821+ let tcx = self . tcx ( ) ;
818822 let infcx = self . mc . infcx ;
819- let delegate = & mut self . delegate ;
823+ let ExprUseVisitor { ref mc , ref mut delegate, param_env } = * self ;
820824 return_if_err ! ( mc. cat_pattern( cmt_discr. clone( ) , pat, |mc, cmt_pat, pat| {
821825 if let PatKind :: Binding ( bmode, def_id, ..) = pat. node {
822826 debug!( "binding cmt_pat={:?} pat={:?} match_mode={:?}" , cmt_pat, pat, match_mode) ;
@@ -840,7 +844,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
840844 }
841845 }
842846 hir:: BindByValue ( ..) => {
843- let mode = copy_or_move( infcx, & cmt_pat, PatBindingMove ) ;
847+ let mode = copy_or_move( infcx, param_env , & cmt_pat, PatBindingMove ) ;
844848 debug!( "walk_pat binding consuming pat" ) ;
845849 delegate. consume_pat( pat, cmt_pat, mode) ;
846850 }
@@ -899,7 +903,10 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
899903 freevar. def) ) ;
900904 match upvar_capture {
901905 ty:: UpvarCapture :: ByValue => {
902- let mode = copy_or_move ( self . mc . infcx , & cmt_var, CaptureMove ) ;
906+ let mode = copy_or_move ( self . mc . infcx ,
907+ self . param_env ,
908+ & cmt_var,
909+ CaptureMove ) ;
903910 self . delegate . consume ( closure_expr. id , freevar. span , cmt_var, mode) ;
904911 }
905912 ty:: UpvarCapture :: ByRef ( upvar_borrow) => {
@@ -929,11 +936,12 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
929936}
930937
931938fn copy_or_move < ' a , ' gcx , ' tcx > ( infcx : & InferCtxt < ' a , ' gcx , ' tcx > ,
939+ param_env : ty:: ParamEnv < ' tcx > ,
932940 cmt : & mc:: cmt < ' tcx > ,
933941 move_reason : MoveReason )
934942 -> ConsumeMode
935943{
936- if infcx. type_moves_by_default ( cmt. ty , cmt. span ) {
944+ if infcx. type_moves_by_default ( param_env , cmt. ty , cmt. span ) {
937945 Move ( move_reason)
938946 } else {
939947 Copy
0 commit comments