Skip to content

Conversation

@kpreid
Copy link
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.

@rustbot
Copy link
Collaborator

rustbot commented May 13, 2024

r? @Nilstrieb

rustbot has assigned @Nilstrieb.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 13, 2024
@ChayimFriedman2
Copy link
Contributor

I still prefer MaybeUninit::uninit_array() to [const { MaybeUninit::uninit() }; N], it's shorter and more readable IMHO.

@workingjubilee
Copy link
Member

The examples and the compiler code should probably still prefer the stable option.

Technically the compared-against example was [MaybeUninit::uninit(); N], which implies that the array initializer is a const context.

@Noratrieb
Copy link
Member

this fell down into the "i hope to get to this eventually but will probably never lol" part of my notification queue and i forgot to look at it again, sorry.
you have my approval for the first two commits, but I'd like a libs-api opinion on the last one. you can split out the first two into a new PR and i'll approve that, or you can keep them all like this if you're okay with letting the first two wait longer (as it will probably take a bit).
r? libs-api

@rustbot rustbot added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jun 4, 2024
@rustbot rustbot assigned dtolnay and unassigned Noratrieb Jun 4, 2024
@kpreid
Copy link
Contributor Author

kpreid commented Jun 4, 2024

Split out the first two parts into #125995. I'll re-summarize this PR once that's merged.

@bors
Copy link
Collaborator

bors commented Jun 5, 2024

☔ The latest upstream changes (presumably #126016) made this pull request unmergeable. Please resolve the merge conflicts.

@kpreid kpreid changed the title Use inline const blocks to create arrays of MaybeUninit; remove uninit_array(). Remove MaybeUninit::uninit_array() and replace it with inline const blocks. Jun 5, 2024
@kpreid
Copy link
Contributor Author

kpreid commented Jun 5, 2024

This PR now consists solely of removing MaybeUninit::uninit_array().

@dtolnay dtolnay removed O-windows Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 5, 2024
@rustbot rustbot added the O-windows Operating system: Windows label Jun 5, 2024
Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I am attempting to start a T-libs-api FCP for this in #96097 (comment).

https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/rfcbot.20asleep

@dtolnay dtolnay removed O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 5, 2024
@kpreid kpreid deleted the const-uninit branch March 19, 2025 02:03
@kpreid kpreid changed the title Remove MaybeUninit::uninit_array() and replace it with inline const blocks. Replace uses of MaybeUninit::uninit_array() with inline const blocks. Mar 19, 2025
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.