diff --git a/compiler/rustc_data_structures/src/intern.rs b/compiler/rustc_data_structures/src/intern.rs index 8079212fac551..8bb6d294f0fba 100644 --- a/compiler/rustc_data_structures/src/intern.rs +++ b/compiler/rustc_data_structures/src/intern.rs @@ -98,8 +98,7 @@ where { #[inline] fn hash(&self, s: &mut H) { - // Pointer hashing is sufficient, due to the uniqueness constraint. - ptr::hash(self.0, s) + Hash::hash(&self.0, s) } } diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 46e52e1f131b0..57b506077d4a7 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -187,11 +187,31 @@ pub(crate) type Import<'ra> = Interned<'ra, ImportData<'ra>>; // FIXME: We may wish to actually have at least debug-level assertions that Interned's guarantees // are upheld. impl std::hash::Hash for ImportData<'_> { - fn hash(&self, _: &mut H) + fn hash(&self, h: &mut H) where H: std::hash::Hasher, { - unreachable!() + let ImportData { + kind: _, + root_id, + use_span, + use_span_with_attributes, + has_attributes, + span, + root_span, + parent_scope: _, + module_path: _, + imported_module: _, + vis, + } = self; + + root_id.hash(h); + use_span.hash(h); + use_span_with_attributes.hash(h); + has_attributes.hash(h); + span.hash(h); + root_span.hash(h); + vis.hash(h); } } diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 5bc37e09f0890..59d37272d72cc 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -481,7 +481,7 @@ impl<'ra> PathResult<'ra> { } } -#[derive(Debug)] +#[derive(Debug, Hash, PartialEq, Eq)] enum ModuleKind { /// An anonymous module; e.g., just a block. /// @@ -594,11 +594,15 @@ struct Module<'ra>(Interned<'ra, ModuleData<'ra>>); // FIXME: We may wish to actually have at least debug-level assertions that Interned's guarantees // are upheld. impl std::hash::Hash for ModuleData<'_> { - fn hash(&self, _: &mut H) + fn hash(&self, h: &mut H) where H: std::hash::Hasher, { - unreachable!() + self.parent.hash(h); + self.kind.hash(h); + self.no_implicit_prelude.hash(h); + self.span.hash(h); + self.expansion.hash(h); } } @@ -757,11 +761,17 @@ type NameBinding<'ra> = Interned<'ra, NameBindingData<'ra>>; // FIXME: We may wish to actually have at least debug-level assertions that Interned's guarantees // are upheld. impl std::hash::Hash for NameBindingData<'_> { - fn hash(&self, _: &mut H) + fn hash(&self, h: &mut H) where H: std::hash::Hasher, { - unreachable!() + let NameBindingData { kind, ambiguity, warn_ambiguity, expansion, span, vis } = self; + kind.hash(h); + ambiguity.hash(h); + warn_ambiguity.hash(h); + expansion.hash(h); + span.hash(h); + vis.hash(h); } } @@ -775,7 +785,7 @@ impl<'ra> ToNameBinding<'ra> for NameBinding<'ra> { } } -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] enum NameBindingKind<'ra> { Res(Res), Module(Module<'ra>), @@ -818,7 +828,7 @@ struct UseError<'a> { is_call: bool, } -#[derive(Clone, Copy, PartialEq, Debug)] +#[derive(Clone, Copy, PartialEq, Debug, Eq, Hash)] enum AmbiguityKind { BuiltinAttr, DeriveHelper,