Skip to content

Commit 203ea0d

Browse files
committed
Auto merge of #106193 - compiler-errors:rollup-0l54wka, r=compiler-errors
Rollup of 9 pull requests Successful merges: - #103718 (More inference-friendly API for lazy) - #105765 (Detect likely `.` -> `..` typo in method calls) - #105852 (Suggest rewriting a malformed hex literal if we expect a float) - #105965 (Provide local extern function arg names) - #106064 (Partially fix `explicit_outlives_requirements` lint in macros) - #106179 (Fix a formatting error in Iterator::for_each docs) - #106181 (Fix doc comment parsing description in book) - #106187 (Update the documentation of `Vec` to use `extend(array)` instead of `extend(array.iter().copied())`) - #106189 (Fix UnsafeCell Documentation Spelling Error) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4e6710c + 4912e11 commit 203ea0d

File tree

7 files changed

+17
-10
lines changed

7 files changed

+17
-10
lines changed

alloc/src/vec/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ mod spec_extend;
166166
/// vec[0] = 7;
167167
/// assert_eq!(vec[0], 7);
168168
///
169-
/// vec.extend([1, 2, 3].iter().copied());
169+
/// vec.extend([1, 2, 3]);
170170
///
171171
/// for x in &vec {
172172
/// println!("{x}");

core/src/cell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1783,7 +1783,7 @@ impl<T: ?Sized + fmt::Display> fmt::Display for RefMut<'_, T> {
17831783
/// until the reference expires. As a special exception, given an `&T`, any part of it that is
17841784
/// inside an `UnsafeCell<_>` may be deallocated during the lifetime of the reference, after the
17851785
/// last time the reference is used (dereferenced or reborrowed). Since you cannot deallocate a part
1786-
/// of what a reference points to, this means the memory an `&T` points to can be deallocted only if
1786+
/// of what a reference points to, this means the memory an `&T` points to can be deallocated only if
17871787
/// *every part of it* (including padding) is inside an `UnsafeCell`.
17881788
///
17891789
/// However, whenever a `&UnsafeCell<T>` is constructed or dereferenced, it must still point to

core/src/cell/lazy.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct LazyCell<T, F = fn() -> T> {
3535
init: Cell<Option<F>>,
3636
}
3737

38-
impl<T, F> LazyCell<T, F> {
38+
impl<T, F: FnOnce() -> T> LazyCell<T, F> {
3939
/// Creates a new lazy value with the given initializing function.
4040
///
4141
/// # Examples
@@ -55,9 +55,7 @@ impl<T, F> LazyCell<T, F> {
5555
pub const fn new(init: F) -> LazyCell<T, F> {
5656
LazyCell { cell: OnceCell::new(), init: Cell::new(Some(init)) }
5757
}
58-
}
5958

60-
impl<T, F: FnOnce() -> T> LazyCell<T, F> {
6159
/// Forces the evaluation of this lazy value and returns a reference to
6260
/// the result.
6361
///

core/src/iter/traits/iterator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ pub trait Iterator {
803803
/// (0..5).map(|x| x * 2 + 1)
804804
/// .for_each(move |x| tx.send(x).unwrap());
805805
///
806-
/// let v: Vec<_> = rx.iter().collect();
806+
/// let v: Vec<_> = rx.iter().collect();
807807
/// assert_eq!(v, vec![1, 3, 5, 7, 9]);
808808
/// ```
809809
///

core/tests/lazy.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ fn lazy_new() {
106106
assert_eq!(called.get(), 1);
107107
}
108108

109+
// Check that we can infer `T` from closure's type.
110+
#[test]
111+
fn lazy_type_inference() {
112+
let _ = LazyCell::new(|| ());
113+
}
114+
109115
#[test]
110116
fn aliasing_in_get() {
111117
let x = OnceCell::new();

std/src/sync/lazy_lock.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,14 @@ pub struct LazyLock<T, F = fn() -> T> {
4646
cell: OnceLock<T>,
4747
init: Cell<Option<F>>,
4848
}
49-
50-
impl<T, F> LazyLock<T, F> {
49+
impl<T, F: FnOnce() -> T> LazyLock<T, F> {
5150
/// Creates a new lazy value with the given initializing
5251
/// function.
5352
#[unstable(feature = "once_cell", issue = "74465")]
5453
pub const fn new(f: F) -> LazyLock<T, F> {
5554
LazyLock { cell: OnceLock::new(), init: Cell::new(Some(f)) }
5655
}
57-
}
5856

59-
impl<T, F: FnOnce() -> T> LazyLock<T, F> {
6057
/// Forces the evaluation of this lazy value and
6158
/// returns a reference to result. This is equivalent
6259
/// to the `Deref` impl, but is explicit.

std/src/sync/lazy_lock/tests.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ fn sync_lazy_poisoning() {
136136
}
137137
}
138138

139+
// Check that we can infer `T` from closure's type.
140+
#[test]
141+
fn lazy_type_inference() {
142+
let _ = LazyCell::new(|| ());
143+
}
144+
139145
#[test]
140146
fn is_sync_send() {
141147
fn assert_traits<T: Send + Sync>() {}

0 commit comments

Comments
 (0)