From f522d882373067ab79ea0fdc30be6150eeccb1fd Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Mon, 29 Feb 2016 22:03:23 -0500 Subject: [PATCH] Explicitly opt out of `Sync` for `cell` and `mpsc` types These types were already `!Sync`, but this improves error messages when they are used in contexts that require `Sync`, aligning them with conventions used with `Rc`, among others. --- src/libcore/cell.rs | 6 ++++ src/libstd/sync/mpsc/mod.rs | 6 ++++ .../compile-fail/comm-not-freeze-receiver.rs | 17 ---------- src/test/compile-fail/comm-not-freeze.rs | 17 ---------- src/test/compile-fail/no_share-rc.rs | 20 ----------- src/test/compile-fail/not-sync.rs | 34 +++++++++++++++++++ 6 files changed, 46 insertions(+), 54 deletions(-) delete mode 100644 src/test/compile-fail/comm-not-freeze-receiver.rs delete mode 100644 src/test/compile-fail/comm-not-freeze.rs delete mode 100644 src/test/compile-fail/no_share-rc.rs create mode 100644 src/test/compile-fail/not-sync.rs diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 255c846244b..144adde12e4 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -241,6 +241,9 @@ impl Cell { #[stable(feature = "rust1", since = "1.0.0")] unsafe impl Send for Cell where T: Send {} +#[stable(feature = "rust1", since = "1.0.0")] +impl !Sync for Cell {} + #[stable(feature = "rust1", since = "1.0.0")] impl Clone for Cell { #[inline] @@ -461,6 +464,9 @@ impl RefCell { #[stable(feature = "rust1", since = "1.0.0")] unsafe impl Send for RefCell where T: Send {} +#[stable(feature = "rust1", since = "1.0.0")] +impl !Sync for RefCell {} + #[stable(feature = "rust1", since = "1.0.0")] impl Clone for RefCell { #[inline] diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index fadca390986..dbcc2bc95bc 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -299,6 +299,9 @@ pub struct Receiver { #[stable(feature = "rust1", since = "1.0.0")] unsafe impl Send for Receiver { } +#[stable(feature = "rust1", since = "1.0.0")] +impl !Sync for Receiver { } + /// An iterator over messages on a receiver, this iterator will block /// whenever `next` is called, waiting for a new message, and `None` will be /// returned when the corresponding channel has hung up. @@ -327,6 +330,9 @@ pub struct Sender { #[stable(feature = "rust1", since = "1.0.0")] unsafe impl Send for Sender { } +#[stable(feature = "rust1", since = "1.0.0")] +impl !Sync for Sender { } + /// The sending-half of Rust's synchronous channel type. This half can only be /// owned by one thread, but it can be cloned to send to other threads. #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/test/compile-fail/comm-not-freeze-receiver.rs b/src/test/compile-fail/comm-not-freeze-receiver.rs deleted file mode 100644 index 305acfec401..00000000000 --- a/src/test/compile-fail/comm-not-freeze-receiver.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use std::sync::mpsc::Receiver; - -fn test() {} - -fn main() { - test::>(); //~ ERROR: `core::marker::Sync` is not implemented -} diff --git a/src/test/compile-fail/comm-not-freeze.rs b/src/test/compile-fail/comm-not-freeze.rs deleted file mode 100644 index de2c96920c3..00000000000 --- a/src/test/compile-fail/comm-not-freeze.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use std::sync::mpsc::Sender; - -fn test() {} - -fn main() { - test::>(); //~ ERROR: `core::marker::Sync` is not implemented -} diff --git a/src/test/compile-fail/no_share-rc.rs b/src/test/compile-fail/no_share-rc.rs deleted file mode 100644 index 4bc3442871f..00000000000 --- a/src/test/compile-fail/no_share-rc.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use std::rc::Rc; -use std::cell::RefCell; - -fn bar(_: T) {} - -fn main() { - let x = Rc::new(RefCell::new(5)); - bar(x); - //~^ ERROR the trait `core::marker::Sync` is not implemented -} diff --git a/src/test/compile-fail/not-sync.rs b/src/test/compile-fail/not-sync.rs new file mode 100644 index 00000000000..a60138c6e1f --- /dev/null +++ b/src/test/compile-fail/not-sync.rs @@ -0,0 +1,34 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::cell::{Cell, RefCell}; +use std::rc::{Rc, Weak}; +use std::sync::mpsc::{Receiver, Sender, SyncSender}; + +fn test() {} + +fn main() { + test::>(); + //~^ ERROR marker::Sync` is not implemented for the type `core::cell::Cell` + test::>(); + //~^ ERROR marker::Sync` is not implemented for the type `core::cell::RefCell` + + test::>(); + //~^ ERROR marker::Sync` is not implemented for the type `alloc::rc::Rc` + test::>(); + //~^ ERROR marker::Sync` is not implemented for the type `alloc::rc::Weak` + + test::>(); + //~^ ERROR marker::Sync` is not implemented for the type `std::sync::mpsc::Receiver` + test::>(); + //~^ ERROR marker::Sync` is not implemented for the type `std::sync::mpsc::Sender` + test::>(); + //~^ ERROR marker::Sync` is not implemented for the type `std::sync::mpsc::SyncSender` +}