Skip to content

Simplify find_attr! for HirId usage#153582

Open
mehdiakiki wants to merge 1 commit intorust-lang:mainfrom
mehdiakiki:simplify-find-attr-hir-id
Open

Simplify find_attr! for HirId usage#153582
mehdiakiki wants to merge 1 commit intorust-lang:mainfrom
mehdiakiki:simplify-find-attr-hir-id

Conversation

@mehdiakiki
Copy link
Contributor

@mehdiakiki mehdiakiki commented Mar 9, 2026

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.

@rustbot
Copy link
Collaborator

rustbot commented Mar 9, 2026

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 9, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 9, 2026

r? @mati865

rustbot has assigned @mati865.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 16 candidates

@rustbot

This comment has been minimized.

@mehdiakiki mehdiakiki force-pushed the simplify-find-attr-hir-id branch from ff3c7f6 to e9a9d24 Compare March 9, 2026 02:51
@rustbot
Copy link
Collaborator

rustbot commented Mar 9, 2026

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.

@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@Kivooeo
Copy link
Member

Kivooeo commented Mar 9, 2026

r? JonathanBrouwer

@rustbot rustbot assigned JonathanBrouwer and unassigned mati865 Mar 9, 2026
Copy link
Contributor

@JonathanBrouwer JonathanBrouwer left a comment

Choose a reason for hiding this comment

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

PR looks good, could you remove the issue mention from the commit & fix CI?

View changes since this review

@mehdiakiki
Copy link
Contributor Author

PR looks good, could you remove the issue mention from the commit & fix CI?

View changes since this review

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
@mehdiakiki mehdiakiki force-pushed the simplify-find-attr-hir-id branch from e9a9d24 to 896da64 Compare March 11, 2026 01:32
@rustbot
Copy link
Collaborator

rustbot commented Mar 11, 2026

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

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

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. 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.

6 participants