Skip to content

Add AcceptContext::expect_no_args#156037

Open
scrabsha wants to merge 1 commit intorust-lang:mainfrom
scrabsha:attributes/expect-no-args
Open

Add AcceptContext::expect_no_args#156037
scrabsha wants to merge 1 commit intorust-lang:mainfrom
scrabsha:attributes/expect-no-args

Conversation

@scrabsha
Copy link
Copy Markdown
Contributor

@scrabsha scrabsha commented May 1, 2026

This PR adds AcceptContext::expect_no_args that follows the same style as what was added in #155696 and #155831 (albeit much smaller this time).

  • There is still one (1) usage of AttributeDiagnosticContext::expected_no_args in proc_macro_attrs:136 and I have no idea how to remove it. Any suggestion on what to replace this call with is welcome :)
  • Some usages of ArgParser::no_args still remain in places where we emit custom errors. They show up in the diff due to the no_args -> as_no_args renaming.

I did a little experiment in which I made AcceptContext::expect_no_args unconditionally return Some(()) so parsing always continues, but it led to lots of gibberish errors being emitted. Full diff for this is available here: expect_no_args_experiment.patch. This means there's no simple way to get rid of the let _ = cx.expect_no_args(/* ... */); and I am not super happy with that.

@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 May 1, 2026
@scrabsha scrabsha force-pushed the attributes/expect-no-args branch from 846e90c to f77fc05 Compare May 1, 2026 08:12
@JonathanBrouwer
Copy link
Copy Markdown
Contributor

JonathanBrouwer commented May 1, 2026

The problem with expect_no_args is that it is too easy to forget to check it. This problem is ofcourse not introduced by this PR, and I still think this PR is an improvement over the current situation so happy to continue with it, but I hope to see the meta_item_no_args function from #155193 be used in more places after that PR finally merges

@scrabsha
Copy link
Copy Markdown
Contributor Author

scrabsha commented May 1, 2026

Absolutely. I would LOVE opening a PR that essentially removes every call to AcceptContext::expect_no_args 🥰

r? JonathanBrouwer

@scrabsha scrabsha marked this pull request as ready for review May 1, 2026 15:19
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 1, 2026

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 May 1, 2026
Copy link
Copy Markdown
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
Copy Markdown
Contributor

rust-bors Bot commented May 1, 2026

📌 Commit f77fc05 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 May 1, 2026
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 1, 2026
…, r=JonathanBrouwer

Add AcceptContext::expect_no_args
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-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.

3 participants