From 26c93433dafaabfd6f61d15c03fde68c9f214bf5 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Sun, 23 Nov 2014 10:21:47 -0800 Subject: [PATCH] Require for AtomicOption Fixes #19247. --- src/libsync/atomic.rs | 6 +++--- .../compile-fail/atomicoption-not-send-ref.rs | 16 ++++++++++++++++ src/test/compile-fail/atomicoption-not-send.rs | 16 ++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/test/compile-fail/atomicoption-not-send-ref.rs create mode 100644 src/test/compile-fail/atomicoption-not-send.rs diff --git a/src/libsync/atomic.rs b/src/libsync/atomic.rs index b4b2ef5218cef..0bc5dd11c253d 100644 --- a/src/libsync/atomic.rs +++ b/src/libsync/atomic.rs @@ -96,7 +96,7 @@ use alloc::boxed::Box; use core::mem; -use core::prelude::{Drop, None, Option, Some}; +use core::prelude::{Send, Drop, None, Option, Some}; pub use core::atomic::{AtomicBool, AtomicInt, AtomicUint, AtomicPtr}; pub use core::atomic::{Ordering, Relaxed, Release, Acquire, AcqRel, SeqCst}; @@ -114,7 +114,7 @@ pub struct AtomicOption { p: AtomicUint, } -impl AtomicOption { +impl AtomicOption { /// Create a new `AtomicOption` pub fn new(p: Box) -> AtomicOption { unsafe { AtomicOption { p: AtomicUint::new(mem::transmute(p)) } } @@ -170,7 +170,7 @@ impl AtomicOption { } #[unsafe_destructor] -impl Drop for AtomicOption { +impl Drop for AtomicOption { fn drop(&mut self) { let _ = self.take(SeqCst); } diff --git a/src/test/compile-fail/atomicoption-not-send-ref.rs b/src/test/compile-fail/atomicoption-not-send-ref.rs new file mode 100644 index 0000000000000..15c726be2fd23 --- /dev/null +++ b/src/test/compile-fail/atomicoption-not-send-ref.rs @@ -0,0 +1,16 @@ +// Copyright 2014 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::atomic::AtomicOption; + +fn main() { + let x = 0u; + AtomicOption::new(box &x); //~ ERROR `x` does not live long enough +} diff --git a/src/test/compile-fail/atomicoption-not-send.rs b/src/test/compile-fail/atomicoption-not-send.rs new file mode 100644 index 0000000000000..df3ebf530df99 --- /dev/null +++ b/src/test/compile-fail/atomicoption-not-send.rs @@ -0,0 +1,16 @@ +// Copyright 2014 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::kinds::marker; +use std::sync::atomic::AtomicOption; + +fn main() { + AtomicOption::new(box marker::NoSend); //~ ERROR `core::kinds::Send` is not implemented +}