@@ -31,8 +31,6 @@ union Data<T, F> {
3131/// Initialize static variables with `LazyLock`.
3232///
3333/// ```
34- /// #![feature(lazy_cell)]
35- ///
3634/// use std::collections::HashMap;
3735///
3836/// use std::sync::LazyLock;
@@ -61,8 +59,6 @@ union Data<T, F> {
6159/// ```
6260/// Initialize fields with `LazyLock`.
6361/// ```
64- /// #![feature(lazy_cell)]
65- ///
6662/// use std::sync::LazyLock;
6763///
6864/// #[derive(Debug)]
@@ -76,17 +72,29 @@ union Data<T, F> {
7672/// println!("{}", *data.number);
7773/// }
7874/// ```
79-
80- #[ unstable( feature = "lazy_cell" , issue = "109736" ) ]
75+ #[ stable( feature = "lazy_cell" , since = "CURRENT_RUSTC_VERSION" ) ]
8176pub struct LazyLock < T , F = fn ( ) -> T > {
8277 once : Once ,
8378 data : UnsafeCell < Data < T , F > > ,
8479}
8580
8681impl < T , F : FnOnce ( ) -> T > LazyLock < T , F > {
8782 /// Creates a new lazy value with the given initializing function.
83+ ///
84+ /// # Examples
85+ ///
86+ /// ```
87+ /// use std::sync::LazyLock;
88+ ///
89+ /// let hello = "Hello, World!".to_string();
90+ ///
91+ /// let lazy = LazyLock::new(|| hello.to_uppercase());
92+ ///
93+ /// assert_eq!(&*lazy, "HELLO, WORLD!");
94+ /// ```
8895 #[ inline]
89- #[ unstable( feature = "lazy_cell" , issue = "109736" ) ]
96+ #[ stable( feature = "lazy_cell" , since = "CURRENT_RUSTC_VERSION" ) ]
97+ #[ rustc_const_stable( feature = "lazy_cell" , since = "CURRENT_RUSTC_VERSION" ) ]
9098 pub const fn new ( f : F ) -> LazyLock < T , F > {
9199 LazyLock { once : Once :: new ( ) , data : UnsafeCell :: new ( Data { f : ManuallyDrop :: new ( f) } ) }
92100 }
@@ -107,7 +115,6 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
107115 /// # Examples
108116 ///
109117 /// ```
110- /// #![feature(lazy_cell)]
111118 /// #![feature(lazy_cell_consume)]
112119 ///
113120 /// use std::sync::LazyLock;
@@ -145,8 +152,6 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
145152 /// # Examples
146153 ///
147154 /// ```
148- /// #![feature(lazy_cell)]
149- ///
150155 /// use std::sync::LazyLock;
151156 ///
152157 /// let lazy = LazyLock::new(|| 92);
@@ -155,7 +160,7 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
155160 /// assert_eq!(&*lazy, &92);
156161 /// ```
157162 #[ inline]
158- #[ unstable ( feature = "lazy_cell" , issue = "109736 " ) ]
163+ #[ stable ( feature = "lazy_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
159164 pub fn force ( this : & LazyLock < T , F > ) -> & T {
160165 this. once . call_once ( || {
161166 // SAFETY: `call_once` only runs this closure once, ever.
@@ -191,7 +196,7 @@ impl<T, F> LazyLock<T, F> {
191196 }
192197}
193198
194- #[ unstable ( feature = "lazy_cell" , issue = "109736 " ) ]
199+ #[ stable ( feature = "lazy_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
195200impl < T , F > Drop for LazyLock < T , F > {
196201 fn drop ( & mut self ) {
197202 match self . once . state ( ) {
@@ -204,7 +209,7 @@ impl<T, F> Drop for LazyLock<T, F> {
204209 }
205210}
206211
207- #[ unstable ( feature = "lazy_cell" , issue = "109736 " ) ]
212+ #[ stable ( feature = "lazy_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
208213impl < T , F : FnOnce ( ) -> T > Deref for LazyLock < T , F > {
209214 type Target = T ;
210215
@@ -219,7 +224,7 @@ impl<T, F: FnOnce() -> T> Deref for LazyLock<T, F> {
219224 }
220225}
221226
222- #[ unstable ( feature = "lazy_cell" , issue = "109736 " ) ]
227+ #[ stable ( feature = "lazy_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
223228impl < T : Default > Default for LazyLock < T > {
224229 /// Creates a new lazy value using `Default` as the initializing function.
225230 #[ inline]
@@ -228,7 +233,7 @@ impl<T: Default> Default for LazyLock<T> {
228233 }
229234}
230235
231- #[ unstable ( feature = "lazy_cell" , issue = "109736 " ) ]
236+ #[ stable ( feature = "lazy_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
232237impl < T : fmt:: Debug , F > fmt:: Debug for LazyLock < T , F > {
233238 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
234239 let mut d = f. debug_tuple ( "LazyLock" ) ;
@@ -242,13 +247,13 @@ impl<T: fmt::Debug, F> fmt::Debug for LazyLock<T, F> {
242247
243248// We never create a `&F` from a `&LazyLock<T, F>` so it is fine
244249// to not impl `Sync` for `F`.
245- #[ unstable ( feature = "lazy_cell" , issue = "109736 " ) ]
250+ #[ stable ( feature = "lazy_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
246251unsafe impl < T : Sync + Send , F : Send > Sync for LazyLock < T , F > { }
247252// auto-derived `Send` impl is OK.
248253
249- #[ unstable ( feature = "lazy_cell" , issue = "109736 " ) ]
254+ #[ stable ( feature = "lazy_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
250255impl < T : RefUnwindSafe + UnwindSafe , F : UnwindSafe > RefUnwindSafe for LazyLock < T , F > { }
251- #[ unstable ( feature = "lazy_cell" , issue = "109736 " ) ]
256+ #[ stable ( feature = "lazy_cell" , since = "CURRENT_RUSTC_VERSION " ) ]
252257impl < T : UnwindSafe , F : UnwindSafe > UnwindSafe for LazyLock < T , F > { }
253258
254259#[ cfg( test) ]
0 commit comments