Skip to content

Hangs if procedural macro prints output when stdout is closed #8245

Closed
@dtolnay

Description

@dtolnay

Problem

Running cargo check | false (or more realistically cargo check | head) hangs if a macro prints more than a small number of lines to stdout.

Expected: same behavior as if the macro only prints a small number of lines to stdout, which is to not hang.

Steps

Cargo.toml

[package]
name = "repro"
version = "0.0.0"
edition = "2018"

[lib]
proc-macro = true

src/lib.rs

use proc_macro::TokenStream;

#[proc_macro]
pub fn repro(_input: TokenStream) -> TokenStream {
    // On my machine <202 lines terminates successfully.
    // >=202 lines hangs.
    for i in 0..1000 {
        println!("{}", i);
    }
    TokenStream::new()
}

src/main.rs

repro::repro!();

fn main() {}

Notes

  • Tested with current master branch of cargo (13bded9) and nightly rustc 1.45.0-nightly (a74d1862d 2020-05-14) on linux. /path/to/cargo/target/release/cargo check | head

  • Mentioning @ehuss because Ignore broken console output in some situations. #8236 looks relevant.

  • Nightly cargo panicks and hangs, so this is not a regression from Ignore broken console output in some situations. #8236 which does eliminate the panic.

  • I think the hang is cargo not rustc but I can't be sure. Reasoning: I ran cargo check --verbose to grab the last rustc invocation before the hang, and ran that rustc invocation piped to head, and that did not hang.

Metadata

Metadata

Assignees

Labels

A-console-outputArea: Terminal output, colors, progress bar, etc.C-bugCategory: bugP-highPriority: Highregression-from-stable-to-betaRegression in beta that previously worked in stable.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions