about summary refs log tree commit diff
path: root/compiler/rustc_attr_parsing
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_attr_parsing')
-rw-r--r--compiler/rustc_attr_parsing/src/context.rs5
-rw-r--r--compiler/rustc_attr_parsing/src/parser.rs13
2 files changed, 12 insertions, 6 deletions
diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs
index 99eee0d3c4a..0e6b0bab082 100644
--- a/compiler/rustc_attr_parsing/src/context.rs
+++ b/compiler/rustc_attr_parsing/src/context.rs
@@ -333,7 +333,10 @@ impl<'sess> AttributeParser<'sess> {
                 {
                     lit
                 } else {
-                    let guar = self.dcx().has_errors().unwrap();
+                    let guar = self.dcx().span_delayed_bug(
+                        args.span().unwrap_or(DUMMY_SP),
+                        "expr in place where literal is expected (builtin attr parsing)",
+                    );
                     ast::MetaItemLit {
                         symbol: kw::Empty,
                         suffix: None,
diff --git a/compiler/rustc_attr_parsing/src/parser.rs b/compiler/rustc_attr_parsing/src/parser.rs
index 0ee0ea4ea59..b6d66af4466 100644
--- a/compiler/rustc_attr_parsing/src/parser.rs
+++ b/compiler/rustc_attr_parsing/src/parser.rs
@@ -13,7 +13,7 @@ use rustc_ast_pretty::pprust;
 use rustc_errors::DiagCtxtHandle;
 use rustc_hir::{self as hir, AttrPath};
 use rustc_span::symbol::{Ident, kw};
-use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol};
+use rustc_span::{ErrorGuaranteed, Span, Symbol};
 
 pub struct SegmentIterator<'a> {
     offset: usize,
@@ -127,7 +127,7 @@ impl<'a> ArgParser<'a> {
             }
             AttrArgs::Eq { eq_span, expr } => Self::NameValue(NameValueParser {
                 eq_span: *eq_span,
-                value: expr_to_lit(dcx, &expr),
+                value: expr_to_lit(dcx, &expr, *eq_span),
                 value_span: expr.span,
             }),
         }
@@ -348,7 +348,7 @@ impl NameValueParser {
     }
 }
 
-fn expr_to_lit(dcx: DiagCtxtHandle<'_>, expr: &Expr) -> MetaItemLit {
+fn expr_to_lit(dcx: DiagCtxtHandle<'_>, expr: &Expr, span: Span) -> MetaItemLit {
     // In valid code the value always ends up as a single literal. Otherwise, a dummy
     // literal suffices because the error is handled elsewhere.
     if let ExprKind::Lit(token_lit) = expr.kind
@@ -356,8 +356,11 @@ fn expr_to_lit(dcx: DiagCtxtHandle<'_>, expr: &Expr) -> MetaItemLit {
     {
         lit
     } else {
-        let guar = dcx.has_errors().unwrap();
-        MetaItemLit { symbol: kw::Empty, suffix: None, kind: LitKind::Err(guar), span: DUMMY_SP }
+        let guar = dcx.span_delayed_bug(
+            span,
+            "expr in place where literal is expected (builtin attr parsing)",
+        );
+        MetaItemLit { symbol: kw::Empty, suffix: None, kind: LitKind::Err(guar), span }
     }
 }