diff options
author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2018-05-07 15:54:41 +0200 |
---|---|---|
committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2018-05-29 23:01:36 +0200 |
commit | 47bb3fd50559c31030c5f89400864f368694c02f (patch) | |
tree | 0784f4343fdaf7a2f1b85b1eeda7ad14da77d24a /src | |
parent | Auto merge of #51165 - SimonSapin:opt2, r=alexcrichton (diff) | |
download | grust-47bb3fd50559c31030c5f89400864f368694c02f.tar.gz grust-47bb3fd50559c31030c5f89400864f368694c02f.tar.bz2 grust-47bb3fd50559c31030c5f89400864f368694c02f.tar.xz |
Debug flag to bypass restriction of mutation in match guards.
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 rust-lang/rust#24535 and rust-lang/rfcs#1006.
Diffstat (limited to 'src')
-rw-r--r-- | src/librustc/session/config.rs | 2 | ||||
-rw-r--r-- | src/librustc/ty/context.rs | 6 | ||||
-rw-r--r-- | src/librustc_mir/hair/pattern/check_match.rs | 4 |
3 files changed, 11 insertions, 1 deletions
diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 755b4af1a3..45af66815f 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs | |||
@@ -1290,6 +1290,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, | |||
1290 | useful for profiling / PGO."), | 1290 | useful for profiling / PGO."), |
1291 | relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED], | 1291 | relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED], |
1292 | "choose which RELRO level to use"), | 1292 | "choose which RELRO level to use"), |
1293 | disable_ast_check_for_mutation_in_guard: bool = (false, parse_bool, [UNTRACKED], | ||
1294 | "skip AST-based mutation-in-guard check (mir-borrowck provides more precise check)"), | ||
1293 | nll_subminimal_causes: bool = (false, parse_bool, [UNTRACKED], | 1295 | nll_subminimal_causes: bool = (false, parse_bool, [UNTRACKED], |
1294 | "when tracking region error causes, accept subminimal results for faster execution."), | 1296 | "when tracking region error causes, accept subminimal results for faster execution."), |
1295 | nll_facts: bool = (false, parse_bool, [UNTRACKED], | 1297 | nll_facts: bool = (false, parse_bool, [UNTRACKED], |
diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index a533e1a5b9..1ee28a6542 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs | |||
@@ -1344,6 +1344,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { | |||
1344 | self.on_disk_query_result_cache.serialize(self.global_tcx(), encoder) | 1344 | self.on_disk_query_result_cache.serialize(self.global_tcx(), encoder) |
1345 | } | 1345 | } |
1346 | 1346 | ||
1347 | /// If true, we should use a naive AST walk to determine if match | ||
1348 | /// guard could perform bad mutations (or mutable-borrows). | ||
1349 | pub fn check_for_mutation_in_guard_via_ast_walk(self) -> bool { | ||
1350 | !self.sess.opts.debugging_opts.disable_ast_check_for_mutation_in_guard | ||
1351 | } | ||
1352 | |||
1347 | /// If true, we should use the MIR-based borrowck (we may *also* use | 1353 | /// If true, we should use the MIR-based borrowck (we may *also* use |
1348 | /// the AST-based borrowck). | 1354 | /// the AST-based borrowck). |
1349 | pub fn use_mir_borrowck(self) -> bool { | 1355 | pub fn use_mir_borrowck(self) -> bool { |
diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 7c44a8d4d5..0a11397009 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs | |||
@@ -181,7 +181,9 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> { | |||
181 | // Second, if there is a guard on each arm, make sure it isn't | 181 | // Second, if there is a guard on each arm, make sure it isn't |
182 | // assigning or borrowing anything mutably. | 182 | // assigning or borrowing anything mutably. |
183 | if let Some(ref guard) = arm.guard { | 183 | if let Some(ref guard) = arm.guard { |
184 | check_for_mutation_in_guard(self, &guard); | 184 | if self.tcx.check_for_mutation_in_guard_via_ast_walk() { |
185 | check_for_mutation_in_guard(self, &guard); | ||
186 | } | ||
185 | } | 187 | } |
186 | 188 | ||
187 | // Third, perform some lints. | 189 | // Third, perform some lints. |