Skip to content

Commit 4dee948

Browse files
committed
Hash interned values, not pointers
1 parent 827a0d6 commit 4dee948

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

compiler/rustc_data_structures/src/intern.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ where
9898
{
9999
#[inline]
100100
fn hash<H: Hasher>(&self, s: &mut H) {
101-
// Pointer hashing is sufficient, due to the uniqueness constraint.
102-
ptr::hash(self.0, s)
101+
Hash::hash(&self.0, s)
103102
}
104103
}
105104

compiler/rustc_resolve/src/imports.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,31 @@ pub(crate) type Import<'ra> = Interned<'ra, ImportData<'ra>>;
187187
// FIXME: We may wish to actually have at least debug-level assertions that Interned's guarantees
188188
// are upheld.
189189
impl std::hash::Hash for ImportData<'_> {
190-
fn hash<H>(&self, _: &mut H)
190+
fn hash<H>(&self, h: &mut H)
191191
where
192192
H: std::hash::Hasher,
193193
{
194-
unreachable!()
194+
let ImportData {
195+
kind: _,
196+
root_id,
197+
use_span,
198+
use_span_with_attributes,
199+
has_attributes,
200+
span,
201+
root_span,
202+
parent_scope: _,
203+
module_path: _,
204+
imported_module: _,
205+
vis,
206+
} = self;
207+
208+
root_id.hash(h);
209+
use_span.hash(h);
210+
use_span_with_attributes.hash(h);
211+
has_attributes.hash(h);
212+
span.hash(h);
213+
root_span.hash(h);
214+
vis.hash(h);
195215
}
196216
}
197217

compiler/rustc_resolve/src/lib.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ impl<'ra> PathResult<'ra> {
481481
}
482482
}
483483

484-
#[derive(Debug)]
484+
#[derive(Debug, Hash, PartialEq, Eq)]
485485
enum ModuleKind {
486486
/// An anonymous module; e.g., just a block.
487487
///
@@ -594,11 +594,15 @@ struct Module<'ra>(Interned<'ra, ModuleData<'ra>>);
594594
// FIXME: We may wish to actually have at least debug-level assertions that Interned's guarantees
595595
// are upheld.
596596
impl std::hash::Hash for ModuleData<'_> {
597-
fn hash<H>(&self, _: &mut H)
597+
fn hash<H>(&self, h: &mut H)
598598
where
599599
H: std::hash::Hasher,
600600
{
601-
unreachable!()
601+
self.parent.hash(h);
602+
self.kind.hash(h);
603+
self.no_implicit_prelude.hash(h);
604+
self.span.hash(h);
605+
self.expansion.hash(h);
602606
}
603607
}
604608

@@ -757,11 +761,17 @@ type NameBinding<'ra> = Interned<'ra, NameBindingData<'ra>>;
757761
// FIXME: We may wish to actually have at least debug-level assertions that Interned's guarantees
758762
// are upheld.
759763
impl std::hash::Hash for NameBindingData<'_> {
760-
fn hash<H>(&self, _: &mut H)
764+
fn hash<H>(&self, h: &mut H)
761765
where
762766
H: std::hash::Hasher,
763767
{
764-
unreachable!()
768+
let NameBindingData { kind, ambiguity, warn_ambiguity, expansion, span, vis } = self;
769+
kind.hash(h);
770+
ambiguity.hash(h);
771+
warn_ambiguity.hash(h);
772+
expansion.hash(h);
773+
span.hash(h);
774+
vis.hash(h);
765775
}
766776
}
767777

@@ -775,7 +785,7 @@ impl<'ra> ToNameBinding<'ra> for NameBinding<'ra> {
775785
}
776786
}
777787

778-
#[derive(Clone, Copy, Debug)]
788+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
779789
enum NameBindingKind<'ra> {
780790
Res(Res),
781791
Module(Module<'ra>),
@@ -818,7 +828,7 @@ struct UseError<'a> {
818828
is_call: bool,
819829
}
820830

821-
#[derive(Clone, Copy, PartialEq, Debug)]
831+
#[derive(Clone, Copy, PartialEq, Debug, Eq, Hash)]
822832
enum AmbiguityKind {
823833
BuiltinAttr,
824834
DeriveHelper,

0 commit comments

Comments
 (0)