Use const fn to abstract away the contents of UnsafeCell & friends.

This commit is contained in:
Eduard Burtescu 2015-05-27 11:18:36 +03:00
parent 6e8e4f847c
commit 377b0900ae
76 changed files with 417 additions and 525 deletions

View file

@ -18,9 +18,9 @@ use id::Id;
mod s {
#![allow(unstable)]
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};
static S_COUNT: AtomicUsize = ATOMIC_USIZE_INIT;
static S_COUNT: AtomicUsize = AtomicUsize::new(0);
pub fn next_count() -> usize {
S_COUNT.fetch_add(1, Ordering::SeqCst) + 1

View file

@ -26,9 +26,9 @@ use id::Id;
mod s {
#![allow(unstable)]
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};
static S_COUNT: AtomicUsize = ATOMIC_USIZE_INIT;
static S_COUNT: AtomicUsize = AtomicUsize::new(0);
pub fn next_count() -> usize {
S_COUNT.fetch_add(1, Ordering::SeqCst) + 1

View file

@ -17,9 +17,9 @@ use std::cell::Cell;
use id::Id;
mod s {
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};
static S_COUNT: AtomicUsize = ATOMIC_USIZE_INIT;
static S_COUNT: AtomicUsize = AtomicUsize::new(0);
pub fn next_count() -> usize {
S_COUNT.fetch_add(1, Ordering::SeqCst) + 1

View file

@ -17,9 +17,9 @@ use id::Id;
mod s {
#![allow(unstable)]
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};
static S_COUNT: AtomicUsize = ATOMIC_USIZE_INIT;
static S_COUNT: AtomicUsize = AtomicUsize::new(0);
pub fn next_count() -> usize {
S_COUNT.fetch_add(1, Ordering::SeqCst) + 1

View file

@ -16,7 +16,7 @@ use self::foo::S;
mod foo {
use std::cell::{UnsafeCell};
static mut count : UnsafeCell<u64> = UnsafeCell { value: 1 };
static mut count : UnsafeCell<u64> = UnsafeCell::new(1);
pub struct S { pub a: u8, pub b: String, secret_uid: u64 }

View file

@ -10,12 +10,12 @@
use std::cell::UnsafeCell;
const A: UnsafeCell<usize> = UnsafeCell { value: 1 };
const A: UnsafeCell<usize> = UnsafeCell::new(1);
const B: &'static UnsafeCell<usize> = &A;
//~^ ERROR: cannot borrow a constant which contains interior mutability
struct C { a: UnsafeCell<usize> }
const D: C = C { a: UnsafeCell { value: 1 } };
const D: C = C { a: UnsafeCell::new(1) };
const E: &'static UnsafeCell<usize> = &D.a;
//~^ ERROR: cannot borrow a constant which contains interior mutability
const F: &'static C = &D;

View file

@ -17,6 +17,5 @@ static boxed: Box<RefCell<isize>> = box RefCell::new(0);
//~^ ERROR allocations are not allowed in statics
//~| ERROR the trait `core::marker::Sync` is not implemented for the type
//~| ERROR the trait `core::marker::Sync` is not implemented for the type
//~| ERROR E0015
fn main() { }

View file

@ -15,11 +15,11 @@ use std::sync::atomic::*;
use std::ptr;
fn main() {
let x = ATOMIC_BOOL_INIT;
let x = AtomicBool::new(false);
let x = *&x; //~ ERROR: cannot move out of borrowed content
let x = ATOMIC_ISIZE_INIT;
let x = AtomicIsize::new(0);
let x = *&x; //~ ERROR: cannot move out of borrowed content
let x = ATOMIC_USIZE_INIT;
let x = AtomicUsize::new(0);
let x = *&x; //~ ERROR: cannot move out of borrowed content
let x: AtomicPtr<usize> = AtomicPtr::new(ptr::null_mut());
let x = *&x; //~ ERROR: cannot move out of borrowed content

View file

@ -28,9 +28,9 @@ use id::Id;
mod s {
#![allow(unstable)]
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
use std::sync::atomic::{AtomicUsize, Ordering};
static S_COUNT: AtomicUsize = ATOMIC_USIZE_INIT;
static S_COUNT: AtomicUsize = AtomicUsize::new(0);
/// generates globally unique count (global across the current
/// process, that is)