Repository navigation
Somewhat confusing error with extended_key_value_attributes #85066
Copy link
Copy link
Closed
Labels
A-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.F-extended_key_value_attributes`#![feature(extended_key_value_attributes)]`#![feature(extended_key_value_attributes)]T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
Note that ../README.md must not exist in order to reproduce this error:
#![feature(extended_key_value_attributes)]
#![doc = include_str!("../README.md")]Output
The first error is what I would expect, but the second is a bit confusing and weird:
error: couldn't read src/../README.md: No such file or directory (os error 2)
--> src/lib.rs:2:10
|
2 | #![doc = include_str!("../README.md")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: unexpected token: `(/*ERROR*/)`
--> src/lib.rs:2:10
|
2 | #![doc = include_str!("../README.md")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors
Perhaps instead of emitting unexpected token: `(/*ERROR*/)` when an error token is encountered, we could use a delay_span_bug since an error should have already occurred.
If for some reason an error had not already been emitted, the compiler would crash; otherwise, it would just show the original error.
Originally posted by @camelid in #83366 (comment)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.Diagnostics: Too much output caused by a single piece of incorrect code.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.F-extended_key_value_attributes`#![feature(extended_key_value_attributes)]`#![feature(extended_key_value_attributes)]T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Activity
camelid commentedon May 25, 2021
Note that
extended_key_value_attributesis stable now (though it hasn't reached the stable channel yet), so this no longer requires a feature flag.jyn514 commentedon Sep 16, 2021
Mentoring instructions: in
rust/compiler/rustc_parse/src/parser/expr.rs
Line 1496 in 34327f6
token::Interpolated(token::NtExpr(expr) | NtLiteral(expr))and the expression is an error; if so, usedelay_span_buginstead ofstruct_span_err.Wardenfar commentedon Sep 16, 2021
Hi @jyn514
I was searching for a first issue and i have a question :
What does
delay_span_bug? Because the function that you pin must return aPResultbutdelay_span_bughas return type()Sorry if i misread something
jyn514 commentedon Sep 16, 2021
@Wardenfar delay_span_bug means "if the compiler finishes running without first reporting another error, panic". It's useful here because error tokens should always report in an error being reported.
I think anything you return is probably fine as long as it doesn't cause further cascading errors :)
Wardenfar commentedon Sep 16, 2021
@jyn514 i fixed it but for adding a test case : i run into an edge case
the output message of the macro : include_str! is not normalized with $DIR
the ui test is working only for me. Have you a tip or i have to create an issue ?
Thanks
jyn514 commentedon Sep 16, 2021
@Wardenfar you can use
normalize-stderr-test: https://rustc-dev-guide.rust-lang.org/tests/adding.html#output-normalization. But I'm surprised $DIR doesn't work :/ that does seem like a bug.Wardenfar commentedon Sep 16, 2021
Sorry I was not clear : the $DIR is working for the test.stderr
But the path is not replace for the error comment in the test.rs because the path read by include_str is in the error message
@jyn514
jyn514 commentedon Sep 16, 2021
@Wardenfar don't put the whole name in the .rs file - you just need to put a substring. Something like
//~^^ ERROR No such file or directory.Rollup merge of rust-lang#89023 - Wardenfar:issue-85066, r=nagisa
Rollup merge of rust-lang#89023 - Wardenfar:issue-85066, r=nagisa
Rollup merge of rust-lang#89023 - Wardenfar:issue-85066, r=nagisa