From 960804598acf4c3469aecaa16cc8a55068b21408 Mon Sep 17 00:00:00 2001 From: colin Date: Thu, 21 Jul 2022 18:31:31 -0700 Subject: [PATCH] coremem_types: enums don't require their variant to be Copy this is safe because the variant is necessarily not ZST. if it was ZST it could just be stored explicitly instead of folding it into the first element, and that case should still be OK. --- crates/types/src/compound/enumerated.rs | 4 ++-- crates/types/src/compound/list/flat.rs | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/types/src/compound/enumerated.rs b/crates/types/src/compound/enumerated.rs index b35d687..dbef77d 100644 --- a/crates/types/src/compound/enumerated.rs +++ b/crates/types/src/compound/enumerated.rs @@ -110,11 +110,11 @@ where impl EnumRequirements for Enum<(), L> where L: list::Meta + Indexable, - list::ElementAt: Copy + DiscriminantCodable<<::Length as PeanoNonZero>::Prev>, + list::ElementAt: DiscriminantCodable<<::Length as PeanoNonZero>::Prev>, { type MaxDiscr = <::Length as PeanoNonZero>::Prev; fn discr(&self) -> Discr { - self.1.get().discr() + self.1.get_ref().discr() } } diff --git a/crates/types/src/compound/list/flat.rs b/crates/types/src/compound/list/flat.rs index a2711bf..8f08062 100644 --- a/crates/types/src/compound/list/flat.rs +++ b/crates/types/src/compound/list/flat.rs @@ -32,6 +32,7 @@ impl Node { pub trait Indexable { type Element; fn get(&self) -> Self::Element where Self::Element: Copy; + fn get_ref(&self) -> &Self::Element; } impl Indexable for Node { @@ -39,6 +40,9 @@ impl Indexable for Node { fn get(&self) -> Self::Element where Self::Element: Copy { self.head } + fn get_ref(&self) -> &Self::Element { + &self.head + } } impl Indexable for Node> { @@ -46,6 +50,9 @@ impl Indexable for Node> { fn get(&self) -> Self::Element where Self::Element: Copy { self.tail.head } + fn get_ref(&self) -> &Self::Element { + &self.tail.head + } } impl Indexable for Node>> { @@ -53,6 +60,9 @@ impl Indexable for Node>> { fn get(&self) -> Self::Element where Self::Element: Copy { self.tail.tail.head } + fn get_ref(&self) -> &Self::Element { + &self.tail.tail.head + } } impl Indexable for Node>>> { @@ -60,6 +70,9 @@ impl Indexable for Node fn get(&self) -> Self::Element where Self::Element: Copy { self.tail.tail.tail.head } + fn get_ref(&self) -> &Self::Element { + &self.tail.tail.tail.head + } } pub trait IntoList {