Skip to content

Commit 89db01d

Browse files
committed
---
yaml --- r: 187830 b: refs/heads/tmp c: b47aebe h: refs/heads/master v: v3
1 parent bfb8428 commit 89db01d

File tree

10 files changed

+166
-32
lines changed

10 files changed

+166
-32
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3434
refs/heads/beta: 522d09dfecbeca1595f25ac58c6d0178bbd21d7d
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
37-
refs/heads/tmp: 653ceee3b3a777ea452e718835e0b27cf369906c
37+
refs/heads/tmp: b47aebe3fc2da06c760fd8ea19f84cbc41d34831
3838
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/tmp/src/libcollections/btree/node.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ impl<K, V> Node<K, V> {
10851085
vals: RawItems::from_slice(self.vals()),
10861086
edges: RawItems::from_slice(self.edges()),
10871087

1088-
ptr: *self.keys as *mut u8,
1088+
ptr: Unique::new(*self.keys as *mut u8),
10891089
capacity: self.capacity(),
10901090
is_leaf: self.is_leaf()
10911091
},
@@ -1354,11 +1354,14 @@ struct MoveTraversalImpl<K, V> {
13541354
edges: RawItems<Node<K, V>>,
13551355

13561356
// For deallocation when we are done iterating.
1357-
ptr: *mut u8,
1357+
ptr: Unique<u8>,
13581358
capacity: usize,
13591359
is_leaf: bool
13601360
}
13611361

1362+
unsafe impl<K: Sync, V: Sync> Sync for MoveTraversalImpl<K, V> {}
1363+
unsafe impl<K: Send, V: Send> Send for MoveTraversalImpl<K, V> {}
1364+
13621365
impl<K, V> TraversalImpl for MoveTraversalImpl<K, V> {
13631366
type Item = (K, V);
13641367
type Edge = Node<K, V>;
@@ -1401,7 +1404,7 @@ impl<K, V> Drop for MoveTraversalImpl<K, V> {
14011404

14021405
let (alignment, size) =
14031406
calculate_allocation_generic::<K, V>(self.capacity, self.is_leaf);
1404-
unsafe { heap::deallocate(self.ptr, size, alignment) };
1407+
unsafe { heap::deallocate(*self.ptr, size, alignment) };
14051408
}
14061409
}
14071410

@@ -1425,12 +1428,12 @@ pub enum TraversalItem<K, V, E> {
14251428
/// A traversal over a node's entries and edges
14261429
pub type Traversal<'a, K, V> = AbsTraversal<ElemsAndEdges<Zip<slice::Iter<'a, K>,
14271430
slice::Iter<'a, V>>,
1428-
slice::Iter<'a, Node<K, V>>>>;
1431+
slice::Iter<'a, Node<K, V>>>>;
14291432

14301433
/// A mutable traversal over a node's entries and edges
14311434
pub type MutTraversal<'a, K, V> = AbsTraversal<ElemsAndEdges<Zip<slice::Iter<'a, K>,
14321435
slice::IterMut<'a, V>>,
1433-
slice::IterMut<'a, Node<K, V>>>>;
1436+
slice::IterMut<'a, Node<K, V>>>>;
14341437

14351438
/// An owning traversal over a node's entries and edges
14361439
pub type MoveTraversal<K, V> = AbsTraversal<MoveTraversalImpl<K, V>>;

branches/tmp/src/libcollections/linked_list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ struct Rawlink<T> {
5151
}
5252

5353
impl<T> Copy for Rawlink<T> {}
54-
unsafe impl<T:'static+Send> Send for Rawlink<T> {}
55-
unsafe impl<T:Send+Sync> Sync for Rawlink<T> {}
54+
unsafe impl<T:Send> Send for Rawlink<T> {}
55+
unsafe impl<T:Sync> Sync for Rawlink<T> {}
5656

5757
struct Node<T> {
5858
next: Link<T>,

branches/tmp/src/libcollections/vec.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,6 +1755,9 @@ pub struct Drain<'a, T:'a> {
17551755
marker: PhantomData<&'a T>,
17561756
}
17571757

1758+
unsafe impl<'a, T: Sync> Sync for Drain<'a, T> {}
1759+
unsafe impl<'a, T: Send> Send for Drain<'a, T> {}
1760+
17581761
#[stable(feature = "rust1", since = "1.0.0")]
17591762
impl<'a, T> Iterator for Drain<'a, T> {
17601763
type Item = T;

branches/tmp/src/libcollections/vec_deque.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use core::cmp::Ordering;
2424
use core::default::Default;
2525
use core::fmt;
2626
use core::iter::{self, repeat, FromIterator, IntoIterator, RandomAccessIterator};
27-
use core::marker;
2827
use core::mem;
2928
use core::num::{Int, UnsignedInt};
3029
use core::ops::{Index, IndexMut};
@@ -59,12 +58,6 @@ pub struct VecDeque<T> {
5958
ptr: Unique<T>,
6059
}
6160

62-
#[stable(feature = "rust1", since = "1.0.0")]
63-
unsafe impl<T: Send> Send for VecDeque<T> {}
64-
65-
#[stable(feature = "rust1", since = "1.0.0")]
66-
unsafe impl<T: Sync> Sync for VecDeque<T> {}
67-
6861
#[stable(feature = "rust1", since = "1.0.0")]
6962
impl<T: Clone> Clone for VecDeque<T> {
7063
fn clone(&self) -> VecDeque<T> {
@@ -545,9 +538,7 @@ impl<T> VecDeque<T> {
545538
IterMut {
546539
tail: self.tail,
547540
head: self.head,
548-
cap: self.cap,
549-
ptr: *self.ptr,
550-
marker: marker::PhantomData,
541+
ring: unsafe { self.buffer_as_mut_slice() },
551542
}
552543
}
553544

@@ -1515,17 +1506,12 @@ impl<'a, T> RandomAccessIterator for Iter<'a, T> {
15151506
}
15161507
}
15171508

1518-
// FIXME This was implemented differently from Iter because of a problem
1519-
// with returning the mutable reference. I couldn't find a way to
1520-
// make the lifetime checker happy so, but there should be a way.
15211509
/// `VecDeque` mutable iterator.
15221510
#[stable(feature = "rust1", since = "1.0.0")]
15231511
pub struct IterMut<'a, T:'a> {
1524-
ptr: *mut T,
1512+
ring: &'a mut [T],
15251513
tail: usize,
15261514
head: usize,
1527-
cap: usize,
1528-
marker: marker::PhantomData<&'a mut T>,
15291515
}
15301516

15311517
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1538,16 +1524,17 @@ impl<'a, T> Iterator for IterMut<'a, T> {
15381524
return None;
15391525
}
15401526
let tail = self.tail;
1541-
self.tail = wrap_index(self.tail + 1, self.cap);
1527+
self.tail = wrap_index(self.tail + 1, self.ring.len());
15421528

15431529
unsafe {
1544-
Some(&mut *self.ptr.offset(tail as isize))
1530+
let elem = self.ring.get_unchecked_mut(tail);
1531+
Some(&mut *(elem as *mut _))
15451532
}
15461533
}
15471534

15481535
#[inline]
15491536
fn size_hint(&self) -> (usize, Option<usize>) {
1550-
let len = count(self.tail, self.head, self.cap);
1537+
let len = count(self.tail, self.head, self.ring.len());
15511538
(len, Some(len))
15521539
}
15531540
}
@@ -1559,10 +1546,11 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
15591546
if self.tail == self.head {
15601547
return None;
15611548
}
1562-
self.head = wrap_index(self.head - 1, self.cap);
1549+
self.head = wrap_index(self.head - 1, self.ring.len());
15631550

15641551
unsafe {
1565-
Some(&mut *self.ptr.offset(self.head as isize))
1552+
let elem = self.ring.get_unchecked_mut(self.head);
1553+
Some(&mut *(elem as *mut _))
15661554
}
15671555
}
15681556
}

branches/tmp/src/libcore/iter.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use num::{ToPrimitive, Int};
6868
use ops::{Add, Deref, FnMut};
6969
use option::Option;
7070
use option::Option::{Some, None};
71-
use marker::Sized;
71+
use marker::{Send, Sized, Sync};
7272
use usize;
7373

7474
/// An interface for dealing with "external iterators". These types of iterators
@@ -1786,6 +1786,10 @@ pub struct Peekable<I: Iterator> {
17861786
peeked: Option<I::Item>,
17871787
}
17881788

1789+
// FIXME: after #22828 being fixed, the following unsafe impl should be removed
1790+
unsafe impl<I: Iterator> Sync for Peekable<I> where I: Sync, I::Item: Sync {}
1791+
unsafe impl<I: Iterator> Send for Peekable<I> where I: Send, I::Item: Send {}
1792+
17891793
impl<I: Iterator + Clone> Clone for Peekable<I> where I::Item: Clone {
17901794
fn clone(&self) -> Peekable<I> {
17911795
Peekable {

branches/tmp/src/libcore/slice.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use ptr;
5151
use ptr::PtrExt;
5252
use mem;
5353
use mem::size_of;
54-
use marker::{Sized, self};
54+
use marker::{Send, Sized, Sync, self};
5555
use raw::Repr;
5656
// Avoid conflicts with *both* the Slice trait (buggy) and the `slice::raw` module.
5757
use raw::Slice as RawSlice;
@@ -740,6 +740,9 @@ pub struct Iter<'a, T: 'a> {
740740
_marker: marker::PhantomData<&'a T>,
741741
}
742742

743+
unsafe impl<'a, T: Sync> Sync for Iter<'a, T> {}
744+
unsafe impl<'a, T: Sync> Send for Iter<'a, T> {}
745+
743746
#[unstable(feature = "core")]
744747
impl<'a, T> ops::Index<ops::Range<usize>> for Iter<'a, T> {
745748
type Output = [T];
@@ -830,6 +833,8 @@ pub struct IterMut<'a, T: 'a> {
830833
_marker: marker::PhantomData<&'a mut T>,
831834
}
832835

836+
unsafe impl<'a, T: Sync> Sync for IterMut<'a, T> {}
837+
unsafe impl<'a, T: Send> Send for IterMut<'a, T> {}
833838

834839
#[unstable(feature = "core")]
835840
impl<'a, T> ops::Index<ops::Range<usize>> for IterMut<'a, T> {

branches/tmp/src/libstd/path.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
use core::prelude::*;
109109

110110
use ascii::*;
111-
use borrow::{Borrow, ToOwned, Cow};
111+
use borrow::{Borrow, IntoCow, ToOwned, Cow};
112112
use cmp;
113113
use iter::{self, IntoIterator};
114114
use mem;
@@ -987,6 +987,18 @@ impl Borrow<Path> for PathBuf {
987987
}
988988
}
989989

990+
impl IntoCow<'static, Path> for PathBuf {
991+
fn into_cow(self) -> Cow<'static, Path> {
992+
Cow::Owned(self)
993+
}
994+
}
995+
996+
impl<'a> IntoCow<'a, Path> for &'a Path {
997+
fn into_cow(self) -> Cow<'a, Path> {
998+
Cow::Borrowed(self)
999+
}
1000+
}
1001+
9901002
impl ToOwned for Path {
9911003
type Owned = PathBuf;
9921004
fn to_owned(&self) -> PathBuf { self.to_path_buf() }
@@ -1411,6 +1423,26 @@ mod tests {
14111423
);
14121424
);
14131425

1426+
#[test]
1427+
fn into_cow() {
1428+
use borrow::{Cow, IntoCow};
1429+
1430+
let static_path = Path::new("/home/foo");
1431+
let static_cow_path: Cow<'static, Path> = static_path.into_cow();
1432+
let pathbuf = PathBuf::new("/home/foo");
1433+
1434+
{
1435+
let path: &Path = &pathbuf;
1436+
let borrowed_cow_path: Cow<Path> = path.into_cow();
1437+
1438+
assert_eq!(static_cow_path, borrowed_cow_path);
1439+
}
1440+
1441+
let owned_cow_path: Cow<'static, Path> = pathbuf.into_cow();
1442+
1443+
assert_eq!(static_cow_path, owned_cow_path);
1444+
}
1445+
14141446
#[test]
14151447
#[cfg(unix)]
14161448
pub fn test_decompositions_unix() {

branches/tmp/src/libsyntax/feature_gate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ pub static KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
187187
("no_link", Normal),
188188
("derive", Normal),
189189
("should_fail", Normal),
190+
("should_panic", Normal),
190191
("ignore", Normal),
191192
("no_implicit_prelude", Normal),
192193
("reexport_test_harness_main", Normal),
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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+
#![allow(unused_mut)]
12+
#![feature(collections)]
13+
14+
extern crate collections;
15+
16+
use collections::BinaryHeap;
17+
use collections::{BitSet, BitVec};
18+
use collections::{BTreeMap, BTreeSet};
19+
use collections::EnumSet;
20+
use collections::LinkedList;
21+
use collections::Vec;
22+
use collections::VecDeque;
23+
use collections::VecMap;
24+
25+
use collections::Bound::Included;
26+
use collections::enum_set::CLike;
27+
use std::mem;
28+
29+
fn is_sync<T>(_: T) where T: Sync {}
30+
fn is_send<T>(_: T) where T: Send {}
31+
32+
macro_rules! all_sync_send {
33+
($ctor:expr, $($iter:ident),+) => ({
34+
$(
35+
let mut x = $ctor;
36+
is_sync(x.$iter());
37+
let mut y = $ctor;
38+
is_send(y.$iter());
39+
)+
40+
})
41+
}
42+
43+
macro_rules! is_sync_send {
44+
($ctor:expr, $iter:ident($($param:expr),+)) => ({
45+
let mut x = $ctor;
46+
is_sync(x.$iter($( $param ),+));
47+
let mut y = $ctor;
48+
is_send(y.$iter($( $param ),+));
49+
})
50+
}
51+
52+
fn main() {
53+
// The iterator "generator" list should exhaust what corresponding
54+
// implementations have where `Sync` and `Send` semantics apply.
55+
all_sync_send!(BinaryHeap::<usize>::new(), iter, drain, into_iter);
56+
57+
all_sync_send!(BitVec::new(), iter);
58+
59+
all_sync_send!(BitSet::new(), iter);
60+
is_sync_send!(BitSet::new(), union(&BitSet::new()));
61+
is_sync_send!(BitSet::new(), intersection(&BitSet::new()));
62+
is_sync_send!(BitSet::new(), difference(&BitSet::new()));
63+
is_sync_send!(BitSet::new(), symmetric_difference(&BitSet::new()));
64+
65+
all_sync_send!(BTreeMap::<usize, usize>::new(), iter, iter_mut, into_iter, keys, values);
66+
is_sync_send!(BTreeMap::<usize, usize>::new(), range(Included(&0), Included(&9)));
67+
is_sync_send!(BTreeMap::<usize, usize>::new(), range_mut(Included(&0), Included(&9)));
68+
69+
all_sync_send!(BTreeSet::<usize>::new(), iter, into_iter);
70+
is_sync_send!(BTreeSet::<usize>::new(), range(Included(&0), Included(&9)));
71+
is_sync_send!(BTreeSet::<usize>::new(), difference(&BTreeSet::<usize>::new()));
72+
is_sync_send!(BTreeSet::<usize>::new(), symmetric_difference(&BTreeSet::<usize>::new()));
73+
is_sync_send!(BTreeSet::<usize>::new(), intersection(&BTreeSet::<usize>::new()));
74+
is_sync_send!(BTreeSet::<usize>::new(), union(&BTreeSet::<usize>::new()));
75+
76+
all_sync_send!(LinkedList::<usize>::new(), iter, iter_mut, into_iter);
77+
78+
#[derive(Copy)]
79+
#[repr(usize)]
80+
#[allow(dead_code)]
81+
enum Foo { A, B, C }
82+
impl CLike for Foo {
83+
fn to_usize(&self) -> usize {
84+
*self as usize
85+
}
86+
87+
fn from_usize(v: usize) -> Foo {
88+
unsafe { mem::transmute(v) }
89+
}
90+
}
91+
all_sync_send!(EnumSet::<Foo>::new(), iter);
92+
93+
all_sync_send!(VecDeque::<usize>::new(), iter, iter_mut, drain, into_iter);
94+
95+
all_sync_send!(VecMap::<usize>::new(), iter, iter_mut, drain, into_iter, keys, values);
96+
97+
all_sync_send!(Vec::<usize>::new(), into_iter, drain);
98+
}

0 commit comments

Comments
 (0)