-
Notifications
You must be signed in to change notification settings - Fork 12.1k
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
Remove MaybeUninit::uninit_array()
and replace it with inline const blocks.
#125082
base: master
Are you sure you want to change the base?
Conversation
r? @Nilstrieb rustbot has assigned @Nilstrieb. Use |
I still prefer |
The examples and the compiler code should probably still prefer the stable option. Technically the compared-against example was |
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. |
Split out the first two parts into #125995. I'll re-summarize this PR once that's merged. |
…trieb Use inline const blocks to create arrays of `MaybeUninit`. This PR contains 2 changes enabled by the fact that [`inline_const` is now stable](rust-lang#104087), and was split out of rust-lang#125082. 1. Use inline const instead of `unsafe` to construct arrays in `MaybeUninit` examples. Rationale: Demonstrate good practice of avoiding `unsafe` code where it is not strictly necessary. 4. Use inline const instead of `unsafe` to implement `MaybeUninit::uninit_array()`. This is arguably giving the compiler more work to do, in exchange for eliminating just one single internal unsafe block, so it's less certain that this is good on net. r? `@Nilstrieb`
…trieb Use inline const blocks to create arrays of `MaybeUninit`. This PR contains 2 changes enabled by the fact that [`inline_const` is now stable](rust-lang#104087), and was split out of rust-lang#125082. 1. Use inline const instead of `unsafe` to construct arrays in `MaybeUninit` examples. Rationale: Demonstrate good practice of avoiding `unsafe` code where it is not strictly necessary. 4. Use inline const instead of `unsafe` to implement `MaybeUninit::uninit_array()`. This is arguably giving the compiler more work to do, in exchange for eliminating just one single internal unsafe block, so it's less certain that this is good on net. r? `@Nilstrieb`
Rollup merge of rust-lang#125995 - kpreid:const-uninit-stable, r=Nilstrieb Use inline const blocks to create arrays of `MaybeUninit`. This PR contains 2 changes enabled by the fact that [`inline_const` is now stable](rust-lang#104087), and was split out of rust-lang#125082. 1. Use inline const instead of `unsafe` to construct arrays in `MaybeUninit` examples. Rationale: Demonstrate good practice of avoiding `unsafe` code where it is not strictly necessary. 4. Use inline const instead of `unsafe` to implement `MaybeUninit::uninit_array()`. This is arguably giving the compiler more work to do, in exchange for eliminating just one single internal unsafe block, so it's less certain that this is good on net. r? `@Nilstrieb`
☔ The latest upstream changes (presumably #126016) made this pull request unmergeable. Please resolve the merge conflicts. |
This is possible now that inline const blocks are stable; the idea was even mentioned as an alternative when `uninit_array()` was added: <rust-lang#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];` Const array repetition and inline const blocks are now stable (in the next release), so that circumstance has come to pass, and we no longer have reason to want `uninit_array()` (unless the repeat syntax is too annoying).
MaybeUninit
; remove uninit_array()
.MaybeUninit::uninit_array()
and replace it with inline const blocks.
This PR now consists solely of removing |
There was a problem hiding this 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
[This PR originally contained the changes in #125995 too. See edit history for the original PR description.]
The documentation of
MaybeUninit::uninit_array()
says:The PR adding it also said: #65580 (comment)
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.