Rollup merge of #89023 - Wardenfar:issue-85066, r=nagisa

Resolve issue : Somewhat confusing error with extended_key_value_attributes

Fixes #85066
This commit is contained in:
Jubilee 2021-09-23 17:31:42 -07:00 committed by GitHub
commit 5da2f460b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 0 deletions

View File

@ -1568,6 +1568,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)
})

View File

@ -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() {}

View File

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