@@ -537,11 +537,15 @@ fn check_legality_of_move_bindings(cx: &MatchVisitor,
537
537
"cannot bind by-move with sub-bindings" )
538
538
. span_label ( p. span , "binds an already bound by-move value by moving it" )
539
539
. emit ( ) ;
540
- } else if has_guard {
541
- struct_span_err ! ( cx. tcx. sess, p. span, E0008 ,
542
- "cannot bind by-move into a pattern guard" )
543
- . span_label ( p. span , "moves value into pattern guard" )
544
- . emit ( ) ;
540
+ } else if has_guard && !cx. tcx . allow_bind_by_move_patterns_with_guards ( ) {
541
+ let mut err = struct_span_err ! ( cx. tcx. sess, p. span, E0008 ,
542
+ "cannot bind by-move into a pattern guard" ) ;
543
+ err. span_label ( p. span , "moves value into pattern guard" ) ;
544
+ if cx. tcx . sess . opts . unstable_features . is_nightly_build ( ) && cx. tcx . use_mir_borrowck ( ) {
545
+ err. help ( "add #![feature(bind_by_move_pattern_guards)] to the \
546
+ crate attributes to enable") ;
547
+ }
548
+ err. emit ( ) ;
545
549
} else if let Some ( by_ref_span) = by_ref_span {
546
550
struct_span_err ! (
547
551
cx. tcx. sess,
@@ -613,10 +617,16 @@ impl<'a, 'tcx> Delegate<'tcx> for MutationChecker<'a, 'tcx> {
613
617
_: LoanCause ) {
614
618
match kind {
615
619
ty:: MutBorrow => {
616
- struct_span_err ! ( self . cx. tcx. sess, span, E0301 ,
617
- "cannot mutably borrow in a pattern guard" )
618
- . span_label ( span, "borrowed mutably in pattern guard" )
619
- . emit ( ) ;
620
+ let mut err = struct_span_err ! ( self . cx. tcx. sess, span, E0301 ,
621
+ "cannot mutably borrow in a pattern guard" ) ;
622
+ err. span_label ( span, "borrowed mutably in pattern guard" ) ;
623
+ if self . cx . tcx . sess . opts . unstable_features . is_nightly_build ( ) &&
624
+ self . cx . tcx . use_mir_borrowck ( )
625
+ {
626
+ err. help ( "add #![feature(bind_by_move_pattern_guards)] to the \
627
+ crate attributes to enable") ;
628
+ }
629
+ err. emit ( ) ;
620
630
}
621
631
ty:: ImmBorrow | ty:: UniqueImmBorrow => { }
622
632
}
0 commit comments