distinguish "expected a single argument" and "expected an argument" on attribute parsing#154827
Conversation
2b3f438 to
436a3bb
Compare
This comment has been minimized.
This comment has been minimized.
b99582a to
61551e5
Compare
This comment has been minimized.
This comment has been minimized.
61551e5 to
c76706b
Compare
This comment has been minimized.
This comment has been minimized.
8fdfe78 to
cd2de6a
Compare
| 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); |
There was a problem hiding this comment.
This is technically incorrect, but fixed two commits later.
cd2de6a to
9173a9b
Compare
This comment has been minimized.
This comment has been minimized.
9173a9b to
1d395f3
Compare
This comment has been minimized.
This comment has been minimized.
1d395f3 to
ec3f438
Compare
|
Some changes occurred in compiler/rustc_attr_parsing |
| return None; | ||
| }; | ||
|
|
||
| let Some(single) = l.single() else { |
There was a problem hiding this comment.
we should probably put a #[deprecated = "use single_element_list instead"] on .single().
There was a problem hiding this comment.
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
|
Reminder, once the PR becomes ready for a review, use |
efed69e to
ec3f438
Compare
|
ok, fair :) @bors r+ rollup |
…szelmann distinguish "expected a single argument" and "expected an argument" on attribute parsing
Rollup merge of #154827 - scrabsha:push-zuosxmmnzkrq, r=jdonszelmann distinguish "expected a single argument" and "expected an argument" on attribute parsing
First commit is the real thing, the commits that follow are refactorings of patterns i kept noticing.
Renders as:
