Skip to content

Resolve issue : Somewhat confusing error with extended_key_value_attributes #89023

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

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1493,6 +1493,20 @@ impl<'a> Parser<'a> {

pub(super) fn parse_lit(&mut self) -> PResult<'a, Lit> {
self.parse_opt_lit().ok_or_else(|| {
if let token::Interpolated(inner) = &self.token.kind {
let expr = match inner.as_ref() {
token::NtExpr(expr) => Some(expr),
token::NtLiteral(expr) => Some(expr),
_ => None,
};
if let Some(expr) = expr {
if matches!(expr.kind, ExprKind::Err) {
self.diagnostic()
.delay_span_bug(self.token.span, &"invalid interpolated expression");
return self.diagnostic().struct_dummy();
}
}
}
let msg = format!("unexpected token: {}", super::token_descr(&self.token));
self.struct_span_err(self.token.span, &msg)
})
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/attributes/extented-attribute-macro-error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// normalize-stderr-test: "couldn't read.*" -> "couldn't read the file"

#![feature(extended_key_value_attributes)]
#![doc = include_str!("../not_existing_file.md")]
struct Documented {}
//~^^ ERROR couldn't read

fn main() {}
10 changes: 10 additions & 0 deletions src/test/ui/attributes/extented-attribute-macro-error.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: couldn't read the file
--> $DIR/extented-attribute-macro-error.rs:4:10
|
LL | #![doc = include_str!("../not_existing_file.md")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error