-
Notifications
You must be signed in to change notification settings - Fork 14k
constify from_fn, try_from_fn, try_map, map #147071
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
base: main
Are you sure you want to change the base?
Conversation
4134ec0 to
b09b6de
Compare
This comment has been minimized.
This comment has been minimized.
b09b6de to
a702598
Compare
This comment has been minimized.
This comment has been minimized.
a702598 to
4029d42
Compare
This comment has been minimized.
This comment has been minimized.
4029d42 to
79879c4
Compare
|
r? @ibraheemdev rustbot has assigned @ibraheemdev. Use |
library/core/src/array/mod.rs
Outdated
| else { | ||
| // SAFETY: this slice will contain only initialized objects. | ||
| unsafe { | ||
| x.array_mut.get_unchecked_mut(..x.initialized).assume_init_drop(); |
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.
What part of this isn't const evaluable? The get_unchecked_mut?
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.
assume_init_drop, and changing it to be const had some rammifications for some reason, causing some tests to fail. #147071 (comment)
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.
Looks like just trivial stderr file changes. Feel free to just bless them.
But is that code path testable in const? Since it's only happening in a panic path, I think it's unreachable anyway in const contexts. They never unwind and never will unwind. So maybe just document that and move the entire drop method body into the non-const code path... Or can we keep it non-const and avoid any drop happening for it by "disarming it" in the success path?
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.
its used in try_from_fn, so it can get dropped in const context?
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.
Ah right. Hmm. Wondering how to write an observable test for this. I think if you use a type with a reference to a Cell and in its const drop impl increment that cell, you should see in a const context that the cell isn't incremented if try_map errors/returns None.
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.
Ah oops, wanted to write this test but forgot about it when I was on a computer.
Need to reinvestigate this to get it all back into cache.
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.
It oughtnt really be needed now, as the behaviour is identical to the non const version?
|
The Miri subtree was changed cc @rust-lang/miri |
e95a529 to
0021344
Compare
43edafa to
7bec7a4
Compare
This comment has been minimized.
This comment has been minimized.
library/core/src/array/drain.rs
Outdated
| where | ||
| F: [const] FnMut(T) -> U, | ||
| { | ||
| extern "rust-call" fn call_mut(&mut self, (i,): (usize,)) -> Self::Output { |
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.
it would be possible to ignore this i and just use moved, but, uh, i think that would be somewhat confusing.
7bec7a4 to
1f0bdad
Compare
library/core/src/array/drain.rs
Outdated
| func(drain) | ||
| #[rustc_const_unstable(feature = "array_try_map", issue = "79711")] | ||
| #[unstable(feature = "array_try_map", issue = "79711")] | ||
| pub(super) struct Drain<'a, T, U, const N: usize, F: FnMut(T) -> U> { |
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.
The previous version had lots of docs explaining the weirdness of the type. Please add docs explaining what this type does and that it's emulating iterators which don't exist in const yet. Also add const hack fixmes
5c8cedc to
fb0881f
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
68ef964 to
3e911ad
Compare
This comment has been minimized.
This comment has been minimized.
3e911ad to
998c680
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
f435a2d to
03360fe
Compare
This comment has been minimized.
This comment has been minimized.
d2077d0 to
21593b2
Compare
This comment has been minimized.
This comment has been minimized.
21593b2 to
b113fb3
Compare
This comment has been minimized.
This comment has been minimized.
5abb182 to
598437f
Compare
598437f to
0011ff0
Compare
adds the
const_arrayfeaturereimplements
try_mapin more or less the same way