2014-05-05 17:00:14 +02:00
|
|
|
digraph block {
|
|
|
|
N0[label="entry"];
|
|
|
|
N1[label="exit"];
|
2014-11-06 00:05:53 -08:00
|
|
|
N2[label="expr E13::E13b"];
|
2014-05-05 17:00:14 +02:00
|
|
|
N3[label="expr 13"];
|
2014-11-06 00:05:53 -08:00
|
|
|
N4[label="expr E13::E13b(13)"];
|
2014-05-05 17:00:14 +02:00
|
|
|
N5[label="local x"];
|
2014-11-06 00:05:53 -08:00
|
|
|
N6[label="stmt let x = E13::E13b(13);"];
|
2014-08-27 21:46:52 -04:00
|
|
|
N7[label="local _y"];
|
|
|
|
N8[label="stmt let _y;"];
|
|
|
|
N9[label="expr x"];
|
2014-11-06 00:05:53 -08:00
|
|
|
N10[label="expr match x { E13::E13a => _y = 1, E13::E13b(v) => _y = v + 1, }"];
|
2014-08-27 21:46:52 -04:00
|
|
|
N11[label="(dummy_node)"];
|
2014-11-06 00:05:53 -08:00
|
|
|
N12[label="pat E13::E13a"];
|
2014-08-27 21:46:52 -04:00
|
|
|
N13[label="expr 1"];
|
|
|
|
N14[label="expr _y"];
|
|
|
|
N15[label="expr _y = 1"];
|
|
|
|
N16[label="(dummy_node)"];
|
|
|
|
N17[label="local v"];
|
2014-11-06 00:05:53 -08:00
|
|
|
N18[label="pat E13::E13b(v)"];
|
2014-08-27 21:46:52 -04:00
|
|
|
N19[label="expr v"];
|
|
|
|
N20[label="expr 1"];
|
|
|
|
N21[label="expr v + 1"];
|
|
|
|
N22[label="expr _y"];
|
|
|
|
N23[label="expr _y = v + 1"];
|
2014-11-06 00:05:53 -08:00
|
|
|
N24[label="block {\l let x = E13::E13b(13);\l let _y;\l match x { E13::E13a => _y = 1, E13::E13b(v) => _y = v + 1, }\l}\l"];
|
2014-05-05 17:00:14 +02:00
|
|
|
N0 -> N2;
|
|
|
|
N2 -> N3;
|
|
|
|
N3 -> N4;
|
|
|
|
N4 -> N5;
|
|
|
|
N5 -> N6;
|
|
|
|
N6 -> N7;
|
2014-08-27 21:46:52 -04:00
|
|
|
N7 -> N8;
|
|
|
|
N8 -> N9;
|
2015-02-19 17:54:41 +01:00
|
|
|
N9 -> N12;
|
|
|
|
N12 -> N11;
|
|
|
|
N11 -> N13;
|
2014-08-27 21:46:52 -04:00
|
|
|
N13 -> N14;
|
2014-05-05 17:00:14 +02:00
|
|
|
N14 -> N15;
|
2014-08-27 21:46:52 -04:00
|
|
|
N15 -> N10;
|
2015-02-19 17:54:41 +01:00
|
|
|
N9 -> N17;
|
2014-05-05 17:00:14 +02:00
|
|
|
N17 -> N18;
|
2015-02-19 17:54:41 +01:00
|
|
|
N18 -> N16;
|
|
|
|
N16 -> N19;
|
librustc: Disallow mutation and assignment in pattern guards, and modify
the CFG for match statements.
There were two bugs in issue #14684. One was simply that the borrow
check didn't know about the correct CFG for match statements: the
pattern must be a predecessor of the guard. This disallows the bad
behavior if there are bindings in the pattern. But it isn't enough to
prevent the memory safety problem, because of wildcards; thus, this
patch introduces a more restrictive rule, which disallows assignments
and mutable borrows inside guards outright.
I discussed this with Niko and we decided this was the best plan of
action.
This breaks code that performs mutable borrows in pattern guards. Most
commonly, the code looks like this:
impl Foo {
fn f(&mut self, ...) {}
fn g(&mut self, ...) {
match bar {
Baz if self.f(...) => { ... }
_ => { ... }
}
}
}
Change this code to not use a guard. For example:
impl Foo {
fn f(&mut self, ...) {}
fn g(&mut self, ...) {
match bar {
Baz => {
if self.f(...) {
...
} else {
...
}
}
_ => { ... }
}
}
}
Sometimes this can result in code duplication, but often it illustrates
a hidden memory safety problem.
Closes #14684.
[breaking-change]
2014-07-25 15:18:19 -07:00
|
|
|
N19 -> N20;
|
|
|
|
N20 -> N21;
|
2014-08-27 21:46:52 -04:00
|
|
|
N21 -> N22;
|
|
|
|
N22 -> N23;
|
|
|
|
N23 -> N10;
|
|
|
|
N10 -> N24;
|
|
|
|
N24 -> N1;
|
2014-05-05 17:00:14 +02:00
|
|
|
}
|