auto merge of #15989 : pcwalton/rust/borrowck-pattern-guards, r=pnkfelix
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] r? @pnkfelix
This commit is contained in:
commit
6635fe7db4
10 changed files with 384 additions and 272 deletions
|
@ -1734,17 +1734,19 @@ fn item_struct(w: &mut fmt::Formatter, it: &clean::Item,
|
|||
}
|
||||
}).peekable();
|
||||
match s.struct_type {
|
||||
doctree::Plain if fields.peek().is_some() => {
|
||||
try!(write!(w, "<h2 class='fields'>Fields</h2>\n<table>"));
|
||||
for field in fields {
|
||||
try!(write!(w, "<tr><td id='structfield.{name}'>\
|
||||
{stab}<code>{name}</code></td><td>",
|
||||
stab = ConciseStability(&field.stability),
|
||||
name = field.name.get_ref().as_slice()));
|
||||
try!(document(w, field));
|
||||
try!(write!(w, "</td></tr>"));
|
||||
doctree::Plain => {
|
||||
if fields.peek().is_some() {
|
||||
try!(write!(w, "<h2 class='fields'>Fields</h2>\n<table>"));
|
||||
for field in fields {
|
||||
try!(write!(w, "<tr><td id='structfield.{name}'>\
|
||||
{stab}<code>{name}</code></td><td>",
|
||||
stab = ConciseStability(&field.stability),
|
||||
name = field.name.get_ref().as_slice()));
|
||||
try!(document(w, field));
|
||||
try!(write!(w, "</td></tr>"));
|
||||
}
|
||||
try!(write!(w, "</table>"));
|
||||
}
|
||||
try!(write!(w, "</table>"));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue