-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
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. |
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
We discussed this in the @rust-lang/libs-api meeting today. We are happy to remove As such we would like to:
|
@Amanieu What should be done with the usage of |
☔ The latest upstream changes (presumably #116113) made this pull request unmergeable. Please resolve the merge conflicts. |
Presumably the answer would be deprecating the method and pointing to the tracking issue to get more feedback? I still think that the correct answer would be the ability to index into |
I would like to accept all the other changes in this PR other than the deletion of the function. I think we should go ahead and use our own recommended replacement in rustc that we are recommending everyone outside rustc to use. I would also accept a
@clarfonthey do you have a link to this getting shot down? I am on board with this |
I don't have any specific examples of an Most of them concern specifically impls for Of course, for arrays, that restriction doesn't apply. |
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()` other than convenience. Therefore, let’s evaluate the inconvenience by not using `uninit_array()` in the standard library, before potentially deleting it entirely.
Updated. |
@bors r+ |
…mpiler-errors Rollup of 11 pull requests Successful merges: - rust-lang#124460 (Show notice about "never used" of Debug for enum) - rust-lang#124712 (Deprecate no-op codegen option `-Cinline-threshold=...`) - rust-lang#125082 (Remove `MaybeUninit::uninit_array()` and replace it with inline const blocks.) - rust-lang#125575 (SmartPointer derive-macro) - rust-lang#126413 (compiletest: make the crash test error message abit more informative) - rust-lang#126673 (Ensure we don't accidentally succeed when we want to report an error) - rust-lang#126682 (coverage: Overhaul validation of the `#[coverage(..)]` attribute) - rust-lang#126899 (Suggest inline const blocks for array initialization) - rust-lang#126904 (Small fixme in core now that NonZero is generic) - rust-lang#126909 (add `@kobzol` to bootstrap team for triagebot) - rust-lang#126911 (Split the lifetimes of `MirBorrowckCtxt`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#125082 - kpreid:const-uninit, r=dtolnay Remove `MaybeUninit::uninit_array()` and replace it with inline const blocks. \[This PR originally contained the changes in rust-lang#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](rust-lang#76001). The example below could then use `let mut buf = [const { MaybeUninit::<u8>::uninit() }; 32];`. The PR adding it also said: <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];` 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.
[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.