summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_middle/src/mir/interpret/allocation.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:29 +0000
commit631cd5845e8de329d0e227aaa707d7ea228b8f8f (patch)
treea1b87c8f8cad01cf18f7c5f57a08f102771ed303 /compiler/rustc_middle/src/mir/interpret/allocation.rs
parentAdding debian version 1.69.0+dfsg1-1. (diff)
downloadrustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.tar.xz
rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_middle/src/mir/interpret/allocation.rs')
-rw-r--r--compiler/rustc_middle/src/mir/interpret/allocation.rs28
1 files changed, 17 insertions, 11 deletions
diff --git a/compiler/rustc_middle/src/mir/interpret/allocation.rs b/compiler/rustc_middle/src/mir/interpret/allocation.rs
index 48375ed30..1a8e48264 100644
--- a/compiler/rustc_middle/src/mir/interpret/allocation.rs
+++ b/compiler/rustc_middle/src/mir/interpret/allocation.rs
@@ -2,8 +2,6 @@
mod init_mask;
mod provenance_map;
-#[cfg(test)]
-mod tests;
use std::borrow::Cow;
use std::fmt;
@@ -111,26 +109,34 @@ const MAX_HASHED_BUFFER_LEN: usize = 2 * MAX_BYTES_TO_HASH;
// large.
impl hash::Hash for Allocation {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
+ let Self {
+ bytes,
+ provenance,
+ init_mask,
+ align,
+ mutability,
+ extra: (), // don't bother hashing ()
+ } = self;
+
// Partially hash the `bytes` buffer when it is large. To limit collisions with common
// prefixes and suffixes, we hash the length and some slices of the buffer.
- let byte_count = self.bytes.len();
+ let byte_count = bytes.len();
if byte_count > MAX_HASHED_BUFFER_LEN {
// Hash the buffer's length.
byte_count.hash(state);
// And its head and tail.
- self.bytes[..MAX_BYTES_TO_HASH].hash(state);
- self.bytes[byte_count - MAX_BYTES_TO_HASH..].hash(state);
+ bytes[..MAX_BYTES_TO_HASH].hash(state);
+ bytes[byte_count - MAX_BYTES_TO_HASH..].hash(state);
} else {
- self.bytes.hash(state);
+ bytes.hash(state);
}
// Hash the other fields as usual.
- self.provenance.hash(state);
- self.init_mask.hash(state);
- self.align.hash(state);
- self.mutability.hash(state);
- self.extra.hash(state);
+ provenance.hash(state);
+ init_mask.hash(state);
+ align.hash(state);
+ mutability.hash(state);
}
}