@@ -31,8 +31,6 @@ union Data<T, F> {
3131//github.com/ Initialize static variables with `LazyLock`.
3232//github.com/
3333//github.com/ ```
34- //github.com/ #![feature(lazy_cell)]
35- //github.com/
3634//github.com/ use std::collections::HashMap;
3735//github.com/
3836//github.com/ use std::sync::LazyLock;
@@ -61,8 +59,6 @@ union Data<T, F> {
6159//github.com/ ```
6260//github.com/ Initialize fields with `LazyLock`.
6361//github.com/ ```
64- //github.com/ #![feature(lazy_cell)]
65- //github.com/
6662//github.com/ use std::sync::LazyLock;
6763//github.com/
6864//github.com/ #[derive(Debug)]
@@ -76,17 +72,29 @@ union Data<T, F> {
7672//github.com/ println!("{}", *data.number);
7773//github.com/ }
7874//github.com/ ```
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 //github.com/ Creates a new lazy value with the given initializing function.
83+ //github.com/
84+ //github.com/ # Examples
85+ //github.com/
86+ //github.com/ ```
87+ //github.com/ use std::sync::LazyLock;
88+ //github.com/
89+ //github.com/ let hello = "Hello, World!".to_string();
90+ //github.com/
91+ //github.com/ let lazy = LazyLock::new(|| hello.to_uppercase());
92+ //github.com/
93+ //github.com/ assert_eq!(&*lazy, "HELLO, WORLD!");
94+ //github.com/ ```
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 //github.com/ # Examples
108116 //github.com/
109117 //github.com/ ```
110- //github.com/ #![feature(lazy_cell)]
111118 //github.com/ #![feature(lazy_cell_consume)]
112119 //github.com/
113120 //github.com/ use std::sync::LazyLock;
@@ -145,8 +152,6 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
145152 //github.com/ # Examples
146153 //github.com/
147154 //github.com/ ```
148- //github.com/ #![feature(lazy_cell)]
149- //github.com/
150155 //github.com/ use std::sync::LazyLock;
151156 //github.com/
152157 //github.com/ let lazy = LazyLock::new(|| 92);
@@ -155,7 +160,7 @@ impl<T, F: FnOnce() -> T> LazyLock<T, F> {
155160 //github.com/ assert_eq!(&*lazy, &92);
156161 //github.com/ ```
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 //github.com/ 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