@@ -5,11 +5,6 @@ use super::_match::WitnessPreference::*;
55use super :: { Pattern , PatternContext , PatternError , PatternKind } ;
66
77use rustc:: middle:: borrowck:: SignalledError ;
8- use rustc:: middle:: expr_use_visitor:: { ConsumeMode , Delegate , ExprUseVisitor } ;
9- use rustc:: middle:: expr_use_visitor:: { LoanCause , MutateMode } ;
10- use rustc:: middle:: expr_use_visitor as euv;
11- use rustc:: middle:: mem_categorization:: cmt_;
12- use rustc:: middle:: region;
138use rustc:: session:: Session ;
149use rustc:: ty:: { self , Ty , TyCtxt } ;
1510use rustc:: ty:: subst:: { InternalSubsts , SubstsRef } ;
@@ -36,9 +31,7 @@ crate fn check_match(tcx: TyCtxt<'_>, def_id: DefId) -> SignalledError {
3631
3732 let mut visitor = MatchVisitor {
3833 tcx,
39- body_owner : def_id,
4034 tables : tcx. body_tables ( body_id) ,
41- region_scope_tree : & tcx. region_scope_tree ( def_id) ,
4235 param_env : tcx. param_env ( def_id) ,
4336 identity_substs : InternalSubsts :: identity_for_item ( tcx, def_id) ,
4437 signalled_error : SignalledError :: NoErrorsSeen ,
@@ -53,11 +46,9 @@ fn create_e0004(sess: &Session, sp: Span, error_message: String) -> DiagnosticBu
5346
5447struct MatchVisitor < ' a , ' tcx > {
5548 tcx : TyCtxt < ' tcx > ,
56- body_owner : DefId ,
5749 tables : & ' a ty:: TypeckTables < ' tcx > ,
5850 param_env : ty:: ParamEnv < ' tcx > ,
5951 identity_substs : SubstsRef < ' tcx > ,
60- region_scope_tree : & ' a region:: ScopeTree ,
6152 signalled_error : SignalledError ,
6253}
6354
@@ -151,11 +142,8 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
151142
152143 // Second, if there is a guard on each arm, make sure it isn't
153144 // assigning or borrowing anything mutably.
154- if let Some ( ref guard ) = arm. guard {
145+ if arm. guard . is_some ( ) {
155146 self . signalled_error = SignalledError :: SawSomeError ;
156- if !self . tcx . features ( ) . bind_by_move_pattern_guards {
157- check_for_mutation_in_guard ( self , & guard) ;
158- }
159147 }
160148
161149 // Third, perform some lints.
@@ -582,19 +570,10 @@ fn check_legality_of_move_bindings(
582570 "cannot bind by-move with sub-bindings" )
583571 . span_label( p. span, "binds an already bound by-move value by moving it" )
584572 . emit( ) ;
585- } else if has_guard {
586- if !cx. tcx. features( ) . bind_by_move_pattern_guards {
587- let mut err = struct_span_err!( cx. tcx. sess, p. span, E0008 ,
588- "cannot bind by-move into a pattern guard" ) ;
589- err. span_label( p. span, "moves value into pattern guard" ) ;
590- if cx. tcx. sess. opts. unstable_features. is_nightly_build( ) {
591- err. help( "add `#![feature(bind_by_move_pattern_guards)]` to the \
592- crate attributes to enable") ;
593- }
594- err. emit( ) ;
573+ } else if !has_guard {
574+ if let Some ( _by_ref_span) = by_ref_span {
575+ span_vec. push( p. span) ;
595576 }
596- } else if let Some ( _by_ref_span) = by_ref_span {
597- span_vec. push( p. span) ;
598577 }
599578 } ;
600579
@@ -636,67 +615,6 @@ fn check_legality_of_move_bindings(
636615 }
637616}
638617
639- /// Ensures that a pattern guard doesn't borrow by mutable reference or assign.
640- //
641- // FIXME: this should be done by borrowck.
642- fn check_for_mutation_in_guard( cx: & MatchVisitor <' _, ' _>, guard: & hir:: Guard ) {
643- let mut checker = MutationChecker {
644- cx,
645- } ;
646- match guard {
647- hir:: Guard :: If ( expr) =>
648- ExprUseVisitor :: new( & mut checker,
649- cx. tcx,
650- cx. body_owner,
651- cx. param_env,
652- cx. region_scope_tree,
653- cx. tables,
654- None ) . walk_expr( expr) ,
655- } ;
656- }
657-
658- struct MutationChecker <' a, ' tcx> {
659- cx: & ' a MatchVisitor <' a, ' tcx>,
660- }
661-
662- impl <' a, ' tcx> Delegate <' tcx> for MutationChecker <' a, ' tcx> {
663- fn matched_pat( & mut self , _: & Pat , _: & cmt_<' _>, _: euv:: MatchMode ) { }
664- fn consume( & mut self , _: hir:: HirId , _: Span , _: & cmt_<' _>, _: ConsumeMode ) { }
665- fn consume_pat( & mut self , _: & Pat , _: & cmt_<' _>, _: ConsumeMode ) { }
666- fn borrow( & mut self ,
667- _: hir:: HirId ,
668- span: Span ,
669- _: & cmt_<' _>,
670- _: ty:: Region <' tcx>,
671- kind: ty:: BorrowKind ,
672- _: LoanCause ) {
673- match kind {
674- ty:: MutBorrow => {
675- let mut err = struct_span_err!( self . cx. tcx. sess, span, E0301 ,
676- "cannot mutably borrow in a pattern guard" ) ;
677- err. span_label( span, "borrowed mutably in pattern guard" ) ;
678- if self . cx. tcx. sess. opts. unstable_features. is_nightly_build( ) {
679- err. help( "add `#![feature(bind_by_move_pattern_guards)]` to the \
680- crate attributes to enable") ;
681- }
682- err. emit( ) ;
683- }
684- ty:: ImmBorrow | ty:: UniqueImmBorrow => { }
685- }
686- }
687- fn decl_without_init( & mut self , _: hir:: HirId , _: Span ) { }
688- fn mutate( & mut self , _: hir:: HirId , span: Span , _: & cmt_<' _>, mode: MutateMode ) {
689- match mode {
690- MutateMode :: JustWrite | MutateMode :: WriteAndRead => {
691- struct_span_err!( self . cx. tcx. sess, span, E0302 , "cannot assign in a pattern guard" )
692- . span_label( span, "assignment in pattern guard" )
693- . emit( ) ;
694- }
695- MutateMode :: Init => { }
696- }
697- }
698- }
699-
700618/// Forbids bindings in `@` patterns. This is necessary for memory safety,
701619 /// because of the way rvalues are handled in the borrow check. ( See issue
702620/// #14587.)
0 commit comments