Skip to content

Replace uses of MaybeUninit::uninit_array() with inline const blocks.#125082

Merged
bors merged 1 commit intorust-lang:masterfrom
kpreid:const-uninit
Jun 24, 2024
Merged

Replace uses of MaybeUninit::uninit_array() with inline const blocks.#125082
bors merged 1 commit intorust-lang:masterfrom
kpreid:const-uninit

Conversation

@kpreid
Copy link
Copy Markdown
Contributor

@kpreid kpreid commented May 13, 2024

[This PR originally contained the changes in #125995 too. See edit history for the original PR description.]

The documentation of MaybeUninit::uninit_array() says:

Note: in a future Rust version this method may become unnecessary when Rust allows inline const expressions. The example below could then use let mut buf = [const { MaybeUninit::<u8>::uninit() }; 32];.

The PR adding it also said: #65580 (comment)

if it’s stabilized soon enough maybe it’s not worth having a standard library method that will be replaceable with let buffer = [MaybeUninit::<T>::uninit(); $N];

That time has come to pass — inline const expressions are stable — so MaybeUninit::uninit_array() is now unnecessary. The only remaining question is whether it is an important enough convenience to keep it around.

I believe it is net good to remove this function, on the principle that it is better to compose two orthogonal features (MaybeUninit and array construction) than to have a specific function for the specific combination, now that that is possible.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants