diff --git a/library/core/src/alloc/layout.rs b/library/core/src/alloc/layout.rs index cf864039a23bad947491e70efc956af49c63807e..2f378836cbbb37619ac0a6f020c8ea356931e8e1 100644 --- a/library/core/src/alloc/layout.rs +++ b/library/core/src/alloc/layout.rs @@ -26,7 +26,7 @@ const fn size_align() -> (usize, usize) { /// like this are met, use specific allocators with looser /// requirements, or use the more lenient `Allocator` interface.) #[stable(feature = "alloc_layout", since = "1.28.0")] -#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[lang = "alloc_layout"] pub struct Layout { // size of the requested block of memory, measured in bytes. diff --git a/library/core/src/mem/valid_align.rs b/library/core/src/mem/valid_align.rs index 596a67f255a1bbcf3cbe003cbc8daab3903f57cf..fcfa95120df21e94d9c6f8c0b3f4c76026a0aa5b 100644 --- a/library/core/src/mem/valid_align.rs +++ b/library/core/src/mem/valid_align.rs @@ -1,6 +1,6 @@ use crate::convert::TryFrom; use crate::num::NonZeroUsize; -use crate::{cmp, fmt, mem, num}; +use crate::{cmp, fmt, hash, mem, num}; /// A type storing a `usize` which is a power of two, and thus /// represents a possible alignment in the rust abstract machine. @@ -105,6 +105,13 @@ fn partial_cmp(&self, other: &Self) -> Option { } } +impl hash::Hash for ValidAlign { + #[inline] + fn hash(&self, state: &mut H) { + self.as_nonzero().hash(state) + } +} + #[cfg(target_pointer_width = "16")] type ValidAlignEnum = ValidAlignEnum16; #[cfg(target_pointer_width = "32")]