-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Make slice comparisons const #143925
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: master
Are you sure you want to change the base?
Make slice comparisons const #143925
Conversation
This comment has been minimized.
This comment has been minimized.
494d350
to
c3b13bb
Compare
|
||
let mut attrs = thin_vec![cx.attr_word(sym::automatically_derived, self.span),]; | ||
|
||
if self.is_const && self.is_staged_api_crate { |
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.
There's clearly something interesting going on here, please add a comment explaining what.
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.
I'm fine with this being a temporary solution. To me, we should change #[derive_const(PartialEq)]
to something like #[derive(PartialEq(const))]
(syntax to-be-bikeshedded), then we can have #[derive(PartialEq(const, unstable))]
in all standard library crates.
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.
How does it know which feature gate to use...?
We're fairly close to actually enforcing feature stability on impls (#140399) so this question matters soon, IIUC.
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 doesn't. All derived const trait impls are under the derive_const
feature gate
@@ -115,11 +119,13 @@ where | |||
// Implemented as explicit indexing rather | |||
// than zipped iterators for performance reasons. | |||
// See PR https://github.com/rust-lang/rust/pull/116846 | |||
for idx in 0..self.len() { | |||
let mut idx = 0; | |||
while idx < self.len() { |
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.
This should get a FIXME(const-hack)
.
Also make it *only* usable on nightly
c3b13bb
to
19c2f1b
Compare
|
||
let mut attrs = thin_vec![cx.attr_word(sym::automatically_derived, self.span),]; | ||
|
||
if self.is_const && self.is_staged_api_crate { |
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.
I'm fine with this being a temporary solution. To me, we should change #[derive_const(PartialEq)]
to something like #[derive(PartialEq(const))]
(syntax to-be-bikeshedded), then we can have #[derive(PartialEq(const, unstable))]
in all standard library crates.
@bors r+ rollup |
This needed a fix for
derive_const
, too, as it wasn't usable in libcore anymore as trait impls need const stability attributes. I think we can't use the same system as normal trait impls whileconst_trait_impl
is still unstable.r? @fee1-dead
cc #143800