-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
libstd: Use std::array::from_fn to implement Default for arrays larger than 32 elements. #124163
Conversation
cc some of the people involved in #74060: @withoutboats @nikomatsakis @SimonSapin |
This comment has been minimized.
This comment has been minimized.
…r than 32 elements. Much like rust-lang#74060 did for every other trait. This avoids tools like rust-bindgen having to painfully work around this limitations, sometimes incorrectly like in rust-lang/rust-bindgen#2803
d64dbff
to
df4b27c
Compare
fn default() -> [T; $n] { [] } | ||
} | ||
}; | ||
#[stable(feature = "default_array_lib", since = "1.79.0")] |
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 don't know if this is the right thing to do annotation wise.
// The Default impls cannot be done with const generics because `[T; 0]` doesn't | ||
// require Default to be implemented, and having different impl blocks for | ||
// different numbers isn't supported yet. |
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.
Is this resolved?
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.
Oh... I totally misread that, ugh
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.
So I could fix this by using a conditional impl using generic_const_exprs, but that causes a bunch of other code in libcore to fail to build, see #124167
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.
Is there any other clever way of getting this to work out of curiosity? (Not familiar with the specialisation features that are available in nightly)
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.
generic_const_exprs is very much forbidden from being used on the standard library, no matter this issue. it's way too broken for that.
Closing for the reason stated. There is no way that this can currently be done in the standard library, as the necessary features are simply not mature enough. Personally, the last time I tried to implement |
Much like #74060 did for every other trait.
This avoids tools like rust-bindgen having to painfully work around this limitations, sometimes incorrectly like in
rust-lang/rust-bindgen#2803