Skip to content

Remove StashKey::AssociatedTypeSuggestion - #162942

Open
nnethercote wants to merge 1 commit into
rust-lang:mainfrom
nnethercote:rm-StashKey-AssociatedTypeSuggestion
Open

nnethercote wants to merge 1 commit into
rust-lang:mainfrom
nnethercote:rm-StashKey-AssociatedTypeSuggestion

Conversation

@nnethercote

Copy link
Copy Markdown
Contributor

Currently it's used in a really hacky way: a diagnostic with an empty message and some suggestions is stashed. Later on it might be retrieved and its suggestions extracted. It uses Level::Allow so that it isn't printed by emit_stashed_diagnostics at shutdown if it hasn't been retrieved.

This isn't a normal stashed diagnostic, more just a case of "save some information that might be useful for diagnostics later". We can record the information more simply and directly.

This commit adds paths_matching_assoc_types fields to Resolver and ResolverGlobalCtxt. These store the spans of the paths of interest. The new subdiagnostic AssocTypeWithSameName is used to construct the relevant suggestions when they are needed. Much nicer. The old approach removed the stashed diagnostic and the new approach doesn't remove the set entry, so a single span could conceivably match more than once, presumably a good thing, though this doesn't show up in the test suite.

r? @davidtwco

@rustbot

rustbot commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

HIR ty lowering was modified

cc @fmease

@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 18, 2026

@davidtwco davidtwco left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One of those situations where I think "how did that ever happen" and then learn that apparently I approved the PR that added this two years ago - thanks for fixing it.

View changes since this review

@davidtwco

Copy link
Copy Markdown
Member

@bors r+ rollup

@rust-bors

rust-bors Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 616089b has been approved by davidtwco

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 23, 2026
rust-bors Bot pushed a commit that referenced this pull request Sep 23, 2026
Rollup of 10 pull requests

Successful merges:

 - #161988 (trait solver: Handle reflexive region constraints)
 - #162498 (Avoid ICEs when recovering malformed function parameters)
 - #163181 (revert #162715 due to #163149)
 - #163207 (Update deprecated rustc_hir imports 2)
 - #163216 (Add `inline` attribute to `NonZero::from_str`)
 - #120589 (std::thread::available_parallelism merging linux/android/freebsd version)
 - #162103 (fix(parser): emit targeted diagnostic for fields inside traits)
 - #162340 (When trying to recover from `for<…> dyn …` don't unconditionally treat `dyn` as a keyword)
 - #163094 (Add regression test for first token source file from TokenStream FromStr)
 - #163115 (Point at `'static` obligations from an fn being called)

Failed merges:

 - #162942 (Remove `StashKey::AssociatedTypeSuggestion`)
@rust-bors rust-bors Bot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Sep 23, 2026
@rust-bors

This comment has been minimized.

@rust-bors rust-bors Bot removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Sep 23, 2026
Currently it's used in a really hacky way: a diagnostic with an empty
message and some suggestions is stashed. Later on it might be retrieved
and its suggestions extracted. It uses `Level::Allow` so that it isn't
printed by `emit_stashed_diagnostics` at shutdown if it hasn't been
retrieved.

This isn't a normal stashed diagnostic, more just a case of "save some
information that might be useful for diagnostics later". We can record
the information more simply and directly.

This commit adds `paths_matching_assoc_types` fields to `Resolver` and
`ResolverGlobalCtxt`. These store the spans of the paths of interest.
The new subdiagnostic `AssocTypeWithSameName` is used to construct the
relevant suggestions when they are needed. Much nicer. The old approach
removed the stashed diagnostic and the new approach doesn't remove the
set entry, so a single span could conceivably match more than once,
presumably a good thing, though this doesn't show up in the test suite.
@nnethercote
nnethercote force-pushed the rm-StashKey-AssociatedTypeSuggestion branch from 616089b to 1e185bd Compare September 23, 2026 23:00
@rustbot

rustbot commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@nnethercote

Copy link
Copy Markdown
Contributor Author

I rebased.

@bors r=davidtwco

@rust-bors

rust-bors Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 1e185bd has been approved by davidtwco

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 23, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Sep 23, 2026
…TypeSuggestion, r=davidtwco

Remove `StashKey::AssociatedTypeSuggestion`

Currently it's used in a really hacky way: a diagnostic with an empty message and some suggestions is stashed. Later on it might be retrieved and its suggestions extracted. It uses `Level::Allow` so that it isn't printed by `emit_stashed_diagnostics` at shutdown if it hasn't been retrieved.

This isn't a normal stashed diagnostic, more just a case of "save some information that might be useful for diagnostics later". We can record the information more simply and directly.

This commit adds `paths_matching_assoc_types` fields to `Resolver` and `ResolverGlobalCtxt`. These store the spans of the paths of interest. The new subdiagnostic `AssocTypeWithSameName` is used to construct the relevant suggestions when they are needed. Much nicer. The old approach removed the stashed diagnostic and the new approach doesn't remove the set entry, so a single span could conceivably match more than once, presumably a good thing, though this doesn't show up in the test suite.

r? @davidtwco

This branch has not been deployed

No deployments
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.

3 participants