Skip to content

Remove impl_stable_hash_via_hash!() #96013

Closed

Description

@michaelwoerister

I came across impl_stable_hash_via_hash!() the other day and it seems very problematic because one can easily generate invalid HashStable implementations without even noticing:

#[derive(Hash)]
struct Foo<'tcx> {
    def_id: DefId, // numeric value of def_id ends up in fingerprint,
    ptr: *const c_void, // memory address ends up in fingerprint,
    bar: Interned<'tcx, Bar>, // ditto
}

// Yay, three separate bugs in a single line!
impl_stable_hash_via_hash!(Foo);

I think we should just remove the macro (or keep it local to the module that implements HashStable for basic types). #[derive(HashStable_Generic)] is available as a safe alternative.

rustc_lint_defs::Level looks like a case where this is already a problem because of the HirId in the contained LintExpectationId.

cc @rust-lang/wg-incr-comp

Activity

  1. added
    C-cleanupCategory: PRs that clean code up or issues documenting cleanup.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    A-incr-compArea: Incremental compilation
    C-bugCategory: This is a bug.
    WG-incr-compWorking group: Incremental compilation
    on Apr 13, 2022
  2. michaelwoerister commented on Apr 13, 2022

    @michaelwoerister
    MemberAuthor

    I plan to fix this on Friday if nobody beats me to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-incr-compArea: Incremental compilationC-bugCategory: This is a bug.C-cleanupCategory: PRs that clean code up or issues documenting cleanup.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-incr-compWorking group: Incremental compilation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions