]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #103718 - matklad:infer-lazy, r=dtolnay
authorMichael Goulet <michael@errs.io>
Tue, 27 Dec 2022 20:33:33 +0000 (12:33 -0800)
committerGitHub <noreply@github.com>
Tue, 27 Dec 2022 20:33:33 +0000 (12:33 -0800)
More inference-friendly API for lazy

The signature for new was

```
fn new<F>(f: F) -> Lazy<T, F>
```

Notably, with `F` unconstrained, `T` can be literally anything, and just `let _ = Lazy::new(|| 92)` would not typecheck.

This historiacally was a necessity -- `new` is a `const` function, it couldn't have any bounds. Today though, we can move `new` under the `F: FnOnce() -> T` bound, which gives the compiler enough data to infer the type of T from closure.

1  2 
library/core/src/cell/lazy.rs
library/std/src/sync/lazy_lock.rs

Simple merge
Simple merge