Enforce T: Hash for Interned<...>
This adds panicking Hash impls for several resolver types that don't actually satisfy this condition. It's not obvious to me that rustc_resolve actually upholds the Interned guarantees but fixing that seems pretty hard (the structures have at minimum some interior mutability, so it's not really recursively hashable in place...).
This commit is contained in:
parent
ce36a966c7
commit
9fc759099b
3 changed files with 43 additions and 1 deletions
|
@ -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]
|
#[inline]
|
||||||
fn hash<H: Hasher>(&self, s: &mut H) {
|
fn hash<H: Hasher>(&self, s: &mut H) {
|
||||||
// Pointer hashing is sufficient, due to the uniqueness constraint.
|
// Pointer hashing is sufficient, due to the uniqueness constraint.
|
||||||
|
|
|
@ -182,6 +182,19 @@ pub(crate) struct ImportData<'ra> {
|
||||||
/// so we can use referential equality to compare them.
|
/// so we can use referential equality to compare them.
|
||||||
pub(crate) type Import<'ra> = Interned<'ra, ImportData<'ra>>;
|
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<H>(&self, _: &mut H)
|
||||||
|
where
|
||||||
|
H: std::hash::Hasher,
|
||||||
|
{
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'ra> ImportData<'ra> {
|
impl<'ra> ImportData<'ra> {
|
||||||
pub(crate) fn is_glob(&self) -> bool {
|
pub(crate) fn is_glob(&self) -> bool {
|
||||||
matches!(self.kind, ImportKind::Glob { .. })
|
matches!(self.kind, ImportKind::Glob { .. })
|
||||||
|
|
|
@ -589,6 +589,19 @@ struct ModuleData<'ra> {
|
||||||
#[rustc_pass_by_value]
|
#[rustc_pass_by_value]
|
||||||
struct Module<'ra>(Interned<'ra, ModuleData<'ra>>);
|
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<H>(&self, _: &mut H)
|
||||||
|
where
|
||||||
|
H: std::hash::Hasher,
|
||||||
|
{
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'ra> ModuleData<'ra> {
|
impl<'ra> ModuleData<'ra> {
|
||||||
fn new(
|
fn new(
|
||||||
parent: Option<Module<'ra>>,
|
parent: Option<Module<'ra>>,
|
||||||
|
@ -739,6 +752,19 @@ struct NameBindingData<'ra> {
|
||||||
/// so we can use referential equality to compare them.
|
/// so we can use referential equality to compare them.
|
||||||
type NameBinding<'ra> = Interned<'ra, NameBindingData<'ra>>;
|
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<H>(&self, _: &mut H)
|
||||||
|
where
|
||||||
|
H: std::hash::Hasher,
|
||||||
|
{
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
trait ToNameBinding<'ra> {
|
trait ToNameBinding<'ra> {
|
||||||
fn to_name_binding(self, arenas: &'ra ResolverArenas<'ra>) -> NameBinding<'ra>;
|
fn to_name_binding(self, arenas: &'ra ResolverArenas<'ra>) -> NameBinding<'ra>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue