Skip to content

Panic with 'Missing tokens for nt ";"' when passing statement to proc macro from declarative macro #80760

Closed
@Kestrer

Description

@Kestrer

This the the lib.rs of a proc macro crate pm:

use proc_macro::TokenStream;

#[proc_macro]
pub fn pm(input: TokenStream) -> TokenStream {
    // It works if this is `format!("{}", input)`
    format!("{:?}", input);
    TokenStream::new()
}

And here is the main.rs of another crate:

macro_rules! t {
    // It works if I take a tt
    ($s:stmt) => {
        pm::pm!($s);
    }
}

t!(;);

When building, this outputs:

error: proc macro panicked
 --> src/lib.rs:3:9
  |
3 |         pm::pm!($s);
  |         ^^^^^^^^^^^^
...
7 | t!(;);
  | ------ in this macro invocation
  |
  = help: message: Missing tokens at src/lib.rs:3:16: 3:18 (#6) for nt ";"
  = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

Version it worked on

1.49.0, 1.50.0-beta.5

Version with regression

rustc 1.51.0-nightly (da305a2 2021-01-05)
binary: rustc
commit-hash: da305a2
commit-date: 2021-01-05
host: x86_64-unknown-linux-gnu
release: 1.51.0-nightly

Metadata

Metadata

Assignees

Labels

A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-proc-macrosArea: Procedural macrosC-bugCategory: This is a bug.E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustcP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions