@@ -1436,10 +1436,37 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
1436
1436
self . queries . on_disk_cache . serialize ( self . global_tcx ( ) , encoder)
1437
1437
}
1438
1438
1439
+ /// This checks whether one is allowed to have pattern bindings
1440
+ /// that bind-by-move on a match arm that has a guard, e.g.:
1441
+ ///
1442
+ /// ```rust
1443
+ /// match foo { A(inner) if { /* something */ } => ..., ... }
1444
+ /// ```
1445
+ ///
1446
+ /// It is separate from check_for_mutation_in_guard_via_ast_walk,
1447
+ /// because that method has a narrower effect that can be toggled
1448
+ /// off via a separate `-Z` flag, at least for the short term.
1449
+ pub fn allow_bind_by_move_patterns_with_guards ( self ) -> bool {
1450
+ self . features ( ) . bind_by_move_pattern_guards && self . use_mir_borrowck ( )
1451
+ }
1452
+
1439
1453
/// If true, we should use a naive AST walk to determine if match
1440
1454
/// guard could perform bad mutations (or mutable-borrows).
1441
1455
pub fn check_for_mutation_in_guard_via_ast_walk ( self ) -> bool {
1442
- !self . sess . opts . debugging_opts . disable_ast_check_for_mutation_in_guard
1456
+ // If someone passes the `-Z` flag, they're asking for the footgun.
1457
+ if self . sess . opts . debugging_opts . disable_ast_check_for_mutation_in_guard {
1458
+ return false ;
1459
+ }
1460
+
1461
+ // If someone requests the feature, then be a little more
1462
+ // careful and ensure that MIR-borrowck is enabled (which can
1463
+ // happen via edition selection, via `feature(nll)`, or via an
1464
+ // appropriate `-Z` flag) before disabling the mutation check.
1465
+ if self . allow_bind_by_move_patterns_with_guards ( ) {
1466
+ return false ;
1467
+ }
1468
+
1469
+ return true ;
1443
1470
}
1444
1471
1445
1472
/// If true, we should use the AST-based borrowck (we may *also* use
0 commit comments