Skip to content

Commit 5da2f46

Browse files
Rollup merge of #89023 - Wardenfar:issue-85066, r=nagisa
Resolve issue : Somewhat confusing error with extended_key_value_attributes Fixes #85066
2 parents 586d028 + 250a3e4 commit 5da2f46

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

compiler/rustc_parse/src/parser/expr.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,20 @@ impl<'a> Parser<'a> {
15681568

15691569
pub(super) fn parse_lit(&mut self) -> PResult<'a, Lit> {
15701570
self.parse_opt_lit().ok_or_else(|| {
1571+
if let token::Interpolated(inner) = &self.token.kind {
1572+
let expr = match inner.as_ref() {
1573+
token::NtExpr(expr) => Some(expr),
1574+
token::NtLiteral(expr) => Some(expr),
1575+
_ => None,
1576+
};
1577+
if let Some(expr) = expr {
1578+
if matches!(expr.kind, ExprKind::Err) {
1579+
self.diagnostic()
1580+
.delay_span_bug(self.token.span, &"invalid interpolated expression");
1581+
return self.diagnostic().struct_dummy();
1582+
}
1583+
}
1584+
}
15711585
let msg = format!("unexpected token: {}", super::token_descr(&self.token));
15721586
self.struct_span_err(self.token.span, &msg)
15731587
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// normalize-stderr-test: "couldn't read.*" -> "couldn't read the file"
2+
3+
#![feature(extended_key_value_attributes)]
4+
#![doc = include_str!("../not_existing_file.md")]
5+
struct Documented {}
6+
//~^^ ERROR couldn't read
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: couldn't read the file
2+
--> $DIR/extented-attribute-macro-error.rs:4:10
3+
|
4+
LL | #![doc = include_str!("../not_existing_file.md")]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: this error originates in the macro `include_str` (in Nightly builds, run with -Z macro-backtrace for more info)
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)