diff options
| author | bors <bors@rust-lang.org> | 2013-08-10 16:32:18 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-08-10 16:32:18 -0700 |
| commit | bf809768ee8ff3ea4ef434721ff82b09a4df261a (patch) | |
| tree | f7492e25ff06c4eeb3d1e480f641344b306c4247 /src/test | |
| parent | 8b9e1ce75a3e1416f2db80d30f65879fd902183f (diff) | |
| parent | 20953bb1fbfafc3839e739f38ddf7d495eb1fe8b (diff) | |
| download | rust-bf809768ee8ff3ea4ef434721ff82b09a4df261a.tar.gz rust-bf809768ee8ff3ea4ef434721ff82b09a4df261a.zip | |
auto merge of #8444 : erickt/rust/rollup, r=cmr
This merges these PR together: #8430: r=thestinger #8370: r=thestinger #8386: r=bstrie #8388: r=thestinger #8390: r=graydon #8394: r=graydon #8402: r=thestinger #8403: r=catamorphism
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/auxiliary/xc_private_method_lib.rs | 30 | ||||
| -rw-r--r-- | src/test/compile-fail/borrowck-move-out-of-vec-tail.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/borrowck-vec-pattern-element-loan.rs | 6 | ||||
| -rw-r--r-- | src/test/compile-fail/borrowck-vec-pattern-nesting.rs | 14 | ||||
| -rw-r--r-- | src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/macro-inner-attributes.rs | 21 | ||||
| -rw-r--r-- | src/test/compile-fail/macro-outer-attributes.rs | 19 | ||||
| -rw-r--r-- | src/test/compile-fail/match-vec-fixed.rs | 16 | ||||
| -rw-r--r-- | src/test/compile-fail/match-vec-unreachable.rs | 4 | ||||
| -rw-r--r-- | src/test/compile-fail/xc-private-method.rs | 10 | ||||
| -rw-r--r-- | src/test/run-pass/issue-3121.rs | 1 | ||||
| -rw-r--r-- | src/test/run-pass/vec-matching-autoslice.rs | 10 | ||||
| -rw-r--r-- | src/test/run-pass/vec-matching-fixed.rs | 28 | ||||
| -rw-r--r-- | src/test/run-pass/vec-matching.rs | 35 | ||||
| -rw-r--r-- | src/test/run-pass/vec-tail-matching.rs | 2 |
15 files changed, 168 insertions, 32 deletions
diff --git a/src/test/auxiliary/xc_private_method_lib.rs b/src/test/auxiliary/xc_private_method_lib.rs index 05325c3b935..8290f62bada 100644 --- a/src/test/auxiliary/xc_private_method_lib.rs +++ b/src/test/auxiliary/xc_private_method_lib.rs @@ -1,9 +1,33 @@ #[crate_type="lib"]; -pub struct Foo { +pub struct Struct { x: int } -impl Foo { - fn new() -> Foo { Foo { x: 1 } } +impl Struct { + fn static_meth_struct() -> Struct { + Struct { x: 1 } + } + + fn meth_struct(&self) -> int { + self.x + } +} + +pub enum Enum { + Variant1(int), + Variant2(int) +} + +impl Enum { + fn static_meth_enum() -> Enum { + Variant2(10) + } + + fn meth_enum(&self) -> int { + match *self { + Variant1(x) | + Variant2(x) => x + } + } } diff --git a/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs b/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs index 39a0e585ad2..0f67d8a6d0c 100644 --- a/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs +++ b/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs @@ -6,7 +6,7 @@ struct Foo { } pub fn main() { - let x = [ + let x = ~[ Foo { string: ~"foo" }, Foo { string: ~"bar" }, Foo { string: ~"baz" } diff --git a/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs b/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs index 7f98eba5996..ca20d68e4cd 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs @@ -1,5 +1,5 @@ fn a() -> &[int] { - let vec = [1, 2, 3, 4]; + let vec = ~[1, 2, 3, 4]; let tail = match vec { [_, ..tail] => tail, //~ ERROR does not live long enough _ => fail!("a") @@ -8,7 +8,7 @@ fn a() -> &[int] { } fn b() -> &[int] { - let vec = [1, 2, 3, 4]; + let vec = ~[1, 2, 3, 4]; let init = match vec { [..init, _] => init, //~ ERROR does not live long enough _ => fail!("b") @@ -17,7 +17,7 @@ fn b() -> &[int] { } fn c() -> &[int] { - let vec = [1, 2, 3, 4]; + let vec = ~[1, 2, 3, 4]; let slice = match vec { [_, ..slice, _] => slice, //~ ERROR does not live long enough _ => fail!("c") diff --git a/src/test/compile-fail/borrowck-vec-pattern-nesting.rs b/src/test/compile-fail/borrowck-vec-pattern-nesting.rs index 36ae5f88208..02ba1b9d2ff 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-nesting.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-nesting.rs @@ -1,24 +1,24 @@ fn a() { - let mut vec = [~1, ~2, ~3]; + let mut vec = ~[~1, ~2, ~3]; match vec { [~ref _a] => { - vec[0] = ~4; //~ ERROR cannot assign to `vec[]` because it is borrowed + vec[0] = ~4; //~ ERROR cannot assign to `(*vec)[]` because it is borrowed } _ => fail!("foo") } } fn b() { - let mut vec = [~1, ~2, ~3]; + let mut vec = ~[~1, ~2, ~3]; match vec { [.._b] => { - vec[0] = ~4; //~ ERROR cannot assign to `vec[]` because it is borrowed + vec[0] = ~4; //~ ERROR cannot assign to `(*vec)[]` because it is borrowed } } } fn c() { - let mut vec = [~1, ~2, ~3]; + let mut vec = ~[~1, ~2, ~3]; match vec { [_a, .._b] => { //~^ ERROR cannot move out @@ -35,7 +35,7 @@ fn c() { } fn d() { - let mut vec = [~1, ~2, ~3]; + let mut vec = ~[~1, ~2, ~3]; match vec { [.._a, _b] => { //~^ ERROR cannot move out @@ -46,7 +46,7 @@ fn d() { } fn e() { - let mut vec = [~1, ~2, ~3]; + let mut vec = ~[~1, ~2, ~3]; match vec { [_a, _b, _c] => {} _ => {} diff --git a/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs b/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs index e3e12a4a416..87511c34172 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs @@ -1,5 +1,5 @@ fn a() -> &int { - let vec = [1, 2, 3, 4]; + let vec = ~[1, 2, 3, 4]; let tail = match vec { [_a, ..tail] => &tail[0], //~ ERROR borrowed value does not live long enough _ => fail!("foo") diff --git a/src/test/compile-fail/macro-inner-attributes.rs b/src/test/compile-fail/macro-inner-attributes.rs new file mode 100644 index 00000000000..95000f4aa22 --- /dev/null +++ b/src/test/compile-fail/macro-inner-attributes.rs @@ -0,0 +1,21 @@ +macro_rules! test ( ($nm:ident, + $a:attr, + $i:item) => (mod $nm { $a; $i }); ) + +test!(a, + #[cfg(qux)], + pub fn bar() { }) + +test!(b, + #[cfg(not(qux))], + pub fn bar() { }) + +#[qux] +fn main() { + a::bar(); + //~^ ERROR use of undeclared module `a` + //~^^ ERROR unresolved name + //~^^^ ERROR unresolved name `a::bar` + b::bar(); +} + diff --git a/src/test/compile-fail/macro-outer-attributes.rs b/src/test/compile-fail/macro-outer-attributes.rs new file mode 100644 index 00000000000..23c3e80cd3b --- /dev/null +++ b/src/test/compile-fail/macro-outer-attributes.rs @@ -0,0 +1,19 @@ +macro_rules! test ( ($nm:ident, + $a:attr, + $i:item) => (mod $nm { $a $i }); ) + +test!(a, + #[cfg(qux)], + pub fn bar() { }) + +test!(b, + #[cfg(not(qux))], + pub fn bar() { }) + +// test1!(#[bar]) +#[qux] +fn main() { + a::bar(); //~ ERROR unresolved name `a::bar` + b::bar(); +} + diff --git a/src/test/compile-fail/match-vec-fixed.rs b/src/test/compile-fail/match-vec-fixed.rs new file mode 100644 index 00000000000..b3e139805a0 --- /dev/null +++ b/src/test/compile-fail/match-vec-fixed.rs @@ -0,0 +1,16 @@ +fn a() { + let v = [1, 2, 3]; + match v { + [_, _, _] => {} + [_, _, _] => {} //~ ERROR unreachable pattern + } + match v { + [_, 1, _] => {} + [_, 1, _] => {} //~ ERROR unreachable pattern + _ => {} + } +} + +fn main() { + a(); +} diff --git a/src/test/compile-fail/match-vec-unreachable.rs b/src/test/compile-fail/match-vec-unreachable.rs index 3930e7d2192..b557242af44 100644 --- a/src/test/compile-fail/match-vec-unreachable.rs +++ b/src/test/compile-fail/match-vec-unreachable.rs @@ -6,13 +6,13 @@ fn main() { _ => () } - match [~"foo", ~"bar", ~"baz"] { + match ~[~"foo", ~"bar", ~"baz"] { [a, _, _, .._] => { println(a); } [~"foo", ~"bar", ~"baz", ~"foo", ~"bar"] => { } //~ ERROR unreachable pattern _ => { } } - match ['a', 'b', 'c'] { + match ~['a', 'b', 'c'] { ['a', 'b', 'c', .._tail] => {} ['a', 'b', 'c'] => {} //~ ERROR unreachable pattern _ => {} diff --git a/src/test/compile-fail/xc-private-method.rs b/src/test/compile-fail/xc-private-method.rs index e8777a0a9f2..8314755af3b 100644 --- a/src/test/compile-fail/xc-private-method.rs +++ b/src/test/compile-fail/xc-private-method.rs @@ -4,5 +4,13 @@ extern mod xc_private_method_lib; fn main() { - let _ = xc_private_method_lib::Foo::new(); //~ ERROR function `new` is private + // normal method on struct + let _ = xc_private_method_lib::Struct{ x: 10 }.meth_struct(); //~ ERROR method `meth_struct` is private + // static method on struct + let _ = xc_private_method_lib::Struct::static_meth_struct(); //~ ERROR function `static_meth_struct` is private + + // normal method on enum + let _ = xc_private_method_lib::Variant1(20).meth_enum(); //~ ERROR method `meth_enum` is private + // static method on enum + let _ = xc_private_method_lib::Enum::static_meth_enum(); //~ ERROR function `static_meth_enum` is private } diff --git a/src/test/run-pass/issue-3121.rs b/src/test/run-pass/issue-3121.rs index 522a68856b6..206dc383cb3 100644 --- a/src/test/run-pass/issue-3121.rs +++ b/src/test/run-pass/issue-3121.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// xfail-test enum side { mayo, catsup, vinegar } enum order { hamburger, fries(side), shake } enum meal { to_go(order), for_here(order) } diff --git a/src/test/run-pass/vec-matching-autoslice.rs b/src/test/run-pass/vec-matching-autoslice.rs index d04deeac52e..13a8e324d43 100644 --- a/src/test/run-pass/vec-matching-autoslice.rs +++ b/src/test/run-pass/vec-matching-autoslice.rs @@ -1,22 +1,22 @@ pub fn main() { let x = @[1, 2, 3]; match x { - [2, .._] => ::std::util::unreachable(), + [2, .._] => fail!(), [1, ..tail] => { assert_eq!(tail, [2, 3]); } - [_] => ::std::util::unreachable(), - [] => ::std::util::unreachable() + [_] => fail!(), + [] => fail!() } let y = (~[(1, true), (2, false)], 0.5); match y { - ([_, _, _], 0.5) => ::std::util::unreachable(), + ([_, _, _], 0.5) => fail!(), ([(1, a), (b, false), ..tail], _) => { assert_eq!(a, true); assert_eq!(b, 2); assert!(tail.is_empty()); } - ([..tail], _) => ::std::util::unreachable() + ([..tail], _) => fail!() } } diff --git a/src/test/run-pass/vec-matching-fixed.rs b/src/test/run-pass/vec-matching-fixed.rs new file mode 100644 index 00000000000..234311dec33 --- /dev/null +++ b/src/test/run-pass/vec-matching-fixed.rs @@ -0,0 +1,28 @@ +fn a() { + let x = [1, 2, 3]; + match x { + [1, 2, 4] => ::std::util::unreachable(), + [0, 2, 3, .._] => ::std::util::unreachable(), + [0, .._, 3] => ::std::util::unreachable(), + [0, .._] => ::std::util::unreachable(), + [1, 2, 3] => (), + [_, _, _] => ::std::util::unreachable(), + } + match x { + [.._] => (), + } + match x { + [_, _, _, .._] => (), + } + match x { + [a, b, c] => { + assert_eq!(1, a); + assert_eq!(2, b); + assert_eq!(3, c); + } + } +} + +pub fn main() { + a(); +} diff --git a/src/test/run-pass/vec-matching.rs b/src/test/run-pass/vec-matching.rs index 5e906fa2659..c09fb8d6bc7 100644 --- a/src/test/run-pass/vec-matching.rs +++ b/src/test/run-pass/vec-matching.rs @@ -1,19 +1,19 @@ fn a() { - let x = [1]; + let x = ~[1]; match x { - [_, _, _, _, _, .._] => ::std::util::unreachable(), - [.._, _, _, _, _] => ::std::util::unreachable(), - [_, .._, _, _] => ::std::util::unreachable(), - [_, _] => ::std::util::unreachable(), + [_, _, _, _, _, .._] => fail!(), + [.._, _, _, _, _] => fail!(), + [_, .._, _, _] => fail!(), + [_, _] => fail!(), [a] => { assert_eq!(a, 1); } - [] => ::std::util::unreachable() + [] => fail!() } } fn b() { - let x = [1, 2, 3]; + let x = ~[1, 2, 3]; match x { [a, b, ..c] => { assert_eq!(a, 1); @@ -48,7 +48,28 @@ fn b() { } } +fn c() { + let x = [1]; + match x { + [2, .. _] => fail!(), + [.. _] => () + } +} + +fn d() { + let x = [1, 2, 3]; + let branch = match x { + [1, 1, .. _] => 0, + [1, 2, 3, .. _] => 1, + [1, 2, .. _] => 2, + _ => 3 + }; + assert_eq!(branch, 1); +} + pub fn main() { a(); b(); + c(); + d(); } diff --git a/src/test/run-pass/vec-tail-matching.rs b/src/test/run-pass/vec-tail-matching.rs index 27f4fc83351..6a60308f2e7 100644 --- a/src/test/run-pass/vec-tail-matching.rs +++ b/src/test/run-pass/vec-tail-matching.rs @@ -3,7 +3,7 @@ struct Foo { } pub fn main() { - let x = [ + let x = ~[ Foo { string: ~"foo" }, Foo { string: ~"bar" }, Foo { string: ~"baz" } |
