@@ -16,8 +16,6 @@ use crate::mem;
1616/// # Examples
1717///
1818/// ```
19- /// #![feature(once_cell)]
20- ///
2119/// use std::cell::OnceCell;
2220///
2321/// let cell = OnceCell::new();
@@ -29,7 +27,7 @@ use crate::mem;
2927/// assert_eq!(value, "Hello, World!");
3028/// assert!(cell.get().is_some());
3129/// ```
32- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
30+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
3331pub struct OnceCell < T > {
3432 // Invariant: written to at most once.
3533 inner : UnsafeCell < Option < T > > ,
@@ -39,7 +37,8 @@ impl<T> OnceCell<T> {
3937 /// Creates a new empty cell.
4038 #[ inline]
4139 #[ 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" ) ]
4342 pub const fn new ( ) -> OnceCell < T > {
4443 OnceCell { inner : UnsafeCell :: new ( None ) }
4544 }
@@ -48,7 +47,7 @@ impl<T> OnceCell<T> {
4847 ///
4948 /// Returns `None` if the cell is empty.
5049 #[ inline]
51- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
50+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
5251 pub fn get ( & self ) -> Option < & T > {
5352 // SAFETY: Safe due to `inner`'s invariant
5453 unsafe { & * self . inner . get ( ) } . as_ref ( )
@@ -58,7 +57,7 @@ impl<T> OnceCell<T> {
5857 ///
5958 /// Returns `None` if the cell is empty.
6059 #[ inline]
61- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
60+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
6261 pub fn get_mut ( & mut self ) -> Option < & mut T > {
6362 self . inner . get_mut ( ) . as_mut ( )
6463 }
@@ -73,8 +72,6 @@ impl<T> OnceCell<T> {
7372 /// # Examples
7473 ///
7574 /// ```
76- /// #![feature(once_cell)]
77- ///
7875 /// use std::cell::OnceCell;
7976 ///
8077 /// let cell = OnceCell::new();
@@ -86,7 +83,7 @@ impl<T> OnceCell<T> {
8683 /// assert!(cell.get().is_some());
8784 /// ```
8885 #[ inline]
89- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
86+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
9087 pub fn set ( & self , value : T ) -> Result < ( ) , T > {
9188 // SAFETY: Safe because we cannot have overlapping mutable borrows
9289 let slot = unsafe { & * self . inner . get ( ) } ;
@@ -117,8 +114,6 @@ impl<T> OnceCell<T> {
117114 /// # Examples
118115 ///
119116 /// ```
120- /// #![feature(once_cell)]
121- ///
122117 /// use std::cell::OnceCell;
123118 ///
124119 /// let cell = OnceCell::new();
@@ -128,7 +123,7 @@ impl<T> OnceCell<T> {
128123 /// assert_eq!(value, &92);
129124 /// ```
130125 #[ inline]
131- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
126+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
132127 pub fn get_or_init < F > ( & self , f : F ) -> & T
133128 where
134129 F : FnOnce ( ) -> T ,
@@ -153,7 +148,7 @@ impl<T> OnceCell<T> {
153148 /// # Examples
154149 ///
155150 /// ```
156- /// #![feature(once_cell )]
151+ /// #![feature(once_cell_try )]
157152 ///
158153 /// use std::cell::OnceCell;
159154 ///
@@ -166,7 +161,7 @@ impl<T> OnceCell<T> {
166161 /// assert_eq!(value, Ok(&92));
167162 /// assert_eq!(cell.get(), Some(&92))
168163 /// ```
169- #[ unstable( feature = "once_cell " , issue = "74465 " ) ]
164+ #[ unstable( feature = "once_cell_try " , issue = "109737 " ) ]
170165 pub fn get_or_try_init < F , E > ( & self , f : F ) -> Result < & T , E >
171166 where
172167 F : FnOnce ( ) -> Result < T , E > ,
@@ -199,8 +194,6 @@ impl<T> OnceCell<T> {
199194 /// # Examples
200195 ///
201196 /// ```
202- /// #![feature(once_cell)]
203- ///
204197 /// use std::cell::OnceCell;
205198 ///
206199 /// let cell: OnceCell<String> = OnceCell::new();
@@ -211,7 +204,7 @@ impl<T> OnceCell<T> {
211204 /// assert_eq!(cell.into_inner(), Some("hello".to_string()));
212205 /// ```
213206 #[ inline]
214- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
207+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
215208 pub fn into_inner ( self ) -> Option < T > {
216209 // Because `into_inner` takes `self` by value, the compiler statically verifies
217210 // that it is not currently borrowed. So it is safe to move out `Option<T>`.
@@ -227,8 +220,6 @@ impl<T> OnceCell<T> {
227220 /// # Examples
228221 ///
229222 /// ```
230- /// #![feature(once_cell)]
231- ///
232223 /// use std::cell::OnceCell;
233224 ///
234225 /// let mut cell: OnceCell<String> = OnceCell::new();
@@ -240,21 +231,21 @@ impl<T> OnceCell<T> {
240231 /// assert_eq!(cell.get(), None);
241232 /// ```
242233 #[ inline]
243- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
234+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
244235 pub fn take ( & mut self ) -> Option < T > {
245236 mem:: take ( self ) . into_inner ( )
246237 }
247238}
248239
249- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
240+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
250241impl < T > Default for OnceCell < T > {
251242 #[ inline]
252243 fn default ( ) -> Self {
253244 Self :: new ( )
254245 }
255246}
256247
257- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
248+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
258249impl < T : fmt:: Debug > fmt:: Debug for OnceCell < T > {
259250 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
260251 match self . get ( ) {
@@ -264,7 +255,7 @@ impl<T: fmt::Debug> fmt::Debug for OnceCell<T> {
264255 }
265256}
266257
267- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
258+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
268259impl < T : Clone > Clone for OnceCell < T > {
269260 #[ inline]
270261 fn clone ( & self ) -> OnceCell < T > {
@@ -279,18 +270,19 @@ impl<T: Clone> Clone for OnceCell<T> {
279270 }
280271}
281272
282- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
273+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
283274impl < T : PartialEq > PartialEq for OnceCell < T > {
284275 #[ inline]
285276 fn eq ( & self , other : & Self ) -> bool {
286277 self . get ( ) == other. get ( )
287278 }
288279}
289280
290- #[ unstable ( feature = "once_cell" , issue = "74465 " ) ]
281+ #[ stable ( feature = "once_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
291282impl < T : Eq > Eq for OnceCell < T > { }
292283
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" ) ]
294286impl < T > const From < T > for OnceCell < T > {
295287 /// Creates a new `OnceCell<T>` which already contains the given `value`.
296288 #[ inline]
@@ -300,5 +292,5 @@ impl<T> const From<T> for OnceCell<T> {
300292}
301293
302294// 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 " ) ]
304296impl < T > !Sync for OnceCell < T > { }
0 commit comments