Closed

Description
I tried this code:
use proc_macro::TokenStream;
#[proc_macro_attribute]
pub fn give_me_trait_alias(_: TokenStream, input: TokenStream) -> TokenStream {
assert!(!input.is_empty());
Default::default()
}
and
#[give_me_trait_alias]
trait Alias = Sized;
I expected to see this happen: the compiler complained #![feature(trait_alias)]
was missing, or on nightly, after adding #![feature(trait_alias)]
, compiled successfully, just like built-in #[allow]
on trait alias.
Instead, this happened: the assertion failed. The compiler gave an empty TokenStream
as input
to the procedural macro:
error: custom attribute panicked
--> tests/trait_alias.rs:3:1
|
3 | #[give_me_trait_alias]
| ^^^^^^^^^^^^^^^^^^^^^^
|
= help: message: assertion failed: !input.is_empty()
Edit: I found this in the compiler's log:
INFO rustc_parse cached tokens found, but they're not "probably equal", going with stringified version
INFO rustc_parse cached tokens: trait Alias = Sized ;
INFO rustc_parse reparsed tokens:
INFO rustc_parse cached tokens debug: TokenStream([(Token(Token { kind: Ident("trait", false), span: tests/trait_alias.rs:4:1: 4:6 (#0) }), Alone), (Token(Token { kind: Ident("Alias", false), span: tests/trait_alias.rs:4:7: 4:12 (#0) }), Alone), (Token(Token { kind: Eq, span: tests/trait_alias.rs:4:13: 4:14 (#0) }), Alone), (Token(Token { kind: Ident("Sized", false), span: tests/trait_alias.rs:4:15: 4:20 (#0) }), Joint), (Token(Token { kind: Semi, span: tests/trait_alias.rs:4:20: 4:21 (#0) }), Alone)])
INFO rustc_parse reparsed tokens debug: TokenStream([])
rust/compiler/rustc_parse/src/lib.rs
Lines 372 to 375 in 8080f54
Meta
I tried this with:
cc #41517
Metadata
Metadata
Assignees
Labels
Area: Procedural macrosCategory: This is a bug.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.`#![feature(trait_alias)]`Relevant to the compiler team, which will review and decide on the PR/issue.