rust/src/test
bors 6635fe7db4 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
2014-07-29 17:41:41 +00:00
..
auxiliary Remove managed_box gate from tests 2014-07-26 21:05:29 -07:00
bench Remove managed_box gate from tests 2014-07-26 21:05:29 -07:00
codegen
compile-fail auto merge of #15989 : pcwalton/rust/borrowck-pattern-guards, r=pnkfelix 2014-07-29 17:41:41 +00:00
compile-fail-fulldeps test: Try to fix a failing snapshot test 2014-07-15 14:00:37 -07:00
debuginfo Remove managed_box gate from tests 2014-07-26 21:05:29 -07:00
pretty Remove managed_box gate from tests 2014-07-26 21:05:29 -07:00
run-fail Remove managed_box gate from tests 2014-07-26 21:05:29 -07:00
run-make librustc: Disallow mutation and assignment in pattern guards, and modify 2014-07-25 15:26:21 -07:00
run-pass Remove managed_box gate from tests 2014-07-26 21:05:29 -07:00
run-pass-fulldeps Remove managed_box gate from tests 2014-07-26 21:05:29 -07:00