@@ -13,7 +13,7 @@ use rustc_ast_pretty::pprust;
13
13
use rustc_errors:: DiagCtxtHandle ;
14
14
use rustc_hir:: { self as hir, AttrPath } ;
15
15
use rustc_span:: symbol:: { Ident , kw} ;
16
- use rustc_span:: { DUMMY_SP , ErrorGuaranteed , Span , Symbol } ;
16
+ use rustc_span:: { ErrorGuaranteed , Span , Symbol } ;
17
17
18
18
pub struct SegmentIterator < ' a > {
19
19
offset : usize ,
@@ -127,7 +127,7 @@ impl<'a> ArgParser<'a> {
127
127
}
128
128
AttrArgs :: Eq { eq_span, expr } => Self :: NameValue ( NameValueParser {
129
129
eq_span : * eq_span,
130
- value : expr_to_lit ( dcx, & expr) ,
130
+ value : expr_to_lit ( dcx, & expr, * eq_span ) ,
131
131
value_span : expr. span ,
132
132
} ) ,
133
133
}
@@ -348,16 +348,19 @@ impl NameValueParser {
348
348
}
349
349
}
350
350
351
- fn expr_to_lit ( dcx : DiagCtxtHandle < ' _ > , expr : & Expr ) -> MetaItemLit {
351
+ fn expr_to_lit ( dcx : DiagCtxtHandle < ' _ > , expr : & Expr , span : Span ) -> MetaItemLit {
352
352
// In valid code the value always ends up as a single literal. Otherwise, a dummy
353
353
// literal suffices because the error is handled elsewhere.
354
354
if let ExprKind :: Lit ( token_lit) = expr. kind
355
355
&& let Ok ( lit) = MetaItemLit :: from_token_lit ( token_lit, expr. span )
356
356
{
357
357
lit
358
358
} else {
359
- let guar = dcx. has_errors ( ) . unwrap ( ) ;
360
- MetaItemLit { symbol : kw:: Empty , suffix : None , kind : LitKind :: Err ( guar) , span : DUMMY_SP }
359
+ let guar = dcx. span_delayed_bug (
360
+ span,
361
+ "expr in place where literal is expected (builtin attr parsing)" ,
362
+ ) ;
363
+ MetaItemLit { symbol : kw:: Empty , suffix : None , kind : LitKind :: Err ( guar) , span }
361
364
}
362
365
}
363
366
0 commit comments