diff options
| author | bors <bors@rust-lang.org> | 2013-05-11 11:49:50 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-05-11 11:49:50 -0700 |
| commit | e478cedb0ab0bdb7e00a3a60a6946915af0fdd5a (patch) | |
| tree | 33adb76318393876fa8c9f78964873807b38deb7 /src/test | |
| parent | 96de2b0273e828edf45d4b3e6c4dc5c3cf665fd5 (diff) | |
| parent | 912a352712b1b97009a11e3c3f7c4ba7360d9eaf (diff) | |
| download | rust-e478cedb0ab0bdb7e00a3a60a6946915af0fdd5a.tar.gz rust-e478cedb0ab0bdb7e00a3a60a6946915af0fdd5a.zip | |
auto merge of #6385 : huonw/rust/rustc-dtor-struct-match, r=nikomatsakis
**Caveat**: With the current commit, this check only works for `match`s, the checks (incorrectly) do not run for patterns in `let`s, and invalid/unsafe code compiles. I don't know how to fix this, I experimented with some things to try to make let patterns and match patterns run on the same code (since this would presumably fix many of the other unsoundness issues of let-patterns, e.g. #6225), but I don't understand enough of the code. (I think I heard someone talking about a fix for `let` being in progress?) Fixes #6344 and #6341.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/disallowed-deconstructing-destructing-struct-let.rs (renamed from src/test/compile-fail/disallowed-deconstructing-destructing-struct.rs) | 3 | ||||
| -rw-r--r-- | src/test/compile-fail/disallowed-deconstructing-destructing-struct-match.rs | 28 | ||||
| -rw-r--r-- | src/test/run-pass/issue-6341.rs | 18 | ||||
| -rw-r--r-- | src/test/run-pass/issue-6344-let.rs | 22 | ||||
| -rw-r--r-- | src/test/run-pass/issue-6344-match.rs | 24 |
5 files changed, 94 insertions, 1 deletions
diff --git a/src/test/compile-fail/disallowed-deconstructing-destructing-struct.rs b/src/test/compile-fail/disallowed-deconstructing-destructing-struct-let.rs index fa34c056794..c363f172d2f 100644 --- a/src/test/compile-fail/disallowed-deconstructing-destructing-struct.rs +++ b/src/test/compile-fail/disallowed-deconstructing-destructing-struct-let.rs @@ -1,3 +1,4 @@ +// xfail-test #3024 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. @@ -19,7 +20,7 @@ impl Drop for X { } fn unwrap(x: X) -> ~str { - let X { x: y } = x; //~ ERROR deconstructing struct not allowed in pattern + let X { x: y } = x; //~ ERROR cannot bind by-move within struct y } diff --git a/src/test/compile-fail/disallowed-deconstructing-destructing-struct-match.rs b/src/test/compile-fail/disallowed-deconstructing-destructing-struct-match.rs new file mode 100644 index 00000000000..40305ba8b95 --- /dev/null +++ b/src/test/compile-fail/disallowed-deconstructing-destructing-struct-match.rs @@ -0,0 +1,28 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +struct X { + x: ~str, +} + +impl Drop for X { + fn finalize(&self) { + error!("value: %s", self.x); + } +} + +fn main() { + let x = X { x: ~"hello" }; + + match x { + X { x: y } => error!("contents: %s", y) + //~^ ERROR cannot bind by-move within struct + } +} diff --git a/src/test/run-pass/issue-6341.rs b/src/test/run-pass/issue-6341.rs new file mode 100644 index 00000000000..394345556fc --- /dev/null +++ b/src/test/run-pass/issue-6341.rs @@ -0,0 +1,18 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[deriving(Eq)] +struct A { x: uint } + +impl Drop for A { + fn finalize(&self) {} +} + +fn main() {} \ No newline at end of file diff --git a/src/test/run-pass/issue-6344-let.rs b/src/test/run-pass/issue-6344-let.rs new file mode 100644 index 00000000000..916131b6b71 --- /dev/null +++ b/src/test/run-pass/issue-6344-let.rs @@ -0,0 +1,22 @@ +// xfail-test #3874 +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +struct A { x: uint } + +impl Drop for A { + fn finalize(&self) {} +} + +fn main() { + let a = A { x: 0 }; + + let A { x: ref x } = a; + debug!("%?", x) +} diff --git a/src/test/run-pass/issue-6344-match.rs b/src/test/run-pass/issue-6344-match.rs new file mode 100644 index 00000000000..5bf57aa7116 --- /dev/null +++ b/src/test/run-pass/issue-6344-match.rs @@ -0,0 +1,24 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +struct A { x: uint } + +impl Drop for A { + fn finalize(&self) {} +} + +fn main() { + let a = A { x: 0 }; + + match a { + A { x : ref x } => { + debug!("%?", x) + } + } +} |
