Skip to content

Commit 28af67e

Browse files
committed
---
yaml --- r: 186347 b: refs/heads/try c: ce341f7 h: refs/heads/master i: 186345: d18988e 186343: f870e93 v: v3
1 parent 5bc88e9 commit 28af67e

File tree

4 files changed

+92
-1
lines changed

4 files changed

+92
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: b4c965ee803a4521d8b4575f634e036f93e408f3
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 3a96d6a9818fe2affc98a187fb1065120458cee9
5-
refs/heads/try: cc8f35f874c81be1a5950d2527902b7dd5a94513
5+
refs/heads/try: ce341f79b49f2b141da608cf53c6b34c11a6d29a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Ensure that we cannot move out of a fixed-size array (especially
12+
// when the element type has a destructor).
13+
14+
15+
struct D { _x: u8 }
16+
17+
impl Drop for D { fn drop(&mut self) { } }
18+
19+
fn main() {
20+
fn d() -> D { D { _x: 0 } }
21+
22+
let _d1 = foo([d(), d(), d(), d()], 1);
23+
let _d3 = foo([d(), d(), d(), d()], 3);
24+
}
25+
26+
fn foo(a: [D; 4], i: usize) -> D {
27+
a[i] //~ ERROR cannot move out of type `[D; 4]`
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Ensure that we can copy out of a fixed-size array.
12+
//
13+
// (Compare with compile-fail/move-out-of-array-1.rs)
14+
15+
struct C { _x: u8 }
16+
17+
impl Copy for C { }
18+
19+
fn main() {
20+
fn d() -> C { C { _x: 0 } }
21+
22+
let _d1 = foo([d(), d(), d(), d()], 1);
23+
let _d3 = foo([d(), d(), d(), d()], 3);
24+
}
25+
26+
fn foo(a: [C; 4], i: usize) -> C {
27+
a[i]
28+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Ensure that we can do a destructuring bind of a fixed-size array,
12+
// even when the element type has a destructor.
13+
14+
struct D { x: u8 }
15+
16+
impl Drop for D { fn drop(&mut self) { } }
17+
18+
fn main() {
19+
fn d(x: u8) -> D { D { x: x } }
20+
21+
let d1 = foo([d(1), d(2), d(3), d(4)], 1);
22+
let d3 = foo([d(5), d(6), d(7), d(8)], 3);
23+
assert_eq!(d1.x, 2);
24+
assert_eq!(d3.x, 8);
25+
}
26+
27+
fn foo([a, b, c, d]: [D; 4], i: usize) -> D {
28+
match i {
29+
0 => a,
30+
1 => b,
31+
2 => c,
32+
3 => d,
33+
_ => panic!("unmatched"),
34+
}
35+
}

0 commit comments

Comments
 (0)