Skip to content

Commit 3864645

Browse files
fmeasejdonszelmann
andcommitted
Don't delay a bug on malformed meta items involving interpolated tokens
Co-authored-by: Jana Dönszelmann <[email protected]>
1 parent 9d6fe3d commit 3864645

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

compiler/rustc_attr_parsing/src/parser.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_ast_pretty::pprust;
1313
use rustc_errors::DiagCtxtHandle;
1414
use rustc_hir::{self as hir, AttrPath};
1515
use rustc_span::symbol::{Ident, kw, sym};
16-
use rustc_span::{ErrorGuaranteed, Span, Symbol};
16+
use rustc_span::{Span, Symbol};
1717

1818
pub struct SegmentIterator<'a> {
1919
offset: usize,
@@ -176,7 +176,7 @@ impl<'a> ArgParser<'a> {
176176
pub enum MetaItemOrLitParser<'a> {
177177
MetaItemParser(MetaItemParser<'a>),
178178
Lit(MetaItemLit),
179-
Err(Span, ErrorGuaranteed),
179+
Err(Span),
180180
}
181181

182182
impl<'a> MetaItemOrLitParser<'a> {
@@ -186,7 +186,7 @@ impl<'a> MetaItemOrLitParser<'a> {
186186
generic_meta_item_parser.span()
187187
}
188188
MetaItemOrLitParser::Lit(meta_item_lit) => meta_item_lit.span,
189-
MetaItemOrLitParser::Err(span, _) => *span,
189+
MetaItemOrLitParser::Err(span) => *span,
190190
}
191191
}
192192

@@ -495,12 +495,9 @@ impl<'a> MetaItemListParserContext<'a> {
495495
// where the macro didn't expand to a literal. An error is already given
496496
// for this at this point, and then we do continue. This makes this path
497497
// reachable...
498-
let e = self.dcx.span_delayed_bug(
499-
*span,
500-
"expr in place where literal is expected (builtin attr parsing)",
501-
);
502-
503-
return Some(MetaItemOrLitParser::Err(*span, e));
498+
// NOTE: For backward compatibility we can't emit any error / delayed bug here (yet).
499+
// See <https://github.com/rust-lang/rust/issues/140612>
500+
return Some(MetaItemOrLitParser::Err(*span));
504501
} else {
505502
self.next_path()?
506503
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
extern crate proc_macro;
2+
3+
use proc_macro::TokenStream;
4+
5+
#[proc_macro_derive(Derive, attributes(arg))]
6+
pub fn derive(_: TokenStream) -> TokenStream {
7+
TokenStream::new()
8+
}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/137687#issuecomment-2816312274>.
2+
//@ proc-macro: derive_macro_with_helper.rs
3+
//@ edition: 2018
4+
//@ check-pass
5+
6+
macro_rules! call_macro {
7+
($text:expr) => {
8+
#[derive(derive_macro_with_helper::Derive)]
9+
#[arg($text)]
10+
pub struct Foo;
11+
};
12+
}
13+
14+
call_macro!(1 + 1);
15+
16+
fn main() {}

0 commit comments

Comments
 (0)