@@ -16,8 +16,6 @@ use crate::mem;
16
16
/// # Examples
17
17
///
18
18
/// ```
19
- /// #![feature(once_cell)]
20
- ///
21
19
/// use std::cell::OnceCell;
22
20
///
23
21
/// let cell = OnceCell::new();
@@ -29,7 +27,7 @@ use crate::mem;
29
27
/// assert_eq!(value, "Hello, World!");
30
28
/// assert!(cell.get().is_some());
31
29
/// ```
32
- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
30
+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
33
31
pub struct OnceCell < T > {
34
32
// Invariant: written to at most once.
35
33
inner : UnsafeCell < Option < T > > ,
@@ -39,7 +37,8 @@ impl<T> OnceCell<T> {
39
37
/// Creates a new empty cell.
40
38
#[ inline]
41
39
#[ must_use]
42
- #[ unstable( feature = "once_cell" , issue = "74465" ) ]
40
+ #[ stable( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION" ) ]
41
+ #[ rustc_const_stable( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION" ) ]
43
42
pub const fn new ( ) -> OnceCell < T > {
44
43
OnceCell { inner : UnsafeCell :: new ( None ) }
45
44
}
@@ -48,7 +47,7 @@ impl<T> OnceCell<T> {
48
47
///
49
48
/// Returns `None` if the cell is empty.
50
49
#[ inline]
51
- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
50
+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
52
51
pub fn get ( & self ) -> Option < & T > {
53
52
// SAFETY: Safe due to `inner`'s invariant
54
53
unsafe { & * self . inner . get ( ) } . as_ref ( )
@@ -58,7 +57,7 @@ impl<T> OnceCell<T> {
58
57
///
59
58
/// Returns `None` if the cell is empty.
60
59
#[ inline]
61
- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
60
+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
62
61
pub fn get_mut ( & mut self ) -> Option < & mut T > {
63
62
self . inner . get_mut ( ) . as_mut ( )
64
63
}
@@ -73,8 +72,6 @@ impl<T> OnceCell<T> {
73
72
/// # Examples
74
73
///
75
74
/// ```
76
- /// #![feature(once_cell)]
77
- ///
78
75
/// use std::cell::OnceCell;
79
76
///
80
77
/// let cell = OnceCell::new();
@@ -86,7 +83,7 @@ impl<T> OnceCell<T> {
86
83
/// assert!(cell.get().is_some());
87
84
/// ```
88
85
#[ inline]
89
- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
86
+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
90
87
pub fn set ( & self , value : T ) -> Result < ( ) , T > {
91
88
// SAFETY: Safe because we cannot have overlapping mutable borrows
92
89
let slot = unsafe { & * self . inner . get ( ) } ;
@@ -117,8 +114,6 @@ impl<T> OnceCell<T> {
117
114
/// # Examples
118
115
///
119
116
/// ```
120
- /// #![feature(once_cell)]
121
- ///
122
117
/// use std::cell::OnceCell;
123
118
///
124
119
/// let cell = OnceCell::new();
@@ -128,7 +123,7 @@ impl<T> OnceCell<T> {
128
123
/// assert_eq!(value, &92);
129
124
/// ```
130
125
#[ inline]
131
- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
126
+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
132
127
pub fn get_or_init < F > ( & self , f : F ) -> & T
133
128
where
134
129
F : FnOnce ( ) -> T ,
@@ -153,7 +148,7 @@ impl<T> OnceCell<T> {
153
148
/// # Examples
154
149
///
155
150
/// ```
156
- /// #![feature(once_cell )]
151
+ /// #![feature(once_cell_try )]
157
152
///
158
153
/// use std::cell::OnceCell;
159
154
///
@@ -166,7 +161,7 @@ impl<T> OnceCell<T> {
166
161
/// assert_eq!(value, Ok(&92));
167
162
/// assert_eq!(cell.get(), Some(&92))
168
163
/// ```
169
- #[ unstable( feature = "once_cell " , issue = "74465 " ) ]
164
+ #[ unstable( feature = "once_cell_try " , issue = "109737 " ) ]
170
165
pub fn get_or_try_init < F , E > ( & self , f : F ) -> Result < & T , E >
171
166
where
172
167
F : FnOnce ( ) -> Result < T , E > ,
@@ -199,8 +194,6 @@ impl<T> OnceCell<T> {
199
194
/// # Examples
200
195
///
201
196
/// ```
202
- /// #![feature(once_cell)]
203
- ///
204
197
/// use std::cell::OnceCell;
205
198
///
206
199
/// let cell: OnceCell<String> = OnceCell::new();
@@ -211,7 +204,7 @@ impl<T> OnceCell<T> {
211
204
/// assert_eq!(cell.into_inner(), Some("hello".to_string()));
212
205
/// ```
213
206
#[ inline]
214
- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
207
+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
215
208
pub fn into_inner ( self ) -> Option < T > {
216
209
// Because `into_inner` takes `self` by value, the compiler statically verifies
217
210
// that it is not currently borrowed. So it is safe to move out `Option<T>`.
@@ -227,8 +220,6 @@ impl<T> OnceCell<T> {
227
220
/// # Examples
228
221
///
229
222
/// ```
230
- /// #![feature(once_cell)]
231
- ///
232
223
/// use std::cell::OnceCell;
233
224
///
234
225
/// let mut cell: OnceCell<String> = OnceCell::new();
@@ -240,21 +231,21 @@ impl<T> OnceCell<T> {
240
231
/// assert_eq!(cell.get(), None);
241
232
/// ```
242
233
#[ inline]
243
- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
234
+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
244
235
pub fn take ( & mut self ) -> Option < T > {
245
236
mem:: take ( self ) . into_inner ( )
246
237
}
247
238
}
248
239
249
- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
240
+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
250
241
impl < T > Default for OnceCell < T > {
251
242
#[ inline]
252
243
fn default ( ) -> Self {
253
244
Self :: new ( )
254
245
}
255
246
}
256
247
257
- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
248
+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
258
249
impl < T : fmt:: Debug > fmt:: Debug for OnceCell < T > {
259
250
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
260
251
match self . get ( ) {
@@ -264,7 +255,7 @@ impl<T: fmt::Debug> fmt::Debug for OnceCell<T> {
264
255
}
265
256
}
266
257
267
- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
258
+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
268
259
impl < T : Clone > Clone for OnceCell < T > {
269
260
#[ inline]
270
261
fn clone ( & self ) -> OnceCell < T > {
@@ -279,18 +270,19 @@ impl<T: Clone> Clone for OnceCell<T> {
279
270
}
280
271
}
281
272
282
- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
273
+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
283
274
impl < T : PartialEq > PartialEq for OnceCell < T > {
284
275
#[ inline]
285
276
fn eq ( & self , other : & Self ) -> bool {
286
277
self . get ( ) == other. get ( )
287
278
}
288
279
}
289
280
290
- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
281
+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
291
282
impl < T : Eq > Eq for OnceCell < T > { }
292
283
293
- #[ unstable( feature = "once_cell" , issue = "74465" ) ]
284
+ #[ stable( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION" ) ]
285
+ #[ rustc_const_unstable( feature = "const_convert" , issue = "88674" ) ]
294
286
impl < T > const From < T > for OnceCell < T > {
295
287
/// Creates a new `OnceCell<T>` which already contains the given `value`.
296
288
#[ inline]
@@ -300,5 +292,5 @@ impl<T> const From<T> for OnceCell<T> {
300
292
}
301
293
302
294
// Just like for `Cell<T>` this isn't needed, but results in nicer error messages.
303
- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
295
+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
304
296
impl < T > !Sync for OnceCell < T > { }
0 commit comments