rustfmt: rustfmt panics on Windows

rustfmt 0.8.3 works fine but when I run rustfmt 0.8.4, I get the following

cargo fmt
thread 'main' panicked at 'failed to emit error: operation not supported by the terminal', C:\Users\epage\.cargo\registry\src\github.com-1ecc6299db9ec823\syntex_errors-0.58.1\src\emitter.rs:1043
stack backtrace:
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: <unknown>
  13: <unknown>
  14: <unknown>
  15: BaseThreadInitThunk

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 15 (8 by maintainers)

Most upvoted comments

@nrc Doing some more testing on Windows nightly.

TLDR; libsyntax branch appears to fix the problem, and my problems from two days ago seem to have been fixed by updating the nightly compiler.

Testing Setup

rustup toolchain list
stable-x86_64-pc-windows-msvc (default)
nightly-x86_64-pc-windows-msvc

rustc --version
rustc 1.17.0 (56124baa9 2017-04-24)

Master Branch @ 15323fc38b8deb761594daba97ba09728ac6a48e

Invalid Rust code panics rustfmt:

Input

a

fn main() {
    let x = 0;
}

Output

cargo +nightly run --bin  rustfmt -- ..\rust-test\src\main.rs --write-mode=diff
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target\debug\rustfmt.exe ..\rust-test\src\main.rs --write-mode=diff`
thread 'main' panicked at 'failed to emit error: operation not supported by the terminal', C:\Users\User\.cargo\registry\src\github.com-1ecc6299db9ec823\syntex_errors-0.58.1\src\emitter.rs:1043
stack backtrace:
   0: std::sys_common::backtrace::_print
             at C:\projects\rust\src\libstd\sys_common\backtrace.rs:94
   1: std::panicking::default_hook::{{closure}}
             at C:\projects\rust\src\libstd\panicking.rs:354
   2: std::panicking::default_hook
             at C:\projects\rust\src\libstd\panicking.rs:371
   3: std::panicking::rust_panic_with_hook
             at C:\projects\rust\src\libstd\panicking.rs:549
   4: std::panicking::begin_panic<collections::string::String>
             at C:\projects\rust\src\libstd\panicking.rs:511
   5: std::panicking::begin_panic_fmt
             at C:\projects\rust\src\libstd\panicking.rs:495
   6: syntex_errors::emitter::EmitterWriter::emit_messages_default
             at C:\Users\User\.cargo\registry\src\github.com-1ecc6299db9ec823\syntex_errors-0.58.1\src\emitter.rs:1043
   7: syntex_errors::emitter::{{impl}}::emit
             at C:\Users\User\.cargo\registry\src\github.com-1ecc6299db9ec823\syntex_errors-0.58.1\src\emitter.rs:37
   8: syntex_errors::diagnostic_builder::DiagnosticBuilder::emit
             at C:\Users\User\.cargo\registry\src\github.com-1ecc6299db9ec823\syntex_errors-0.58.1\src\diagnostic_builder.rs:98
   9: rustfmt::format_input<std::io::stdio::Stdout>
             at .\src\lib.rs:598
  10: rustfmt::run
             at .\src\lib.rs:655
  11: rustfmt::execute
             at .\src\bin\rustfmt.rs:286
  12: rustfmt::main
             at .\src\bin\rustfmt.rs:299
  13: panic_unwind::__rust_maybe_catch_panic
             at C:\projects\rust\src\libpanic_unwind\lib.rs:98
  14: std::rt::lang_start
             at C:\projects\rust\src\libstd\rt.rs:50
  15: main
  16: __scrt_common_main_seh
             at f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:253
  17: BaseThreadInitThunk
error: process didn't exit successfully: `target\debug\rustfmt.exe ..\rust-test\src\main.rs --write-mode=diff` (exit code: 101)

libsyntax Branch

Input

a

fn main() {
    let x = 0;
}

Output

Success!

cargo +nightly run --bin rustfmt -- --write-mode diff ..\rust-test\src\main.rs
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target\debug\rustfmt.exe --write-mode diff ..\rust-test\src\main.rs`
error: expected one of `!` or `::`, found `fn`
 --> \\?\C:\Users\User\PycharmProjects\rust-test\src\main.rs:2:1
  |
1 | a
  |  - expected one of `!` or `::` here
2 | fn main() {
  | ^^ unexpected token

error: process didn't exit successfully: `target\debug\rustfmt.exe --write-mode diff ..\rust-test\src\main.rs` (exit code: 2)

Input

mod other;  // file other.rs exists

fn main() {
let x = 0;
}

Output

Works correctly, other than some ? characters displayed on the ends of lines in terminal (characters that cmd.exe doesn’t support?

cargo +nightly run --bin rustfmt -- --write-mode diff ..\rust-test\src\main.rs
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target\debug\rustfmt.exe --write-mode diff ..\rust-test\src\main.rs`
Diff in \\?\C:\Users\User\PycharmProjects\rust-test\src\main.rs at line 1:
 mod other;⏎
 ⏎
 fn main() {⏎
-let x = 0;⏎
+    let x = 0;⏎
 }⏎
error: process didn't exit successfully: `target\debug\rustfmt.exe --write-mode diff ..\rust-test\src\main.rs` (exit code: 4)

Same for me. When i configure a task that calls “cargo fmt” in Visual Studio Code, i get this in the output pane:

running command> cargo fmt
error: file not found for module `core`
 --> \\?\C:\Users\Arnold\sw\rust\cargo-fmt-crash\src\main.rs:1:5
  |
1 | mod core;
  |     ^^^^
  |
  = help: name the file either core.rs or core/mod.rs inside the directory "\\\\?\\C:\\Users\\Arnold\\sw\\rust\\cargo-fmt-crash\\src"

With 2 source files.

// src/main.rs

mod core;
fn main() {
    core::run();
}
// src/core/mod.rs

pub fn run() {
    println!("Hello, world!");
}

When the file src/core/mod.rs is renamed to src/core.rs no error occures.