Skip to content

Commit af9168c

Browse files
committed
Implement Hash for core::alloc::Layout
1 parent f1f721e commit af9168c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

library/core/src/alloc/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const fn size_align<T>() -> (usize, usize) {
2626
/// like this are met, use specific allocators with looser
2727
/// requirements, or use the more lenient `Allocator` interface.)
2828
#[stable(feature = "alloc_layout", since = "1.28.0")]
29-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
29+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
3030
#[lang = "alloc_layout"]
3131
pub struct Layout {
3232
// size of the requested block of memory, measured in bytes.

library/core/src/mem/valid_align.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::convert::TryFrom;
22
use crate::num::NonZeroUsize;
3-
use crate::{cmp, fmt, mem, num};
3+
use crate::{cmp, fmt, hash, mem, num};
44

55
/// A type storing a `usize` which is a power of two, and thus
66
/// represents a possible alignment in the rust abstract machine.
@@ -105,6 +105,13 @@ impl cmp::PartialOrd for ValidAlign {
105105
}
106106
}
107107

108+
impl hash::Hash for ValidAlign {
109+
#[inline]
110+
fn hash<H: hash::Hasher>(&self, state: &mut H) {
111+
self.as_nonzero().hash(state)
112+
}
113+
}
114+
108115
#[cfg(target_pointer_width = "16")]
109116
type ValidAlignEnum = ValidAlignEnum16;
110117
#[cfg(target_pointer_width = "32")]

0 commit comments

Comments
 (0)