Skip to content

Move check_rustc_must_implement_one_of validation to attribute parser - #163980

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

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

Conversation

@darkraider01

@darkraider01 darkraider01 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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.

_ => {
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

rust-bors Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #164230) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

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 (`#[…]`, `#![…]`) 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.

5 participants