diff --git a/compiler/rustc_data_structures/src/intern.rs b/compiler/rustc_data_structures/src/intern.rs index 850b052f564b7..8079212fac551 100644 --- a/compiler/rustc_data_structures/src/intern.rs +++ b/compiler/rustc_data_structures/src/intern.rs @@ -92,7 +92,10 @@ impl<'a, T: Ord> Ord for Interned<'a, T> { } } -impl<'a, T> Hash for Interned<'a, T> { +impl<'a, T> Hash for Interned<'a, T> +where + T: Hash, +{ #[inline] fn hash(&self, s: &mut H) { // Pointer hashing is sufficient, due to the uniqueness constraint. diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index b1b234eb75737..46e52e1f131b0 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -182,6 +182,19 @@ pub(crate) struct ImportData<'ra> { /// so we can use referential equality to compare them. pub(crate) type Import<'ra> = Interned<'ra, ImportData<'ra>>; +// Allows us to use Interned without actually enforcing (via Hash/PartialEq/...) uniqueness of the +// contained data. +// 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) + where + H: std::hash::Hasher, + { + unreachable!() + } +} + impl<'ra> ImportData<'ra> { pub(crate) fn is_glob(&self) -> bool { matches!(self.kind, ImportKind::Glob { .. }) diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 90191b7776f32..5bc37e09f0890 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -589,6 +589,19 @@ struct ModuleData<'ra> { #[rustc_pass_by_value] struct Module<'ra>(Interned<'ra, ModuleData<'ra>>); +// Allows us to use Interned without actually enforcing (via Hash/PartialEq/...) uniqueness of the +// contained data. +// 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) + where + H: std::hash::Hasher, + { + unreachable!() + } +} + impl<'ra> ModuleData<'ra> { fn new( parent: Option>, @@ -739,6 +752,19 @@ struct NameBindingData<'ra> { /// so we can use referential equality to compare them. type NameBinding<'ra> = Interned<'ra, NameBindingData<'ra>>; +// Allows us to use Interned without actually enforcing (via Hash/PartialEq/...) uniqueness of the +// contained data. +// 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) + where + H: std::hash::Hasher, + { + unreachable!() + } +} + trait ToNameBinding<'ra> { fn to_name_binding(self, arenas: &'ra ResolverArenas<'ra>) -> NameBinding<'ra>; }