Skip to content

Commit 432c568

Browse files
committed
---
yaml --- r: 80988 b: refs/heads/snap-stage3 c: db78fdc h: refs/heads/master v: v3
1 parent 9193ad1 commit 432c568

File tree

7 files changed

+153
-7
lines changed

7 files changed

+153
-7
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 4c6bf4872012c010f84dc7fa2cdfe87522533f89
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 4fd061c426902b0904c65e64a3780b21f9ab3afb
4+
refs/heads/snap-stage3: db78fdc10c0cf6c02005c0b8daefe9cf47aa806f
55
refs/heads/try: 70152ff55722878cde684ee6462c14c65f2c4729
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[attr]rust text eol=lf whitespace=tab-in-indent,trailing-space,tabwidth=4
22

3-
* text eol=lf
3+
* text=auto eol=lf
44
*.cpp rust
55
*.h rust
66
*.rs rust

branches/snap-stage3/RELEASES.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Version 0.8 (October 2013)
66
* Language
77
* The `for` loop syntax has changed to work with the `Iterator` trait.
88
* At long last, unwinding works on Windows.
9-
* Default methods definitely mostly work.
9+
* Default methods are ready for use.
1010
* Many trait inheritance bugs fixed.
1111
* Owned and borrowed trait objects work more reliably.
1212
* `copy` is no longer a keyword. It has been replaced by the `Clone` trait.
@@ -56,7 +56,7 @@ Version 0.8 (October 2013)
5656
be specified with `#[link_section = "..."]`.
5757
* The `proto!` syntax extension for defining bounded message protocols
5858
was removed.
59-
* `macro_rules!` is hygenic for `let` declarations.
59+
* `macro_rules!` is hygienic for `let` declarations.
6060
* The `#[export_name]` attribute specifies the name of a symbol.
6161
* `unreachable!` can be used to indicate unreachable code, and fails
6262
if executed.
@@ -92,7 +92,7 @@ Version 0.8 (October 2013)
9292
* std: Added `SharedPort` to `comm`.
9393
* std: `Eq` has a default method for `ne`; only `eq` is required
9494
in implementations.
95-
* std: `Ord` has default methods for `le`, `gt` and `le`; only `lt`
95+
* std: `Ord` has default methods for `le`, `gt` and `ge`; only `lt`
9696
is required in implementations.
9797
* std: `is_utf8` performance is improved, impacting many string functions.
9898
* std: `os::MemoryMap` provides cross-platform mmap.
@@ -130,6 +130,7 @@ Version 0.8 (October 2013)
130130
* rustc's debug info generation (`-Z debug-info`) is greatly improved.
131131
* rustc accepts `--target-cpu` to compile to a specific CPU architecture,
132132
similarly to gcc's `--march` flag.
133+
* rustc's performance compiling small crates is much better.
133134
* rustpkg has received many improvements.
134135
* rustpkg supports git tags as package IDs.
135136
* rustpkg builds into target-specific directories so it can be used for

branches/snap-stage3/src/librustc/middle/moves.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ use middle::typeck::{method_map};
134134
use util::ppaux;
135135
use util::ppaux::Repr;
136136
use util::common::indenter;
137+
use util::ppaux::UserString;
137138

138139
use std::at_vec;
139140
use std::hashmap::{HashSet, HashMap};
@@ -433,7 +434,21 @@ impl VisitContext {
433434
ty::type_moves_by_default(self.tcx, tf.mt.ty)
434435
});
435436

437+
fn has_dtor(tcx: ty::ctxt, ty: ty::t) -> bool {
438+
use middle::ty::{get,ty_struct,ty_enum};
439+
match get(ty).sty {
440+
ty_struct(did, _) | ty_enum(did, _) => ty::has_dtor(tcx, did),
441+
_ => false,
442+
}
443+
}
444+
436445
if consume_with {
446+
if has_dtor(self.tcx, with_ty) {
447+
self.tcx.sess.span_err(with_expr.span,
448+
fmt!("cannot move out of type `%s`, \
449+
which defines the `Drop` trait",
450+
with_ty.user_string(self.tcx)));
451+
}
437452
self.consume_expr(*with_expr, visitor);
438453
} else {
439454
self.use_expr(*with_expr, Read, visitor);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2012-2013 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+
// Issue 4691: Ensure that functional-struct-update can only copy, not
12+
// move, when the struct implements Drop.
13+
14+
use NC = std::util::NonCopyable;
15+
struct S { a: int, nc: NC }
16+
impl Drop for S { fn drop(&mut self) { } }
17+
18+
struct T { a: int, mv: ~int }
19+
impl Drop for T { fn drop(&mut self) { } }
20+
21+
fn f(s0:S) {
22+
let _s2 = S{a: 2, ..s0}; //~error: cannot move out of type `S`, which defines the `Drop` trait
23+
}
24+
25+
fn g(s0:T) {
26+
let _s2 = T{a: 2, ..s0}; //~error: cannot move out of type `T`, which defines the `Drop` trait
27+
}
28+
29+
fn main() { }

branches/snap-stage3/src/test/compile-fail/functional-struct-update-noncopyable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ impl Drop for A {
2121
}
2222
fn main() {
2323
let a = A { y: Arc::new(1), x: Arc::new(2) };
24-
let _b = A { y: Arc::new(3), ..a };
25-
let _c = a; //~ ERROR use of moved value
24+
let _b = A { y: Arc::new(3), ..a }; //~ ERROR cannot move out of type `A`
25+
let _c = a;
2626
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// Copyright 2012-2013 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+
// Issue 4691: Ensure that functional-struct-updates operates
12+
// correctly and moves rather than copy when appropriate.
13+
14+
use NC = std::util::NonCopyable;
15+
16+
struct ncint { nc: NC, v: int }
17+
fn ncint(v: int) -> ncint { ncint { nc: NC, v: v } }
18+
19+
struct NoFoo { copied: int, noncopy: ncint, }
20+
impl NoFoo {
21+
fn new(x:int,y:int) -> NoFoo { NoFoo { copied: x, noncopy: ncint(y) } }
22+
}
23+
24+
struct MoveFoo { copied: int, moved: ~int, }
25+
impl MoveFoo {
26+
fn new(x:int,y:int) -> MoveFoo { MoveFoo { copied: x, moved: ~y } }
27+
}
28+
29+
struct DropNoFoo { inner: NoFoo }
30+
impl DropNoFoo {
31+
fn new(x:int,y:int) -> DropNoFoo { DropNoFoo { inner: NoFoo::new(x,y) } }
32+
}
33+
impl Drop for DropNoFoo { fn drop(&mut self) { } }
34+
35+
struct DropMoveFoo { inner: MoveFoo }
36+
impl DropMoveFoo {
37+
fn new(x:int,y:int) -> DropMoveFoo { DropMoveFoo { inner: MoveFoo::new(x,y) } }
38+
}
39+
impl Drop for DropMoveFoo { fn drop(&mut self) { } }
40+
41+
42+
fn test0() {
43+
// just copy implicitly copyable fields from `f`, no moves
44+
// (and thus it is okay that these are Drop; compare against
45+
// compile-fail test: borrowck-struct-update-with-dtor.rs).
46+
47+
// Case 1: NonCopyable
48+
let f = DropNoFoo::new(1, 2);
49+
let b = DropNoFoo { inner: NoFoo { noncopy: ncint(3), ..f.inner }};
50+
let c = DropNoFoo { inner: NoFoo { noncopy: ncint(4), ..f.inner }};
51+
assert_eq!(f.inner.copied, 1);
52+
assert_eq!(f.inner.noncopy.v, 2);
53+
54+
assert_eq!(b.inner.copied, 1);
55+
assert_eq!(b.inner.noncopy.v, 3);
56+
57+
assert_eq!(c.inner.copied, 1);
58+
assert_eq!(c.inner.noncopy.v, 4);
59+
60+
// Case 2: Owned
61+
let f = DropMoveFoo::new(5, 6);
62+
let b = DropMoveFoo { inner: MoveFoo { moved: ~7, ..f.inner }};
63+
let c = DropMoveFoo { inner: MoveFoo { moved: ~8, ..f.inner }};
64+
assert_eq!(f.inner.copied, 5);
65+
assert_eq!(*f.inner.moved, 6);
66+
67+
assert_eq!(b.inner.copied, 5);
68+
assert_eq!(*b.inner.moved, 7);
69+
70+
assert_eq!(c.inner.copied, 5);
71+
assert_eq!(*c.inner.moved, 8);
72+
}
73+
74+
fn test1() {
75+
// copying move-by-default fields from `f`, so it moves:
76+
let f = MoveFoo::new(11, 12);
77+
78+
let b = MoveFoo {moved: ~13, ..f};
79+
let c = MoveFoo {copied: 14, ..f};
80+
assert_eq!(b.copied, 11);
81+
assert_eq!(*b.moved, 13);
82+
assert_eq!(c.copied, 14);
83+
assert_eq!(*c.moved, 12);
84+
}
85+
86+
fn test2() {
87+
// move non-copyable field
88+
let f = NoFoo::new(21, 22);
89+
let b = NoFoo {noncopy: ncint(23), ..f};
90+
let c = NoFoo {copied: 24, ..f};
91+
assert_eq!(b.copied, 21);
92+
assert_eq!(b.noncopy.v, 23);
93+
assert_eq!(c.copied, 24);
94+
assert_eq!(c.noncopy.v, 22);
95+
}
96+
97+
fn main() {
98+
test0();
99+
test1();
100+
test2();
101+
}

0 commit comments

Comments
 (0)