Skip to content
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

Somewhat confusing error with extended_key_value_attributes #85066

Closed
camelid opened this issue May 8, 2021 · 8 comments · Fixed by #89023
Closed

Somewhat confusing error with extended_key_value_attributes #85066

camelid opened this issue May 8, 2021 · 8 comments · Fixed by #89023
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor 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)] T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@camelid
Copy link
Member

camelid commented May 8, 2021

Code

Note that ../README.md must not exist in order to reproduce this error:

#![feature(extended_key_value_attributes)]
#![doc = include_str!("../README.md")]

Playground

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)

@camelid camelid added A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) D-confusing Diagnostics: Confusing error or lint that should be reworked. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. F-extended_key_value_attributes `#![feature(extended_key_value_attributes)] T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-attributes Area: Attributes (`#[…]`, `#![…]`) C-enhancement Category: An issue proposing an enhancement or a PR with one. labels May 8, 2021
@camelid
Copy link
Member Author

camelid commented May 25, 2021

Note that extended_key_value_attributes is stable now (though it hasn't reached the stable channel yet), so this no longer requires a feature flag.

@jyn514
Copy link
Member

jyn514 commented Sep 16, 2021

Mentoring instructions: in

let msg = format!("unexpected token: {}", super::token_descr(&self.token));
, check if the token is a token::Interpolated(token::NtExpr(expr) | NtLiteral(expr)) and the expression is an error; if so, use delay_span_bug instead of struct_span_err.

@jyn514 jyn514 added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Sep 16, 2021
@Wardenfar
Copy link
Contributor

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 a PResult but delay_span_bug has return type ()
Sorry if i misread something

@jyn514
Copy link
Member

jyn514 commented 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
Copy link
Contributor

@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

#![feature(extended_key_value_attributes)]
#![doc = include_str!("../not_existing_file.md")]
struct Documented {}
//~^^ ERROR 2:10: 2:49: couldn't read /home/<username>/dev/rustc/rust/src/test/ui/attributes/../not_existing_file.md: No such file or directory (os error 2)

fn main() {}
```

@jyn514
Copy link
Member

jyn514 commented 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
Copy link
Contributor

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
Copy link
Member

jyn514 commented 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.

JohnTitor added a commit to JohnTitor/rust that referenced this issue Sep 19, 2021
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Sep 23, 2021
Resolve issue : Somewhat confusing error with extended_key_value_attributes

Fixes rust-lang#85066
@bors bors closed this as completed in 5da2f46 Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor 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)] T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants