Skip to content

select! cannot contain more than 64 macro calls #2097

Closed
@dbrgn

Description

@dbrgn

This is a bit strange, but based on experimentation, I hope that the issue title is right.

The following code fails to compile:

#![recursion_limit = "2048"]

use futures::{select, channel::mpsc};
use futures_util::sink::SinkExt;
use futures_util::stream::StreamExt;

async fn blah() {
    let (mut tx, mut rx) = mpsc::channel(8);
    tx.send(42u8).await;
    
    loop {
        let mut next_msg = rx.next();
        select! {
            _ = next_msg => {
                println!("1");
                ...
                println!("65"); 
            }
        }
    }
}

fn main() {
    let myfuture = blah();
}

Error message:

   Compiling playground v0.0.1 (/playground)
error: no rules expected the token `!`
  --> src/main.rs:13:9
   |
13 | /         select! {
14 | |             _ = next_msg => {
15 | |                 println!("1");
16 | |                 println!("2");
...  |
80 | |             }
81 | |         }
   | |_________^ no rules expected this token in macro call
   |
   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

Removing one of the println calls makes it compile.

The problem is not specific to println!, it also happens with macros like debug!.

Reproducer: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=de8c4b5aa1ae3ac9c432952e9143fb59

This happened to me in a real-world project due to logging calls in a big select block 😕

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macroArea: macro related

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions