Skip to content

Commit f436f9c

Browse files
committed
Make Send and Sync traits unsafe
1 parent 686ce66 commit f436f9c

32 files changed

+73
-55
lines changed

src/liballoc/arc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ pub struct Weak<T> {
129129
_ptr: *mut ArcInner<T>,
130130
}
131131

132-
impl<T: Sync + Send> Send for Arc<T> { }
132+
unsafe impl<T: Sync + Send> Send for Arc<T> { }
133133

134-
impl<T: Sync + Send> Sync for Arc<T> { }
134+
unsafe impl<T: Sync + Send> Sync for Arc<T> { }
135135

136136
struct ArcInner<T> {
137137
strong: atomic::AtomicUint,

src/libcore/cell.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,6 @@ impl<T> RacyCell<T> {
577577
}
578578
}
579579

580-
impl<T:Send> Send for RacyCell<T> { }
580+
unsafe impl<T:Send> Send for RacyCell<T> { }
581581

582-
impl<T> Sync for RacyCell<T> { } // Oh dear
582+
unsafe impl<T> Sync for RacyCell<T> { } // Oh dear

src/libcore/kinds.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
/// Types able to be transferred across task boundaries.
2121
#[lang="send"]
22-
pub trait Send for Sized? : 'static {
22+
pub unsafe trait Send for Sized? : 'static {
2323
// empty.
2424
}
2525

@@ -81,7 +81,7 @@ pub trait Copy for Sized? {
8181
/// reference; not doing this is undefined behaviour (for example,
8282
/// `transmute`-ing from `&T` to `&mut T` is illegal).
8383
#[lang="sync"]
84-
pub trait Sync for Sized? {
84+
pub unsafe trait Sync for Sized? {
8585
// Empty
8686
}
8787

src/libcore/ptr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,13 +515,13 @@ pub struct UniquePtr<T>(pub *mut T);
515515
/// reference is unaliased. Note that this aliasing invariant is
516516
/// unenforced by the type system; the abstraction using the
517517
/// `UniquePtr` must enforce it.
518-
impl<T:Send> Send for UniquePtr<T> { }
518+
unsafe impl<T:Send> Send for UniquePtr<T> { }
519519

520520
/// `UniquePtr` pointers are `Sync` if `T` is `Sync` because the data they
521521
/// reference is unaliased. Note that this aliasing invariant is
522522
/// unenforced by the type system; the abstraction using the
523523
/// `UniquePtr` must enforce it.
524-
impl<T:Sync> Sync for UniquePtr<T> { }
524+
unsafe impl<T:Sync> Sync for UniquePtr<T> { }
525525

526526
impl<T> UniquePtr<T> {
527527
/// Returns a null UniquePtr.

src/librustc_trans/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ struct ModuleConfig {
281281
time_passes: bool,
282282
}
283283

284-
impl Send for ModuleConfig { }
284+
unsafe impl Send for ModuleConfig { }
285285

286286
impl ModuleConfig {
287287
fn new(tm: TargetMachineRef, passes: Vec<String>) -> ModuleConfig {

src/librustc_trans/trans/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ pub struct ModuleTranslation {
6060
pub llmod: ModuleRef,
6161
}
6262

63-
impl Send for ModuleTranslation { }
64-
impl Sync for ModuleTranslation { }
63+
unsafe impl Send for ModuleTranslation { }
64+
unsafe impl Sync for ModuleTranslation { }
6565

6666
pub struct CrateTranslation {
6767
pub modules: Vec<ModuleTranslation>,

src/libstd/c_str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ pub struct CString {
8989
owns_buffer_: bool,
9090
}
9191

92-
impl Send for CString { }
93-
impl Sync for CString { }
92+
unsafe impl Send for CString { }
93+
unsafe impl Sync for CString { }
9494

9595
impl Clone for CString {
9696
/// Clone this CString into a new, uniquely owned CString. For safety

src/libstd/comm/blocking.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@
1313
use thread::Thread;
1414
use sync::atomic::{AtomicBool, INIT_ATOMIC_BOOL, Ordering};
1515
use sync::Arc;
16+
use kinds::{Sync, Send};
1617
use kinds::marker::{NoSend, NoSync};
1718
use mem;
1819
use clone::Clone;
1920

20-
#[deriving(Send, Sync)]
2121
struct Inner {
2222
thread: Thread,
2323
woken: AtomicBool,
2424
}
2525

26+
unsafe impl Send for Inner {}
27+
unsafe impl Sync for Inner {}
28+
2629
#[deriving(Clone)]
2730
pub struct SignalToken {
2831
inner: Arc<Inner>,

src/libstd/comm/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ pub struct Receiver<T> {
363363

364364
// The receiver port can be sent from place to place, so long as it
365365
// is not used to receive non-sendable things.
366-
impl<T:Send> Send for Receiver<T> { }
366+
unsafe impl<T:Send> Send for Receiver<T> { }
367367

368368
/// An iterator over messages on a receiver, this iterator will block
369369
/// whenever `next` is called, waiting for a new message, and `None` will be
@@ -382,7 +382,7 @@ pub struct Sender<T> {
382382

383383
// The send port can be sent from place to place, so long as it
384384
// is not used to send non-sendable things.
385-
impl<T:Send> Send for Sender<T> { }
385+
unsafe impl<T:Send> Send for Sender<T> { }
386386

387387
/// The sending-half of Rust's synchronous channel type. This half can only be
388388
/// owned by one task, but it can be cloned to send to other tasks.

src/libstd/comm/mpsc_queue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ pub struct Queue<T> {
7676
tail: UnsafeCell<*mut Node<T>>,
7777
}
7878

79-
impl<T:Send> Send for Queue<T> { }
80-
impl<T:Send> Sync for Queue<T> { }
79+
unsafe impl<T:Send> Send for Queue<T> { }
80+
unsafe impl<T:Send> Sync for Queue<T> { }
8181

8282
impl<T> Node<T> {
8383
unsafe fn new(v: Option<T>) -> *mut Node<T> {

0 commit comments

Comments
 (0)