Skip to content

Commit 7bac055

Browse files
authored
Unrolled build for rust-lang#139273
Rollup merge of rust-lang#139273 - tgross35:cell-update-changes, r=jhpratt Apply requested API changes to `cell_update` Do the following: * Switch to `impl FnOnce` rather than a generic `F`. * Change `update` to return nothing. This was discussed at a libs-api meeting [1]. Tracking issue: rust-lang#50186 [1]: rust-lang#134446 (comment)
2 parents 946aea0 + 072aa9e commit 7bac055

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

Diff for: library/core/src/cell.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ impl<T: Copy> Cell<T> {
544544
unsafe { *self.value.get() }
545545
}
546546

547-
/// Updates the contained value using a function and returns the new value.
547+
/// Updates the contained value using a function.
548548
///
549549
/// # Examples
550550
///
@@ -554,21 +554,14 @@ impl<T: Copy> Cell<T> {
554554
/// use std::cell::Cell;
555555
///
556556
/// let c = Cell::new(5);
557-
/// let new = c.update(|x| x + 1);
558-
///
559-
/// assert_eq!(new, 6);
557+
/// c.update(|x| x + 1);
560558
/// assert_eq!(c.get(), 6);
561559
/// ```
562560
#[inline]
563561
#[unstable(feature = "cell_update", issue = "50186")]
564-
pub fn update<F>(&self, f: F) -> T
565-
where
566-
F: FnOnce(T) -> T,
567-
{
562+
pub fn update(&self, f: impl FnOnce(T) -> T) {
568563
let old = self.get();
569-
let new = f(old);
570-
self.set(new);
571-
new
564+
self.set(f(old));
572565
}
573566
}
574567

Diff for: library/coretests/tests/cell.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ fn smoketest_cell() {
5050
fn cell_update() {
5151
let x = Cell::new(10);
5252

53-
assert_eq!(x.update(|x| x + 5), 15);
53+
x.update(|x| x + 5);
5454
assert_eq!(x.get(), 15);
5555

56-
assert_eq!(x.update(|x| x / 3), 5);
56+
x.update(|x| x / 3);
5757
assert_eq!(x.get(), 5);
5858
}
5959

0 commit comments

Comments
 (0)