Skip to content

Commit 92abfe5

Browse files
committed
add test to reproduce #137687 and add a hotfix
1 parent ab5b1be commit 92abfe5

7 files changed

+65
-9
lines changed

compiler/rustc_attr_parsing/src/parser.rs

+11-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,14 @@ 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+
// FIXME(jdonszelmann): proc macro helper attributes should be filtered out and this
499+
// shouldn't trigger anymore. See #137687
500+
// let e = self.dcx.span_delayed_bug(
501+
// *span,
502+
// "expr in place where literal is expected (builtin attr parsing)",
503+
// );
504+
505+
return Some(MetaItemOrLitParser::Err(*span));
504506
} else {
505507
self.next_path()?
506508
};
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(Bar, attributes(arg))]
6+
pub fn derive_bar(_: proc_macro::TokenStream) -> proc_macro::TokenStream {
7+
TokenStream::new()
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@compile-flags: --crate-type=lib
2+
// reproduces #137687
3+
// FIXME(jdonszelmann): should ERROR malformed `crate_name` attribute input but now still ignored.
4+
// This is for the beta backport of 1.87
5+
#[crate_name = concat!("Cloneb")]
6+
7+
macro_rules! inline {
8+
() => {};
9+
}
10+
11+
#[crate_name] //~ ERROR malformed `crate_name` attribute input
12+
mod foo {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: malformed `crate_name` attribute input
2+
--> $DIR/crate_name_on_other_items.rs:11:1
3+
|
4+
LL | #[crate_name]
5+
| ^^^^^^^^^^^^^ help: must be of the form: `#[crate_name = "name"]`
6+
7+
error: aborting due to 1 previous error
8+
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ proc-macro: bar_derive.rs
2+
//@ check-pass
3+
4+
extern crate bar_derive;
5+
use bar_derive as bar;
6+
7+
macro_rules! call_macro {
8+
($text:expr) => {
9+
#[derive(bar::Bar)]
10+
#[arg($text)]
11+
pub struct Foo;
12+
};
13+
}
14+
15+
call_macro!(1 + 1);
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@check-pass
2+
//@ compile-flags: --print=file-names
3+
4+
#[crate_name = concat!("wrapped")]
5+
6+
macro_rules! inline {
7+
() => {};
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print-file-names-request-malformed-crate-name-3

0 commit comments

Comments
 (0)