libstd: Use std::array::from_fn to implement Default for arrays larger than 32 elements.#124163
libstd: Use std::array::from_fn to implement Default for arrays larger than 32 elements.#124163emilio wants to merge 1 commit intorust-lang:masterfrom
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.
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.
Oh... I totally misread that, ugh
There was a problem hiding this comment.
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.
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.
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