Skip to content

Somewhat confusing error with extended_key_value_attributes #85066

Closed
@camelid

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)

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