about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTheo <theo.emeriau@gmail.com>2021-09-16 21:00:11 +0200
committerTheo <theo.emeriau@gmail.com>2021-09-19 10:53:49 +0200
commit250a3e482f125e96b37d66d6d87be7b09436be5c (patch)
treeda874203a94f719a78337ba07813fba77ee83c6c
parent2b5ddf36fdc784106b3a064d93dd054c32b1f10f (diff)
downloadrust-250a3e482f125e96b37d66d6d87be7b09436be5c.tar.gz
rust-250a3e482f125e96b37d66d6d87be7b09436be5c.zip
Resolve issue 85066
Fix : use struct_dummy

Fix different os messages
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs14
-rw-r--r--src/test/ui/attributes/extented-attribute-macro-error.rs8
-rw-r--r--src/test/ui/attributes/extented-attribute-macro-error.stderr10
3 files changed, 32 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index dc80dab8c6c..9216c2fe2e4 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -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)
         })
diff --git a/src/test/ui/attributes/extented-attribute-macro-error.rs b/src/test/ui/attributes/extented-attribute-macro-error.rs
new file mode 100644
index 00000000000..f5f75f9f4da
--- /dev/null
+++ b/src/test/ui/attributes/extented-attribute-macro-error.rs
@@ -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() {}
diff --git a/src/test/ui/attributes/extented-attribute-macro-error.stderr b/src/test/ui/attributes/extented-attribute-macro-error.stderr
new file mode 100644
index 00000000000..e4deeacd0ff
--- /dev/null
+++ b/src/test/ui/attributes/extented-attribute-macro-error.stderr
@@ -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
+