Skip to content

Somewhat confusing error with extended_key_value_attributes #85066

Closed

Description

@camelid

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)

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
    D-confusingDiagnostics: Confusing error or lint that should be reworked.
    D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    A-attributesArea: Attributes (`#[…]`, `#![…]`)
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    on May 8, 2021
  2. camelid commented on May 25, 2021

    @camelid
    MemberAuthor

    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.

  3. jyn514 commented on Sep 16, 2021

    @jyn514
    Member

    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.

  4. added
    E-easyCall 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.
    on Sep 16, 2021
  5. Wardenfar commented on Sep 16, 2021

    @Wardenfar
    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

  6. jyn514 commented on Sep 16, 2021

    @jyn514
    Member

    @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 :)

  7. Wardenfar commented on Sep 16, 2021

    @Wardenfar
    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() {}
    ```
    
  8. jyn514 commented on Sep 16, 2021

    @jyn514
    Member

    @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.

  9. Wardenfar commented on Sep 16, 2021

    @Wardenfar
    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

  10. jyn514 commented on Sep 16, 2021

    @jyn514
    Member

    @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.

  11. added a commit that references this issue on Sep 19, 2021
    833312b
  12. added 2 commits that reference this issue on Sep 23, 2021
    e9d1d12
    5da2f46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.D-verboseDiagnostics: 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.E-mentorCall 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-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions