Skip to content

Move check_rustc_must_implement_one_of validation to attribute parser - #163980

Open
darkraider01 wants to merge 1 commit into
rust-lang:mainfrom
darkraider01:document-must-implement-one-of-boundary
Open

darkraider01 wants to merge 1 commit into
rust-lang:mainfrom
darkraider01:document-must-implement-one-of-boundary

Conversation

@darkraider01

@darkraider01 darkraider01 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

Part of #153101 and #131229.

Moves the remaining rustc_must_implement_one_of validation from rustc_passes::check_attr into RustcMustImplementOneOfParser::finalize_check using AST trait information available through FinalizeCheckContext::target_item.

The duplicate-name validation was already migrated in #160412. This completes the remaining associated-item and default-implementation checks.

Related: #153101, #131229, #160412

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 8, 2026
@darkraider01
darkraider01 force-pushed the document-must-implement-one-of-boundary branch from 2828fd1 to 5792ac6 Compare October 8, 2026 10:29
@darkraider01 darkraider01 changed the title Document check_rustc_must_implement_one_of boundary in check_attr Move check_rustc_must_implement_one_of validation to attribute parser Oct 8, 2026
@darkraider01
darkraider01 force-pushed the document-must-implement-one-of-boundary branch from 5792ac6 to ab04b05 Compare October 8, 2026 11:10
@darkraider01
darkraider01 marked this pull request as ready for review October 8, 2026 11:11
@rustbot

rustbot commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

@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 Oct 8, 2026
@rustbot

rustbot commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

r? @wesleywiser

rustbot has assigned @wesleywiser.
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 77 candidates
  • Random selection from 19 candidates

@darkraider01
darkraider01 marked this pull request as draft October 8, 2026 11:14
@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 Oct 8, 2026
match ctxt {
visit::AssocCtxt::Trait => {
self.replace_with_dummy(item, AssocItemKind::MacCall, AstOwner::TraitItem)
self.insert(item.id, AstOwner::TraitItem(Box::new(item.clone())));

@darkraider01 darkraider01 Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The old replace_with_dummy was replacing the trait items with MacCall placeholders, so finalize_check couldn't actually inspect them through target_item.

This keeps the original items in the trait while still indexing the cloned ones separately for lowering.

The downside is that we're cloning trait items even when the attribute isn't used. I couldn't find a simpler way to reuse the existing infrastructure here, but I'm open to suggestions.

View changes since the review

@darkraider01 darkraider01 Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Edit: (This approach is suggested by llm, since i couldn't come with a better/simplied solution) Maybe another option could be to keep the original trait items only for traits with #[rustc_must_implement_one_of] , and use the existing placeholders everywhere else. That would still involve cloning, but limit it to traits that actually need the check. Not sure how neatly it would fit into the indexer, especially with nested traits, but it might be worth exploring.

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.

I think both options might be terrible for performance, let's check.
It also just doesn't feel like a great solution, it might be better to just keep the check in rustc_passes if this is needed

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.

I've started a small experiment here that might make this code nice if perf allows: #164980

I'm not expecting that PR to be accepted tho

@darkraider01 darkraider01 Oct 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tried this with #163980 locally and it works without cloning the trait items. I just dropped the cloning hunk and kept your indexer as-is. Thank you!!!
Edit: heres the branch if you'd like to inspect https://github.com/darkraider01/rust/tree/experiment-ast-retention-164980

_ => {
cx.emit_err(diagnostics::MustImplementNotFunction {
span: item.span,
span_note: diagnostics::MustImplementNotFunctionSpanNote {

@darkraider01 darkraider01 Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Keeping delegation as a valid case here since it lowers to TraitFn::Provided, which the old check already accepted.

I added tests for both normal and renamed delegation as well.

View changes since the review

panic!("expected trait AST target item for Target::Trait");
};

let fn_names =

@darkraider01 darkraider01 Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Kept the full Ident comparison here rather than just matching names, since the old check did the same.

Added a couple of macro tests to make sure the hygiene behavior stays the same.

View changes since the review

@darkraider01
darkraider01 marked this pull request as ready for review October 8, 2026 11:47
@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 Oct 8, 2026
@rust-log-analyzer

This comment was marked as outdated.

@JonathanBrouwer

Copy link
Copy Markdown
Member

r? me

@rust-bors

This comment has been minimized.

@darkraider01
darkraider01 force-pushed the document-must-implement-one-of-boundary branch from ab04b05 to 73ccfeb Compare October 13, 2026 08:13
@rustbot

This comment has been minimized.

@JonathanBrouwer

Copy link
Copy Markdown
Member

(Sorry for taking so long to review this, I've been away for a bit due to conferences and illness, I should get to this in a day or two)

@rust-bors

This comment has been minimized.

@darkraider01
darkraider01 force-pushed the document-must-implement-one-of-boundary branch from 73ccfeb to 46ce4af Compare October 26, 2026 08:05
@rustbot

rustbot commented Oct 26, 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.

@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors try @rust-timer queuee

@rust-timer

Copy link
Copy Markdown
Collaborator

Unknown rust-timer command: queuee

@JonathanBrouwer

Copy link
Copy Markdown
Member

@rust-timer queue

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Oct 26, 2026
…oundary, r=<try>

Move check_rustc_must_implement_one_of validation to attribute parser
@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Oct 26, 2026
@rust-bors

rust-bors Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: b1e6bae (b1e6bae0c860da20f7d5a54118a16d884694aaf0)
Base parent: aaf324d (aaf324d50a7dcb17aae7f2a37e15ff143d980c6e)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (b1e6bae): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=iffy rustc-perf
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.2% [0.2%, 0.3%] 3
Regressions ❌
(secondary)
0.4% [0.2%, 0.7%] 9
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.3% [-0.5%, -0.0%] 12
All ❌✅ (primary) 0.2% [0.2%, 0.3%] 3

Max RSS (memory usage)

Results (primary 0.3%, secondary 0.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.6% [0.4%, 1.4%] 8
Regressions ❌
(secondary)
0.5% [0.5%, 0.5%] 1
Improvements ✅
(primary)
-0.6% [-0.7%, -0.4%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [-0.7%, 1.4%] 11

Cycles

Results (primary -0.5%, secondary -0.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.6% [0.4%, 0.9%] 4
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.9% [-1.9%, -0.6%] 11
Improvements ✅
(secondary)
-0.5% [-0.7%, -0.4%] 2
All ❌✅ (primary) -0.5% [-1.9%, 0.9%] 15

Binary size

Results (primary 0.1%, secondary 0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.1% [0.0%, 0.2%] 64
Regressions ❌
(secondary)
0.1% [0.0%, 0.3%] 56
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [0.0%, 0.2%] 64

Bootstrap: 488.092s -> 488.8s (0.15%)
Artifact size: 405.81 MiB -> 406.04 MiB (0.06%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Oct 26, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Member

The include-blob improvements are noise, the regressions seem to be real

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

A-attributes Area: Attributes (`#[…]`, `#![…]`) perf-regression Performance regression. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants