Make Global and System allocators unstably implement const Clone + const Default.#159471
Make Global and System allocators unstably implement const Clone + const Default.#159471kpreid wants to merge 1 commit into
Global and System allocators unstably implement const Clone + const Default.#159471Conversation
…Default`.
This is useful for generically constructing empty collections:
struct Foo<A: Allocator>(Vec<i32, A>);
impl<A: Allocator + const Default> Foo<A> {
pub const EMPTY: Self = Self(Vec::new_in(A::default()));
}
|
r? @clarfonthey rustbot has assigned @clarfonthey. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Based upon the ruling in #155816 I'm tempted to just close this. You can already construct both of these in const code because they're just ZSTs with public constructors, and even though adding const traits is easy, similarly, this means we can do that later. |
You can’t construct them in generic const code. Well, can’t without defining your own |
|
Right, so, I had missed the discussion on Zulip, and you're right these should be reasonable to add. Sorry for the confusion. @bors r+ rollup |
Allocators implementing
const Defaultis useful for generically constructing empty collections inside of constants:const Cloneis not strictly necessary to permit such constants to exist, but may make more complex code easier to write (e.g. so a const constructor can accept one allocator and clone it).@rustbot label +A-allocators