Skip to content

Commit fc60244

Browse files
authored
Unrolled build for rust-lang#129334
Rollup merge of rust-lang#129334 - ChayimFriedman2:more-lazy-methods, r=Amanieu Implement (part of) ACP 429: add `DerefMut` to `Lazy[Cell/Lock]` `DerefMut` is instantly stable, as a trait impl. That means this needs an FCP. ``@rustbot`` label +needs-fcp rust-lang/libs-team#429
2 parents b105556 + b208706 commit fc60244

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

library/core/src/cell/lazy.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::UnsafeCell;
22
use crate::hint::unreachable_unchecked;
3-
use crate::ops::Deref;
3+
use crate::ops::{Deref, DerefMut};
44
use crate::{fmt, mem};
55

66
enum State<T, F> {
@@ -284,6 +284,14 @@ impl<T, F: FnOnce() -> T> Deref for LazyCell<T, F> {
284284
}
285285
}
286286

287+
#[stable(feature = "lazy_deref_mut", since = "CURRENT_RUSTC_VERSION")]
288+
impl<T, F: FnOnce() -> T> DerefMut for LazyCell<T, F> {
289+
#[inline]
290+
fn deref_mut(&mut self) -> &mut T {
291+
LazyCell::force_mut(self)
292+
}
293+
}
294+
287295
#[stable(feature = "lazy_cell", since = "1.80.0")]
288296
impl<T: Default> Default for LazyCell<T> {
289297
/// Creates a new lazy value using `Default` as the initializing function.

library/std/src/sync/lazy_lock.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::poison::once::ExclusiveState;
22
use crate::cell::UnsafeCell;
33
use crate::mem::ManuallyDrop;
4-
use crate::ops::Deref;
4+
use crate::ops::{Deref, DerefMut};
55
use crate::panic::{RefUnwindSafe, UnwindSafe};
66
use crate::sync::Once;
77
use crate::{fmt, ptr};
@@ -313,6 +313,14 @@ impl<T, F: FnOnce() -> T> Deref for LazyLock<T, F> {
313313
}
314314
}
315315

316+
#[stable(feature = "lazy_deref_mut", since = "CURRENT_RUSTC_VERSION")]
317+
impl<T, F: FnOnce() -> T> DerefMut for LazyLock<T, F> {
318+
#[inline]
319+
fn deref_mut(&mut self) -> &mut T {
320+
LazyLock::force_mut(self)
321+
}
322+
}
323+
316324
#[stable(feature = "lazy_cell", since = "1.80.0")]
317325
impl<T: Default> Default for LazyLock<T> {
318326
/// Creates a new lazy value using `Default` as the initializing function.

0 commit comments

Comments
 (0)