Skip to content

distinguish "expected a single argument" and "expected an argument" on attribute parsing#154827

Merged
rust-bors[bot] merged 4 commits intorust-lang:mainfrom
scrabsha:push-zuosxmmnzkrq
Apr 11, 2026
Merged

distinguish "expected a single argument" and "expected an argument" on attribute parsing#154827
rust-bors[bot] merged 4 commits intorust-lang:mainfrom
scrabsha:push-zuosxmmnzkrq

Conversation

@scrabsha
Copy link
Copy Markdown
Contributor

@scrabsha scrabsha commented Apr 4, 2026

First commit is the real thing, the commits that follow are refactorings of patterns i kept noticing.

Renders as:
error message

@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 Apr 4, 2026
@scrabsha scrabsha force-pushed the push-zuosxmmnzkrq branch 2 times, most recently from 2b3f438 to 436a3bb Compare April 4, 2026 20:07
@rust-log-analyzer

This comment has been minimized.

@scrabsha scrabsha force-pushed the push-zuosxmmnzkrq branch 2 times, most recently from b99582a to 61551e5 Compare April 5, 2026 12:18
Comment thread compiler/rustc_attr_parsing/src/parser.rs Outdated
Comment thread tests/ui/attributes/malformed-attrs.stderr Outdated
@rust-log-analyzer

This comment has been minimized.

@scrabsha scrabsha force-pushed the push-zuosxmmnzkrq branch from 61551e5 to c76706b Compare April 6, 2026 09:32
@rust-log-analyzer

This comment has been minimized.

@scrabsha scrabsha force-pushed the push-zuosxmmnzkrq branch 3 times, most recently from 8fdfe78 to cd2de6a Compare April 6, 2026 10:14
let Some(arg) = args.list().and_then(MetaItemListParser::single) else {
let attr_span = cx.attr_span;
cx.adcx().expected_single_argument(attr_span);
cx.adcx().expected_single_argument(attr_span, 2);
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.

This is technically incorrect, but fixed two commits later.

@scrabsha scrabsha force-pushed the push-zuosxmmnzkrq branch from cd2de6a to 9173a9b Compare April 6, 2026 10:30
@rust-log-analyzer

This comment has been minimized.

@scrabsha scrabsha force-pushed the push-zuosxmmnzkrq branch from 9173a9b to 1d395f3 Compare April 6, 2026 13:16
@rust-bors

This comment has been minimized.

@scrabsha scrabsha force-pushed the push-zuosxmmnzkrq branch from 1d395f3 to ec3f438 Compare April 9, 2026 17:11
@scrabsha
Copy link
Copy Markdown
Contributor Author

scrabsha commented Apr 9, 2026

r? @jdonszelmann

@scrabsha scrabsha marked this pull request as ready for review April 9, 2026 21:10
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 9, 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 Apr 9, 2026
return None;
};

let Some(single) = l.single() else {
Copy link
Copy Markdown
Contributor

@jdonszelmann jdonszelmann Apr 10, 2026

Choose a reason for hiding this comment

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

we should probably put a #[deprecated = "use single_element_list instead"] on .single().

Copy link
Copy Markdown
Contributor Author

@scrabsha scrabsha Apr 10, 2026

Choose a reason for hiding this comment

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

I tried this locally and I'm not sure it's a good idea. There are some patterns in which calling single() is still legit. Here are a couple I found:

In test_attrs:74:

match args {
    // Many match args for all kinds of ArgParser

    ArgParser::List(list) => {
        let Some(single) = list.single() else { /* ... /* };
    }
}

There is a similar pattern in inline.rs:40, cfg.rs:95, attributes/mod.rs:407 and many others.

In cfg.rs:52:

let ArgParser::List(list) = args else {
    let attr_span = cx.attr_span;
    cx.adcx().expected_list(attr_span, args);
    return None;
};

let Some(single) = list.single() else {
    // Lots and lots of code generating cute error messages.
};

I don't really see any replacement for these patterns. If you want, I can review exhaustively review every use of .single() and see what I can do, but I honestly doubt we'd find anything to improve. What do you think?

@rustbot ready

Copy link
Copy Markdown
Contributor

@jdonszelmann jdonszelmann left a comment

Choose a reason for hiding this comment

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

@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 Apr 10, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 10, 2026

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

@scrabsha scrabsha force-pushed the push-zuosxmmnzkrq branch from efed69e to ec3f438 Compare April 10, 2026 14:17
@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 Apr 10, 2026
@jdonszelmann
Copy link
Copy Markdown
Contributor

ok, fair :)

@bors r+ rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 11, 2026

📌 Commit ec3f438 has been approved by jdonszelmann

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 Apr 11, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 11, 2026
…szelmann

distinguish "expected a single argument" and "expected an argument" on attribute parsing
rust-bors bot pushed a commit that referenced this pull request Apr 11, 2026
Rollup of 3 pull requests

Successful merges:

 - #154827 (distinguish "expected a single argument" and "expected an argument" on attribute parsing)
 - #155104 (bootstrap: auto-patch libgccjit.so for NixOS)
 - #155120 (Use a linting node closer the parsing of `#[cfg_attr]`)
@rust-bors rust-bors bot merged commit ca34f77 into rust-lang:main Apr 11, 2026
22 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 11, 2026
rust-timer added a commit that referenced this pull request Apr 11, 2026
Rollup merge of #154827 - scrabsha:push-zuosxmmnzkrq, r=jdonszelmann

distinguish "expected a single argument" and "expected an argument" on attribute parsing
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.

4 participants