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.

Fixes #153103

@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!

@mehdiakiki mehdiakiki force-pushed the simplify-find-attr-hir-id branch from e9a9d24 to 896da64 Compare March 11, 2026 01:32
@rustbot

This comment has been minimized.

@Kivooeo
Copy link
Member

Kivooeo commented Mar 11, 2026

please remove issue links from commit message as warning above suggests

@JonathanBrouwer
Copy link
Contributor

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 11, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 11, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

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.

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.
@mehdiakiki mehdiakiki force-pushed the simplify-find-attr-hir-id branch from 896da64 to 858b82d Compare March 12, 2026 00:31
@mehdiakiki
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 22, 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.

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 22, 2026

📌 Commit 858b82d has been approved by JonathanBrouwer

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 Mar 22, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 22, 2026
…id, r=JonathanBrouwer

Simplify find_attr! for HirId usage

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`.

Fixes rust-lang#153103
Zalathar added a commit to Zalathar/rust that referenced this pull request Mar 22, 2026
…id, r=JonathanBrouwer

Simplify find_attr! for HirId usage

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`.

Fixes rust-lang#153103
rust-bors bot pushed a commit that referenced this pull request Mar 22, 2026
Rollup of 9 pull requests

Successful merges:

 - #122668 (Add APIs for dealing with titlecase)
 - #153312 (Packages as namespaces part 1)
 - #153534 (Remove a flaky `got_timeout` assert from two channel tests)
 - #153582 (Simplify find_attr! for HirId usage)
 - #154174 (allow `incomplete_features` in most UI tests)
 - #154175 (Add new alias for Guillaume Gomez email address)
 - #154182 (diagnostics: avoid ICE for undeclared generic parameter in impl)
 - #154188 (Update the tracking issue for #[diagnostic::on_move])
 - #154201 (Use enums to clarify `DepNodeColorMap` color marking )
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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

Simplify find_attr!() for the case when a hir id is given

6 participants