Skip to content

Commit 73e6b27

Browse files
committed
---
yaml --- r: 152638 b: refs/heads/try2 c: 373b0fc h: refs/heads/master v: v3
1 parent ab4e029 commit 73e6b27

File tree

4 files changed

+109
-1
lines changed

4 files changed

+109
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 95fdbeee48163691cf66de4a53fdc108157babcf
8+
refs/heads/try2: 373b0fc56905c17d14438446e16712bf714c6f08
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2012-2014 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+
struct S;
12+
// Ensure S is moved, not copied, on assignment.
13+
impl Drop for S { fn drop(&mut self) { } }
14+
15+
// user-defined function "returning" bottom (i.e. no return at all).
16+
fn my_fail() -> ! { loop {} }
17+
18+
pub fn step(f: bool) {
19+
let mut g = S;
20+
let mut i = 0;
21+
loop
22+
{
23+
if i > 10 { break; } else { i += 1; }
24+
25+
let _g = g;
26+
27+
if f {
28+
// re-initialize g, but only before restarting loop.
29+
g = S;
30+
continue;
31+
}
32+
33+
my_fail();
34+
35+
// we never get here, so we do not need to re-initialize g.
36+
}
37+
}
38+
39+
pub fn main() {
40+
step(true);
41+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2012 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+
#[deriving(PartialEq, Show)]
12+
struct Partial<T> { x: T, y: T }
13+
14+
#[deriving(PartialEq, Show)]
15+
struct S { val: int }
16+
impl S { fn new(v: int) -> S { S { val: v } } }
17+
impl Drop for S { fn drop(&mut self) { } }
18+
19+
pub fn f<T>((b1, b2): (T, T), f: |T| -> T) -> Partial<T> {
20+
let p = Partial { x: b1, y: b2 };
21+
22+
// Move of `p` is legal even though we are also moving `p.y`; the
23+
// `..p` moves all fields *except* `p.y` in this context.
24+
Partial { y: f(p.y), ..p }
25+
}
26+
27+
pub fn main() {
28+
let p = f((S::new(3), S::new(4)), |S { val: z }| S::new(z+1));
29+
assert_eq!(p, Partial { x: S::new(3), y: S::new(5) });
30+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2012 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+
#[deriving(PartialEq, Show)]
12+
struct Partial<T> { x: T, y: T }
13+
14+
#[deriving(PartialEq, Show)]
15+
struct S { val: int }
16+
impl S { fn new(v: int) -> S { S { val: v } } }
17+
impl Drop for S { fn drop(&mut self) { } }
18+
19+
type Two<T> = (Partial<T>, Partial<T>);
20+
21+
pub fn f<T>((b1, b2): (T, T), (b3, b4): (T, T), f: |T| -> T) -> Two<T> {
22+
let p = Partial { x: b1, y: b2 };
23+
let q = Partial { x: b3, y: b4 };
24+
25+
// Move of `q` is legal even though we have already moved `q.y`;
26+
// the `..q` moves all fields *except* `q.y` in this context.
27+
// Likewise, the move of `p.x` is legal for similar reasons.
28+
(Partial { x: f(q.y), ..p }, Partial { y: f(p.x), ..q })
29+
}
30+
31+
pub fn main() {
32+
let two = f((S::new(1), S::new(3)),
33+
(S::new(5), S::new(7)),
34+
|S { val: z }| S::new(z+1));
35+
assert_eq!(two, (Partial { x: S::new(8), y: S::new(3) },
36+
Partial { x: S::new(5), y: S::new(2) }));
37+
}

0 commit comments

Comments
 (0)