Skip to content

Commit

Permalink
Implement Hash for core::alloc::Layout
Browse files Browse the repository at this point in the history
  • Loading branch information
fee1-dead committed May 14, 2022
1 parent f1f721e commit af9168c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion library/core/src/alloc/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const fn size_align<T>() -> (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.
Expand Down
9 changes: 8 additions & 1 deletion library/core/src/mem/valid_align.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -105,6 +105,13 @@ impl cmp::PartialOrd for ValidAlign {
}
}

impl hash::Hash for ValidAlign {
#[inline]
fn hash<H: hash::Hasher>(&self, state: &mut H) {
self.as_nonzero().hash(state)
}
}

#[cfg(target_pointer_width = "16")]
type ValidAlignEnum = ValidAlignEnum16;
#[cfg(target_pointer_width = "32")]
Expand Down

0 comments on commit af9168c

Please sign in to comment.