Skip to content

Commit 9d7d81f

Browse files
committed
---
yaml --- r: 141008 b: refs/heads/try2 c: 03a8e59 h: refs/heads/master v: v3
1 parent daea759 commit 9d7d81f

File tree

121 files changed

+3158
-3306
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+3158
-3306
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: 018dfaf9a6a25f5dba0ac642ff6c426c549bc4d7
8+
refs/heads/try2: 03a8e59615f7ced4def8adaad41cfcb0fd0f9d29
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/.swo

-72 KB
Binary file not shown.

branches/try2/doc/rust.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,7 @@ Supported traits for `deriving` are:
15621562

15631563
* Comparison traits: `Eq`, `TotalEq`, `Ord`, `TotalOrd`.
15641564
* Serialization: `Encodable`, `Decodable`. These require `std`.
1565-
* `Clone`, to perform deep copies.
1565+
* `Clone` and `DeepClone`, to perform (deep) copies.
15661566
* `IterBytes`, to iterate over the bytes in a data type.
15671567
* `Rand`, to create a random instance of a data type.
15681568
* `ToStr`, to convert to a string. For a type with this instance,

branches/try2/doc/tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,8 +2308,8 @@ enum ABC { A, B, C }
23082308
~~~
23092309

23102310
The full list of derivable traits is `Eq`, `TotalEq`, `Ord`,
2311-
`TotalOrd`, `Encodable` `Decodable`, `Clone`, `IterBytes`, `Rand` and
2312-
`ToStr`.
2311+
`TotalOrd`, `Encodable` `Decodable`, `Clone`, `DeepClone`,
2312+
`IterBytes`, `Rand` and `ToStr`.
23132313

23142314
# Modules and crates
23152315

branches/try2/src/etc/vim/after/syntax/rust.vim

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ syn match rustRightArrowHead contained ">" conceal cchar= 
1111
syn match rustRightArrowTail contained "-" conceal cchar=
1212
syn match rustNiceOperator "->" contains=rustRightArrowHead,rustRightArrowTail
1313

14-
syn match rustLeftRightArrowHead contained ">" conceal cchar= 
15-
syn match rustLeftRightArrowTail contained "<-" conceal cchar=
16-
syn match rustNiceOperator "<->" contains=rustLeftRightArrowHead,rustLeftRightArrowTail
17-
1814
syn match rustFatRightArrowHead contained ">" conceal cchar= 
1915
syn match rustFatRightArrowTail contained "=" conceal cchar=
2016
syn match rustNiceOperator "=>" contains=rustFatRightArrowHead,rustFatRightArrowTail

branches/try2/src/etc/vim/syntax/rust.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ syn keyword rustOperator as
1515

1616
syn keyword rustKeyword break copy do drop extern
1717
syn keyword rustKeyword for if impl let log
18-
syn keyword rustKeyword copy do drop extern
18+
syn keyword rustKeyword copy do extern
1919
syn keyword rustKeyword for impl let log
2020
syn keyword rustKeyword loop mod once priv pub
2121
syn keyword rustKeyword return
@@ -28,8 +28,8 @@ syn keyword rustStorage const mut ref static
2828
syn match rustIdentifier contains=rustIdentifierPrime "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
2929
syn match rustFuncName "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
3030

31-
" Reserved words
32-
"syn keyword rustKeyword m32 m64 m128 f80 f16 f128 be " These are obsolete
31+
" reserved
32+
syn keyword rustKeyword be
3333

3434
syn keyword rustType int uint float char bool u8 u16 u32 u64 f32
3535
syn keyword rustType f64 i8 i16 i32 i64 str Self

branches/try2/src/libcore/at_vec.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pub fn from_elem<T:Copy>(n_elts: uint, t: T) -> @[T] {
149149
* Creates and initializes an immutable managed vector by moving all the
150150
* elements from an owned vector.
151151
*/
152-
pub fn from_owned<T>(v: ~[T]) -> @[T] {
152+
pub fn to_managed_consume<T>(v: ~[T]) -> @[T] {
153153
let mut av = @[];
154154
unsafe {
155155
raw::reserve(&mut av, v.len());
@@ -164,7 +164,7 @@ pub fn from_owned<T>(v: ~[T]) -> @[T] {
164164
* Creates and initializes an immutable managed vector by copying all the
165165
* elements of a slice.
166166
*/
167-
pub fn from_slice<T:Copy>(v: &[T]) -> @[T] {
167+
pub fn to_managed<T:Copy>(v: &[T]) -> @[T] {
168168
from_fn(v.len(), |i| v[i])
169169
}
170170

@@ -304,20 +304,20 @@ mod test {
304304
}
305305

306306
#[test]
307-
fn test_from_owned() {
308-
assert!(from_owned::<int>(~[]) == @[]);
309-
assert!(from_owned(~[true]) == @[true]);
310-
assert!(from_owned(~[1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
311-
assert!(from_owned(~[~"abc", ~"123"]) == @[~"abc", ~"123"]);
312-
assert!(from_owned(~[~[42]]) == @[~[42]]);
307+
fn test_to_managed_consume() {
308+
assert!(to_managed_consume::<int>(~[]) == @[]);
309+
assert!(to_managed_consume(~[true]) == @[true]);
310+
assert!(to_managed_consume(~[1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
311+
assert!(to_managed_consume(~[~"abc", ~"123"]) == @[~"abc", ~"123"]);
312+
assert!(to_managed_consume(~[~[42]]) == @[~[42]]);
313313
}
314314
315315
#[test]
316-
fn test_from_slice() {
317-
assert!(from_slice::<int>([]) == @[]);
318-
assert!(from_slice([true]) == @[true]);
319-
assert!(from_slice([1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
320-
assert!(from_slice([@"abc", @"123"]) == @[@"abc", @"123"]);
321-
assert!(from_slice([@[42]]) == @[@[42]]);
316+
fn test_to_managed() {
317+
assert!(to_managed::<int>([]) == @[]);
318+
assert!(to_managed([true]) == @[true]);
319+
assert!(to_managed([1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]);
320+
assert!(to_managed([@"abc", @"123"]) == @[@"abc", @"123"]);
321+
assert!(to_managed([@[42]]) == @[@[42]]);
322322
}
323323
}

branches/try2/src/libcore/cell.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@ Similar to a mutable option type, but friendlier.
2121
*/
2222

2323
#[mutable]
24+
#[deriving(Clone)]
2425
pub struct Cell<T> {
2526
priv value: Option<T>
2627
}
2728

29+
impl<T: DeepClone> DeepClone for Cell<T> {
30+
fn deep_clone(&self) -> Cell<T> {
31+
Cell{value: self.value.deep_clone()}
32+
}
33+
}
34+
2835
impl<T:cmp::Eq> cmp::Eq for Cell<T> {
2936
fn eq(&self, other: &Cell<T>) -> bool {
3037
(self.value) == (other.value)

branches/try2/src/libcore/clone.rs

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,15 @@ by convention implementing the `Clone` trait and calling the
2222
2323
*/
2424

25+
use core::kinds::Const;
26+
2527
pub trait Clone {
26-
/// Return a deep copy of the owned object tree. Managed boxes are cloned with a shallow copy.
28+
/// Return a deep copy of the owned object tree. Types with shared ownership like managed boxes
29+
/// are cloned with a shallow copy.
2730
fn clone(&self) -> Self;
2831
}
2932

30-
impl Clone for () {
31-
/// Return a copy of the value.
32-
#[inline(always)]
33-
fn clone(&self) -> () { () }
34-
}
35-
36-
impl<T:Clone> Clone for ~T {
33+
impl<T: Clone> Clone for ~T {
3734
/// Return a deep copy of the owned box.
3835
#[inline(always)]
3936
fn clone(&self) -> ~T { ~(**self).clone() }
@@ -51,10 +48,16 @@ impl<T> Clone for @mut T {
5148
fn clone(&self) -> @mut T { *self }
5249
}
5350

51+
impl<'self, T> Clone for &'self T {
52+
/// Return a shallow copy of the borrowed pointer.
53+
#[inline(always)]
54+
fn clone(&self) -> &'self T { *self }
55+
}
56+
5457
macro_rules! clone_impl(
5558
($t:ty) => {
5659
impl Clone for $t {
57-
/// Return a copy of the value.
60+
/// Return a deep copy of the value.
5861
#[inline(always)]
5962
fn clone(&self) -> $t { *self }
6063
}
@@ -77,28 +80,103 @@ clone_impl!(float)
7780
clone_impl!(f32)
7881
clone_impl!(f64)
7982

83+
clone_impl!(())
8084
clone_impl!(bool)
8185
clone_impl!(char)
8286

87+
pub trait DeepClone {
88+
/// Return a deep copy of the object tree. Types with shared ownership are also copied via a
89+
/// deep copy, unlike `Clone`.
90+
fn deep_clone(&self) -> Self;
91+
}
92+
93+
impl<T: DeepClone> DeepClone for ~T {
94+
/// Return a deep copy of the owned box.
95+
#[inline(always)]
96+
fn deep_clone(&self) -> ~T { ~(**self).deep_clone() }
97+
}
98+
99+
// FIXME: #6525: should also be implemented for `T: Owned + DeepClone`
100+
impl<T: Const + DeepClone> DeepClone for @T {
101+
/// Return a deep copy of the managed box. The `Const` trait is required to prevent performing
102+
/// a deep clone of a potentially cyclical type.
103+
#[inline(always)]
104+
fn deep_clone(&self) -> @T { @(**self).deep_clone() }
105+
}
106+
107+
// FIXME: #6525: should also be implemented for `T: Owned + DeepClone`
108+
impl<T: Const + DeepClone> DeepClone for @mut T {
109+
/// Return a deep copy of the managed box. The `Const` trait is required to prevent performing
110+
/// a deep clone of a potentially cyclical type.
111+
#[inline(always)]
112+
fn deep_clone(&self) -> @mut T { @mut (**self).deep_clone() }
113+
}
114+
115+
macro_rules! deep_clone_impl(
116+
($t:ty) => {
117+
impl DeepClone for $t {
118+
/// Return a deep copy of the value.
119+
#[inline(always)]
120+
fn deep_clone(&self) -> $t { *self }
121+
}
122+
}
123+
)
124+
125+
deep_clone_impl!(int)
126+
deep_clone_impl!(i8)
127+
deep_clone_impl!(i16)
128+
deep_clone_impl!(i32)
129+
deep_clone_impl!(i64)
130+
131+
deep_clone_impl!(uint)
132+
deep_clone_impl!(u8)
133+
deep_clone_impl!(u16)
134+
deep_clone_impl!(u32)
135+
deep_clone_impl!(u64)
136+
137+
deep_clone_impl!(float)
138+
deep_clone_impl!(f32)
139+
deep_clone_impl!(f64)
140+
141+
deep_clone_impl!(())
142+
deep_clone_impl!(bool)
143+
deep_clone_impl!(char)
144+
83145
#[test]
84146
fn test_owned_clone() {
85-
let a: ~int = ~5i;
147+
let a = ~5i;
86148
let b: ~int = a.clone();
87149
assert!(a == b);
88150
}
89151

90152
#[test]
91153
fn test_managed_clone() {
92-
let a: @int = @5i;
154+
let a = @5i;
93155
let b: @int = a.clone();
94156
assert!(a == b);
95157
}
96158

159+
#[test]
160+
fn test_managed_mut_deep_clone() {
161+
let x = @mut 5i;
162+
let y: @mut int = x.deep_clone();
163+
*x = 20;
164+
assert_eq!(*y, 5);
165+
}
166+
97167
#[test]
98168
fn test_managed_mut_clone() {
99-
let a: @mut int = @mut 5i;
169+
let a = @mut 5i;
100170
let b: @mut int = a.clone();
101171
assert!(a == b);
102172
*b = 10;
103173
assert!(a == b);
104174
}
175+
176+
#[test]
177+
fn test_borrowed_clone() {
178+
let x = 5i;
179+
let y: &int = &x;
180+
let z: &int = (&y).clone();
181+
assert_eq!(*z, 5);
182+
}

branches/try2/src/libcore/hashmap.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use container::{Container, Mutable, Map, Set};
1717
use cmp::{Eq, Equiv};
1818
use hash::Hash;
1919
use old_iter::BaseIter;
20-
use hash::Hash;
2120
use old_iter;
2221
use option::{None, Option, Some};
2322
use rand::RngUtil;
@@ -825,6 +824,10 @@ pub impl <T:Hash + Eq> HashSet<T> {
825824
fn consume(&mut self, f: &fn(T)) {
826825
self.map.consume(|k, _| f(k))
827826
}
827+
828+
fn contains_equiv<Q:Hash + Equiv<T>>(&self, value: &Q) -> bool {
829+
self.map.contains_key_equiv(value)
830+
}
828831
}
829832

830833
#[cfg(test)]

0 commit comments

Comments
 (0)