-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tweak macro parse errors when reaching EOF during macro call parse #61026
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
589db38
to
a556363
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
2 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
src/libsyntax/ext/derive.rs
Outdated
@@ -17,8 +17,11 @@ pub fn collect_derives(cx: &mut ExtCtxt<'_>, attrs: &mut Vec<ast::Attribute>) -> | |||
return true; | |||
} | |||
if !attr.is_meta_item_list() { | |||
cx.span_err(attr.span, | |||
"attribute must be of the form `#[derive(Trait1, Trait2, ...)]`"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The output was supposed to be identical to the generic attribute input validation infra in feature_gate.rs
.
(Some attributes like cfg
or derive
are very special, and have to be checked before that generic infra works.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed plenty of attribute-specific messages like "missing traits to be derived" in #57321 because the generic messages are good enough and intuitive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cfg_attr
check should probably follow the same template.
I still hope that the special attributes can be made less special and go through the generic infra one day.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was considering (but obviously didn't do it in this PR) moving the generic errors to this new format. Is the concern about these being inconsistent or fundamentally against the new output? If it is the former, should I just do that work here for you to see what it'd look like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fist, consistency, second, I don't like the new wording.
"Bad attribute" doesn't says that the issue is with the attribute input specifically, and not with name or something, the format suggestion is moved too far into a note.
The status quo looks good to me (that's not surprising, since I wrote it) and I don't understand the motivation behind the change.
If I'd change anything, I'd rather move the "must be of the form #[...]" to a suggestion, since it's indeed an approximate suggesion (IIRC, it will be rendered as a label then and will stay close enough).
For the primary message in that case I'd choose something mentioning input, e.g. "ill-formed attribute input".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made these changes and it ballooned the size of the PR, I hope that's ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, you can move the EOF staff into a separate PR and consider it r+'d.
I'll be mostly unavailable in the next few days, so this PR may land with a delay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kept the EOF stuff here and opened a new one with the rewording at #61140
- Add detail on origin of current parser when reaching EOF and stop saying "found <eof>" and point at the end of macro calls - Handle empty `cfg_attr` attribute - Reword empty `derive` attribute error
--> $DIR/bad-annotation.rs:17:1 | ||
| | ||
LL | #[rustc_on_unimplemented] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
help: the following are the possible correct uses | ||
| | ||
LL | #[rustc_on_unimplemented(/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now it's not possible to have more than one suggestion per input type, but now that we suggest we could add it and have a suggestion for each combination (this is probably not best example that would benefit of this).
src/test/ui/no_crate_type.stderr
Outdated
--> $DIR/no_crate_type.rs:2:1 | ||
| | ||
LL | #![crate_type] | ||
| ^^^^^^^^^^^^^^ | ||
| ^^^^^^^^^^^^^^ help: must be of the form: `#[crate_type = "bin|lib|..."]` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would benefit of multiple suggestions of the same type.
--> $DIR/malformed-unwind-1.rs:3:1 | ||
| | ||
LL | #[unwind] | ||
| ^^^^^^^^^ | ||
| ^^^^^^^^^ help: must be of the form: `#[unwind(allowed|aborts)]` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would benefit of multiple suggestions
--> $DIR/reasons-erroneous.rs:9:29 | ||
| | ||
LL | #![warn(bare_trait_objects, reasons = "leaders to no sure land, guides their bearings lost")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bad attribute argument |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add levenshtein distance enabled suggestions?
| ^ | ||
| | ||
= help: reason must be a string literal | ||
| ^ reason must be a string literal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could suggest "0"
.
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: reason must be a string literal | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reason must be a string literal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could suggest removing the b
.
CC @rust-lang/wg-diagnostics for more eyes |
@bors r=petrochenkov as per #61026 (comment), the extraneous changes have been moved to #61140 |
📌 Commit ee7593e has been approved by |
…enkov Tweak macro parse errors when reaching EOF during macro call parse Add detail on origin of current parser when reaching EOF, stop saying "found `<eof>`" and point at the end of macro calls. Fix rust-lang#27569.
Rollup of 13 pull requests Successful merges: - rust-lang#61026 (Tweak macro parse errors when reaching EOF during macro call parse) - rust-lang#61095 (Update cargo) - rust-lang#61096 (tidy: don't short-circuit on license error) - rust-lang#61107 (Fix a couple docs typos) - rust-lang#61110 (Revert edition-guide toolstate override) - rust-lang#61111 (Fixed type-alias-bounds lint doc) - rust-lang#61113 (Deprecate `FnBox`. `Box<dyn FnOnce()>` can be called directly, since 1.35) - rust-lang#61116 (Remove the incorrect warning from README.md) - rust-lang#61118 (Dont ICE on an attempt to use GAT without feature gate) - rust-lang#61121 (improve debug-printing of scalars) - rust-lang#61125 (Updated my mailmap entry) - rust-lang#61134 (Annotate each `reverse_bits` with `#[must_use]`) - rust-lang#61138 (Move async/await tests to their own folder) Failed merges: r? @ghost
Rollup of 13 pull requests Successful merges: - #61026 (Tweak macro parse errors when reaching EOF during macro call parse) - #61095 (Update cargo) - #61096 (tidy: don't short-circuit on license error) - #61107 (Fix a couple docs typos) - #61110 (Revert edition-guide toolstate override) - #61111 (Fixed type-alias-bounds lint doc) - #61113 (Deprecate `FnBox`. `Box<dyn FnOnce()>` can be called directly, since 1.35) - #61116 (Remove the incorrect warning from README.md) - #61118 (Dont ICE on an attempt to use GAT without feature gate) - #61121 (improve debug-printing of scalars) - #61125 (Updated my mailmap entry) - #61134 (Annotate each `reverse_bits` with `#[must_use]`) - #61138 (Move async/await tests to their own folder) Failed merges: r? @ghost
Rustup to rust-lang/rust#61026 None
Changes: ```` Rustup to rust-lang#61026 rustup rust-lang#60803 Rustup to rust-lang#59545 Rustup to rust-lang#60965 clippy: bump rustc_tools util version to 0.2 rustc_tools_util: fix typo in docs (readme) rustc_tool_utils: bump version to 0.2.0 update if_chain to 1.0.0 tests: update needless_bool test stderr cargo fmt Rustup to rust-lang#60740 Lifetimes UI test cleanup ````
…lwoerister Reword malformed attribute input diagnostics - Handle empty `cfg_attr` attribute - Reword empty `derive` attribute error - Use consistend error message: "malformed `attrname` attribute input" - Provide suggestions when possible - Move note/help to label/suggestion - Use consistent wording "ill-formed" -> "malformed" - Move diagnostic logic out of parser Split up from rust-lang#61026, where there's prior conversation.
Reword malformed attribute input diagnostics - Handle empty `cfg_attr` attribute - Reword empty `derive` attribute error - Use consistend error message: "malformed `attrname` attribute input" - Provide suggestions when possible - Move note/help to label/suggestion - Use consistent wording "ill-formed" -> "malformed" - Move diagnostic logic out of parser Split up from #61026, where there's prior conversation.
Add detail on origin of current parser when reaching EOF, stop saying "found
<eof>
" and point at the end of macro calls.Fix #27569.