Skip to content

Clean up diagnostic hashing - #163148

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
nnethercote:improve-Diag-hashing
Sep 22, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
nnethercote:improve-Diag-hashing

Conversation

@nnethercote

Copy link
Copy Markdown
Contributor

DiagInner impls PartialEq and Hash, as you'd expect for storing it in a hash table. But there's a couple of strange things.

  • We only store the hash value of the DiagInner to do deduplication, not the DiagInner itself, which means the PartialEq impl is unused.

  • The Hash impl only considers some of the fields. Some of the ignored fields are clearly deliberate (there are comments) but for some it is unclear if it is deliberate.

This commit:

  • Removes the unused PartialEq impl.

  • Inlines and removes keys now that it's not needed for PartialEq.

  • Uses struct deconstruction to ensure no fields can be accidentally ignored. I have preserved existing behaviour by assuming that all the ignored fields are supposed to be ignored.

  • Renames hash as an inherent method dedup_hash to indicate that it's not a typical hash function, and simplifies it to just return Hash128 instead of being generic.

  • Replaces the unnecessary collect on args with as_slice.

  • Improves the comment on emitted_diagnostics.

r? @oli-obk

`DiagInner` impls `PartialEq` and `Hash`, as you'd expect for storing it
in a hash table. But there's a couple of strange things.

- We only store the hash value of the `DiagInner` to do deduplication,
  not the `DiagInner` itself, which means the `PartialEq` impl is
  unused.

- The `Hash` impl only considers some of the fields. Some of the ignored
  fields are clearly deliberate (there are comments) but for some it is
  unclear if it is deliberate.

This commit:

- Removes the unused `PartialEq` impl.

- Inlines and removes `keys` now that it's not needed for `PartialEq`.

- Uses struct deconstruction to ensure no fields can be accidentally
  ignored. I have preserved existing behaviour by assuming that all the
  ignored fields are supposed to be ignored.

- Renames `hash` as an inherent method `dedup_hash` to indicate that
  it's not a typical hash function, and simplifies it to just return
  `Hash128` instead of being generic.

- Replaces the unnecessary `collect` on `args` with `as_slice`.

- Improves the comment on `emitted_diagnostics`.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 22, 2026
@bjorn3

bjorn3 commented Sep 22, 2026

Copy link
Copy Markdown
Member

Have you seen #162901 by the way?

@nnethercote

Copy link
Copy Markdown
Contributor Author

I haven't. It's orthogonal, because this is just a refactoring. Looks like the span field needs some special treatment.

@oli-obk oli-obk left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rust-bors

rust-bors Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 9fecc5a has been approved by oli-obk

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 22, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 22, 2026
…r=oli-obk

Clean up diagnostic hashing

`DiagInner` impls `PartialEq` and `Hash`, as you'd expect for storing it in a hash table. But there's a couple of strange things.

- We only store the hash value of the `DiagInner` to do deduplication, not the `DiagInner` itself, which means the `PartialEq` impl is unused.

- The `Hash` impl only considers some of the fields. Some of the ignored fields are clearly deliberate (there are comments) but for some it is unclear if it is deliberate.

This commit:

- Removes the unused `PartialEq` impl.

- Inlines and removes `keys` now that it's not needed for `PartialEq`.

- Uses struct deconstruction to ensure no fields can be accidentally ignored. I have preserved existing behaviour by assuming that all the ignored fields are supposed to be ignored.

- Renames `hash` as an inherent method `dedup_hash` to indicate that it's not a typical hash function, and simplifies it to just return `Hash128` instead of being generic.

- Replaces the unnecessary `collect` on `args` with `as_slice`.

- Improves the comment on `emitted_diagnostics`.

r? @oli-obk
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 22, 2026
…r=oli-obk

Clean up diagnostic hashing

`DiagInner` impls `PartialEq` and `Hash`, as you'd expect for storing it in a hash table. But there's a couple of strange things.

- We only store the hash value of the `DiagInner` to do deduplication, not the `DiagInner` itself, which means the `PartialEq` impl is unused.

- The `Hash` impl only considers some of the fields. Some of the ignored fields are clearly deliberate (there are comments) but for some it is unclear if it is deliberate.

This commit:

- Removes the unused `PartialEq` impl.

- Inlines and removes `keys` now that it's not needed for `PartialEq`.

- Uses struct deconstruction to ensure no fields can be accidentally ignored. I have preserved existing behaviour by assuming that all the ignored fields are supposed to be ignored.

- Renames `hash` as an inherent method `dedup_hash` to indicate that it's not a typical hash function, and simplifies it to just return `Hash128` instead of being generic.

- Replaces the unnecessary `collect` on `args` with `as_slice`.

- Improves the comment on `emitted_diagnostics`.

r? @oli-obk
rust-bors Bot pushed a commit that referenced this pull request Sep 22, 2026
…uwer

Rollup of 7 pull requests

Successful merges:

 - #147876 (Check tainted_by_error in LateLint)
 - #162998 (Avoid generating overlapping assignments in DSE)
 - #163136 (library: prune allowed lints)
 - #163102 (remove unnecessary restriction with next-solver)
 - #163106 (emit the constant pattern note for raw identifier bindings)
 - #163118 (add `feature(field_projections)` fixme)
 - #163148 (Clean up diagnostic hashing)
@rust-bors
rust-bors Bot merged commit cecc101 into rust-lang:main Sep 22, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Sep 22, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 22, 2026
Rollup merge of #163148 - nnethercote:improve-Diag-hashing, r=oli-obk

Clean up diagnostic hashing

`DiagInner` impls `PartialEq` and `Hash`, as you'd expect for storing it in a hash table. But there's a couple of strange things.

- We only store the hash value of the `DiagInner` to do deduplication, not the `DiagInner` itself, which means the `PartialEq` impl is unused.

- The `Hash` impl only considers some of the fields. Some of the ignored fields are clearly deliberate (there are comments) but for some it is unclear if it is deliberate.

This commit:

- Removes the unused `PartialEq` impl.

- Inlines and removes `keys` now that it's not needed for `PartialEq`.

- Uses struct deconstruction to ensure no fields can be accidentally ignored. I have preserved existing behaviour by assuming that all the ignored fields are supposed to be ignored.

- Renames `hash` as an inherent method `dedup_hash` to indicate that it's not a typical hash function, and simplifies it to just return `Hash128` instead of being generic.

- Replaces the unnecessary `collect` on `args` with `as_slice`.

- Improves the comment on `emitted_diagnostics`.

r? @oli-obk
@nnethercote
nnethercote deleted the improve-Diag-hashing branch September 22, 2026 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants