File tree 8 files changed +50
-3
lines changed
8 files changed +50
-3
lines changed Original file line number Diff line number Diff line change @@ -39,5 +39,8 @@ optional = true
39
39
version = " 1"
40
40
default-features = false
41
41
42
+ [build-dependencies ]
43
+ autocfg = " 0.1.6"
44
+
42
45
[dev-dependencies ]
43
46
rand = " 0.6"
Original file line number Diff line number Diff line change
1
+ extern crate autocfg;
2
+
3
+ fn main ( ) {
4
+ let cfg = autocfg:: new ( ) ;
5
+ if cfg. probe_rustc_version ( 1 , 31 ) {
6
+ println ! ( "cargo:rustc-cfg=has_min_const_fn" ) ;
7
+ }
8
+ }
Original file line number Diff line number Diff line change @@ -150,7 +150,7 @@ impl<T> Atomic<T> {
150
150
///
151
151
/// let a = Atomic::<i32>::null();
152
152
/// ```
153
- #[ cfg( not( feature = "nightly" ) ) ]
153
+ #[ cfg( not( has_min_const_fn ) ) ]
154
154
pub fn null ( ) -> Atomic < T > {
155
155
Self {
156
156
data : AtomicUsize :: new ( 0 ) ,
@@ -167,7 +167,7 @@ impl<T> Atomic<T> {
167
167
///
168
168
/// let a = Atomic::<i32>::null();
169
169
/// ```
170
- #[ cfg( feature = "nightly" ) ]
170
+ #[ cfg( has_min_const_fn ) ]
171
171
pub const fn null ( ) -> Atomic < T > {
172
172
Self {
173
173
data : AtomicUsize :: new ( 0 ) ,
Original file line number Diff line number Diff line change 57
57
#![ warn( missing_docs) ]
58
58
#![ warn( missing_debug_implementations) ]
59
59
#![ cfg_attr( not( feature = "std" ) , no_std) ]
60
- #![ cfg_attr( feature = "nightly" , feature( const_fn) ) ]
61
60
#![ cfg_attr( feature = "nightly" , feature( cfg_target_has_atomic) ) ]
62
61
63
62
#[ macro_use]
Original file line number Diff line number Diff line change @@ -25,5 +25,8 @@ alloc = []
25
25
cfg-if = " 0.1.2"
26
26
lazy_static = { version = " 1.1.0" , optional = true }
27
27
28
+ [build-dependencies ]
29
+ autocfg = " 0.1.6"
30
+
28
31
[dev-dependencies ]
29
32
rand = " 0.6"
Original file line number Diff line number Diff line change
1
+ extern crate autocfg;
2
+
3
+ fn main ( ) {
4
+ let cfg = autocfg:: new ( ) ;
5
+ if cfg. probe_rustc_version ( 1 , 31 ) {
6
+ println ! ( "cargo:rustc-cfg=has_min_const_fn" ) ;
7
+ }
8
+ }
Original file line number Diff line number Diff line change @@ -51,12 +51,29 @@ impl<T> AtomicCell<T> {
51
51
///
52
52
/// let a = AtomicCell::new(7);
53
53
/// ```
54
+ #[ cfg( not( has_min_const_fn) ) ]
54
55
pub fn new ( val : T ) -> AtomicCell < T > {
55
56
AtomicCell {
56
57
value : UnsafeCell :: new ( val) ,
57
58
}
58
59
}
59
60
61
+ /// Creates a new atomic cell initialized with `val`.
62
+ ///
63
+ /// # Examples
64
+ ///
65
+ /// ```
66
+ /// use crossbeam_utils::atomic::AtomicCell;
67
+ ///
68
+ /// let a = AtomicCell::new(7);
69
+ /// ```
70
+ #[ cfg( has_min_const_fn) ]
71
+ pub const fn new ( val : T ) -> AtomicCell < T > {
72
+ AtomicCell {
73
+ value : UnsafeCell :: new ( val) ,
74
+ }
75
+ }
76
+
60
77
/// Unwraps the atomic cell and returns its inner value.
61
78
///
62
79
/// # Examples
Original file line number Diff line number Diff line change @@ -223,3 +223,12 @@ fn garbage_padding() {
223
223
assert ! ( cell. compare_exchange( prev, next) . is_ok( ) ) ;
224
224
println ! ( ) ;
225
225
}
226
+
227
+ #[ cfg( has_min_const_fn) ]
228
+ #[ test]
229
+ fn const_atomic_cell_new ( ) {
230
+ static CELL : AtomicCell < usize > = AtomicCell :: new ( 0 ) ;
231
+
232
+ CELL . store ( 1 ) ;
233
+ assert_eq ! ( CELL . load( ) , 1 ) ;
234
+ }
You can’t perform that action at this time.
0 commit comments