-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More inference-friendly API for lazy #103718
Conversation
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.
(rustbot has picked a reviewer for you, use r? to override) |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
@rustbot label +T-libs-api -T-libs |
let me ping a random T-libs person @yaahc for r+ :) |
r? libs-api |
@bors r+ |
…mpiler-errors Rollup of 9 pull requests Successful merges: - rust-lang#103718 (More inference-friendly API for lazy) - rust-lang#105765 (Detect likely `.` -> `..` typo in method calls) - rust-lang#105852 (Suggest rewriting a malformed hex literal if we expect a float) - rust-lang#105965 (Provide local extern function arg names) - rust-lang#106064 (Partially fix `explicit_outlives_requirements` lint in macros) - rust-lang#106179 (Fix a formatting error in Iterator::for_each docs) - rust-lang#106181 (Fix doc comment parsing description in book) - rust-lang#106187 (Update the documentation of `Vec` to use `extend(array)` instead of `extend(array.iter().copied())`) - rust-lang#106189 (Fix UnsafeCell Documentation Spelling Error) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
The signature for new was
Notably, with
F
unconstrained,T
can be literally anything, and justlet _ = Lazy::new(|| 92)
would not typecheck.This historiacally was a necessity --
new
is aconst
function, it couldn't have any bounds. Today though, we can movenew
under theF: FnOnce() -> T
bound, which gives the compiler enough data to infer the type of T from closure.