Skip to content

Commit e6cbedc

Browse files
committed
Stabilize a portion of 'once_cell'
Move items not part of this stabilization to 'lazy_cell' or 'once_cell_try'
1 parent e25c4fa commit e6cbedc

File tree

9 files changed

+68
-92
lines changed

9 files changed

+68
-92
lines changed

alloc/tests/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#![feature(slice_flatten)]
4444
#![feature(thin_box)]
4545
#![feature(strict_provenance)]
46-
#![feature(once_cell)]
4746
#![feature(drain_keep_rest)]
4847
#![deny(fuzzy_provenance_casts)]
4948
#![deny(unsafe_op_in_unsafe_fn)]

core/src/cell.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ use crate::ptr::{self, NonNull};
202202
mod lazy;
203203
mod once;
204204

205-
#[unstable(feature = "once_cell", issue = "74465")]
205+
#[unstable(feature = "lazy_cell", issue = "109736")]
206206
pub use lazy::LazyCell;
207-
#[unstable(feature = "once_cell", issue = "74465")]
207+
#[stable(feature = "once_cell", since = "CURRENT_RUSTC_VERSION")]
208208
pub use once::OnceCell;
209209

210210
/// A mutable memory location.

core/src/cell/lazy.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::ops::Deref;
1111
/// # Examples
1212
///
1313
/// ```
14-
/// #![feature(once_cell)]
14+
/// #![feature(lazy_cell)]
1515
///
1616
/// use std::cell::LazyCell;
1717
///
@@ -29,7 +29,7 @@ use crate::ops::Deref;
2929
/// // 92
3030
/// // 92
3131
/// ```
32-
#[unstable(feature = "once_cell", issue = "74465")]
32+
#[unstable(feature = "lazy_cell", issue = "109736")]
3333
pub struct LazyCell<T, F = fn() -> T> {
3434
cell: OnceCell<T>,
3535
init: Cell<Option<F>>,
@@ -41,7 +41,7 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
4141
/// # Examples
4242
///
4343
/// ```
44-
/// #![feature(once_cell)]
44+
/// #![feature(lazy_cell)]
4545
///
4646
/// use std::cell::LazyCell;
4747
///
@@ -52,7 +52,7 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
5252
/// assert_eq!(&*lazy, "HELLO, WORLD!");
5353
/// ```
5454
#[inline]
55-
#[unstable(feature = "once_cell", issue = "74465")]
55+
#[unstable(feature = "lazy_cell", issue = "109736")]
5656
pub const fn new(init: F) -> LazyCell<T, F> {
5757
LazyCell { cell: OnceCell::new(), init: Cell::new(Some(init)) }
5858
}
@@ -65,7 +65,7 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
6565
/// # Examples
6666
///
6767
/// ```
68-
/// #![feature(once_cell)]
68+
/// #![feature(lazy_cell)]
6969
///
7070
/// use std::cell::LazyCell;
7171
///
@@ -75,7 +75,7 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
7575
/// assert_eq!(&*lazy, &92);
7676
/// ```
7777
#[inline]
78-
#[unstable(feature = "once_cell", issue = "74465")]
78+
#[unstable(feature = "lazy_cell", issue = "109736")]
7979
pub fn force(this: &LazyCell<T, F>) -> &T {
8080
this.cell.get_or_init(|| match this.init.take() {
8181
Some(f) => f(),
@@ -84,7 +84,7 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
8484
}
8585
}
8686

87-
#[unstable(feature = "once_cell", issue = "74465")]
87+
#[unstable(feature = "lazy_cell", issue = "109736")]
8888
impl<T, F: FnOnce() -> T> Deref for LazyCell<T, F> {
8989
type Target = T;
9090
#[inline]
@@ -93,7 +93,7 @@ impl<T, F: FnOnce() -> T> Deref for LazyCell<T, F> {
9393
}
9494
}
9595

96-
#[unstable(feature = "once_cell", issue = "74465")]
96+
#[unstable(feature = "lazy_cell", issue = "109736")]
9797
impl<T: Default> Default for LazyCell<T> {
9898
/// Creates a new lazy value using `Default` as the initializing function.
9999
#[inline]
@@ -102,7 +102,7 @@ impl<T: Default> Default for LazyCell<T> {
102102
}
103103
}
104104

105-
#[unstable(feature = "once_cell", issue = "74465")]
105+
#[unstable(feature = "lazy_cell", issue = "109736")]
106106
impl<T: fmt::Debug, F> fmt::Debug for LazyCell<T, F> {
107107
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
108108
f.debug_struct("Lazy").field("cell", &self.cell).field("init", &"..").finish()

core/src/cell/once.rs

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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")]
3331
pub 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")]
250241
impl<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")]
258249
impl<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")]
268259
impl<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")]
283274
impl<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")]
291282
impl<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")]
294286
impl<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")]
304296
impl<T> !Sync for OnceCell<T> {}

core/tests/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
#![feature(pointer_is_aligned)]
9595
#![feature(portable_simd)]
9696
#![feature(ptr_metadata)]
97-
#![feature(once_cell)]
97+
#![feature(lazy_cell)]
9898
#![feature(unsized_tuple_coercion)]
9999
#![feature(const_option)]
100100
#![feature(const_option_ext)]

std/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@
339339
#![feature(edition_panic)]
340340
#![feature(format_args_nl)]
341341
#![feature(log_syntax)]
342-
#![feature(once_cell)]
342+
#![feature(lazy_cell)]
343343
#![feature(saturating_int_impl)]
344344
#![feature(stdsimd)]
345345
#![feature(test)]

0 commit comments

Comments
 (0)