Simplify find_attr! for HirId usage#153582
Open
mehdiakiki wants to merge 1 commit intorust-lang:mainfrom
Open
Conversation
Collaborator
|
Some changes occurred to the CTFE machinery Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred in compiler/rustc_hir/src/attrs |
Collaborator
|
r? @mati865 rustbot has assigned @mati865. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
ff3c7f6 to
e9a9d24
Compare
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. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Member
|
r? JonathanBrouwer |
JonathanBrouwer
approved these changes
Mar 9, 2026
Contributor
Author
Sure Jonathan, I will do that tomorrow! |
Add a HasAttrs<'tcx, Tcx> trait to rustc_hir that allows find_attr! to accept DefId, LocalDefId, OwnerId, and HirId directly, instead of requiring callers to manually fetch the attribute slice first. Before: find_attr!(tcx.hir_attrs(hir_id), SomeAttr) After: find_attr!(tcx, hir_id, SomeAttr) The trait is defined in rustc_hir with a generic Tcx parameter to avoid a dependency cycle (rustc_hir cannot depend on rustc_middle). The four concrete impls for TyCtxt are in rustc_middle. Closes rust-lang#153103
e9a9d24 to
896da64
Compare
Collaborator
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a
HasAttrs<'tcx, Tcx>trait torustc_hirthat allowsfind_attr!to acceptDefId,LocalDefId,OwnerId, andHirIddirectly, instead of requiring callers to manually fetch the attribute slice first.Before:
find_attr!(tcx.hir_attrs(hir_id), SomeAttr)After:
find_attr!(tcx, hir_id, SomeAttr)The trait is defined in
rustc_hirwith a genericTcxparameter to avoid a dependency cycle (rustc_hircannot depend onrustc_middle). The four concrete impls forTyCtxtare inrustc_middle.