Skip to content

Commit

Permalink
Require <T: Send> for AtomicOption
Browse files Browse the repository at this point in the history
Fixes #19247.
  • Loading branch information
Keegan McAllister committed Nov 23, 2014
1 parent 220b99b commit 26c9343
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/libsync/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -114,7 +114,7 @@ pub struct AtomicOption<T> {
p: AtomicUint,
}

impl<T> AtomicOption<T> {
impl<T: Send> AtomicOption<T> {
/// Create a new `AtomicOption`
pub fn new(p: Box<T>) -> AtomicOption<T> {
unsafe { AtomicOption { p: AtomicUint::new(mem::transmute(p)) } }
Expand Down Expand Up @@ -170,7 +170,7 @@ impl<T> AtomicOption<T> {
}

#[unsafe_destructor]
impl<T> Drop for AtomicOption<T> {
impl<T: Send> Drop for AtomicOption<T> {
fn drop(&mut self) {
let _ = self.take(SeqCst);
}
Expand Down
16 changes: 16 additions & 0 deletions src/test/compile-fail/atomicoption-not-send-ref.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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
}
16 changes: 16 additions & 0 deletions src/test/compile-fail/atomicoption-not-send.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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
}

5 comments on commit 26c9343

@bors
Copy link
Contributor

@bors bors commented on 26c9343 Nov 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at kmcallister@26c9343

@bors
Copy link
Contributor

@bors bors commented on 26c9343 Nov 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging kmcallister/rust/atomicoption = 26c9343 into auto

@bors
Copy link
Contributor

@bors bors commented on 26c9343 Nov 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kmcallister/rust/atomicoption = 26c9343 merged ok, testing candidate = 377d752

@bors
Copy link
Contributor

@bors bors commented on 26c9343 Nov 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 26c9343 Nov 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 377d752

Please sign in to comment.