Skip to content

Commit

Permalink
Debug flag to bypass restriction of mutation in match guards.
Browse files Browse the repository at this point in the history
Now, if you pass `-Z disable-ast-check-for-mutation-in-guard`, then we
will just allow you to mutably-borrow and assign in guards of `match`
arms.

This is wildly unsound with AST-borrowck. It is also unsound with
MIR-borrowck without further adjustments, which come in later in the
commit series on this Pull Request.

See also #24535 and rust-lang/rfcs#1006.
  • Loading branch information
pnkfelix committed May 29, 2018
1 parent 524ad9b commit 47bb3fd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
useful for profiling / PGO."),
relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
"choose which RELRO level to use"),
disable_ast_check_for_mutation_in_guard: bool = (false, parse_bool, [UNTRACKED],
"skip AST-based mutation-in-guard check (mir-borrowck provides more precise check)"),
nll_subminimal_causes: bool = (false, parse_bool, [UNTRACKED],
"when tracking region error causes, accept subminimal results for faster execution."),
nll_facts: bool = (false, parse_bool, [UNTRACKED],
Expand Down
6 changes: 6 additions & 0 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
self.on_disk_query_result_cache.serialize(self.global_tcx(), encoder)
}

/// If true, we should use a naive AST walk to determine if match
/// guard could perform bad mutations (or mutable-borrows).
pub fn check_for_mutation_in_guard_via_ast_walk(self) -> bool {
!self.sess.opts.debugging_opts.disable_ast_check_for_mutation_in_guard
}

/// If true, we should use the MIR-based borrowck (we may *also* use
/// the AST-based borrowck).
pub fn use_mir_borrowck(self) -> bool {
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_mir/hair/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
// Second, if there is a guard on each arm, make sure it isn't
// assigning or borrowing anything mutably.
if let Some(ref guard) = arm.guard {
check_for_mutation_in_guard(self, &guard);
if self.tcx.check_for_mutation_in_guard_via_ast_walk() {
check_for_mutation_in_guard(self, &guard);
}
}

// Third, perform some lints.
Expand Down

0 comments on commit 47bb3fd

Please sign in to comment.