Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Kestrer opened this issue Jan 6, 2021 · 6 comments · Fixed by #80789
Assignees
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-proc-macros Area: Procedural macros C-bug Category: This is a bug. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Kestrer
Copy link
Contributor

Kestrer commented Jan 6, 2021

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

@jonas-schievink jonas-schievink added A-proc-macros Area: Procedural macros C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Jan 6, 2021
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jan 6, 2021
@camelid camelid added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label Jan 6, 2021
@camelid
Copy link
Member

camelid commented Jan 6, 2021

cc #79812

@camelid camelid added the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Jan 6, 2021
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 7, 2021
@jyn514
Copy link
Member

jyn514 commented Jan 7, 2021

cc @Aaron1011

@apiraino apiraino added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jan 7, 2021
@apiraino
Copy link
Contributor

apiraino commented Jan 7, 2021

Assigning P-high as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@pnkfelix
Copy link
Member

pnkfelix commented Jan 7, 2021

assigning to self to confirm if #79812 is the cause of the breakage, and if so, revert the PR until it can be revised to handle this case.

@pnkfelix pnkfelix self-assigned this Jan 7, 2021
@Aaron1011
Copy link
Member

This is caused by us not handling StmtKind::Empty properly - I'm working on a fix.

@Aaron1011
Copy link
Member

Opened #80789

bors added a commit to rust-lang-ci/rust that referenced this issue Jan 10, 2021
Synthesize a `TokenStream` for `StmtKind::Empty`

Fixes rust-lang#80760
@bors bors closed this as completed in 3ed6caa Jan 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-proc-macros Area: Procedural macros C-bug Category: This is a bug. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants