rustfmt panics on Windows

Created on 10 May 2017  ·  15Comments  ·  Source: rust-lang/rustfmt

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
bug

All 15 comments

Given the error is in Syntex, this may be one that can only be solved by upgrading that dependency (and which is a bit problematic).

The odd thing is it doesn't look like the version of Syntex has changed.

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.

rustfmt 0.8.4 stopped working on Windows.

cargo.exe fmt -- --write-mode=overwrite
error: file not found for module `game`
  --> \\?\C:\Users\User\PycharmProjects\rust-belt\src\main.rs:12:5
   |
12 | mod game;
   |     ^^^^
   |
   = help: name the file either game.rs or game/mod.rs inside the directory "\\\\?\\C:\\Users\\User\\PycharmProjects\\rust-belt\\src"

And in this case the file is located in game/mod.rs.

The repository used is: https://github.com/johnthagen/rust-belt at 5bf10ea4b0e43ad8a672343f8fd40c1bb1b936e0.

If someone on Windows is using the nightly compiler, could you try using the libsyntax branch of Rustfmt please? It would be good to know if that fixes this (I suspect it will).

@nrc I checked out rustfmt and built the branch on Windows.

$ rustup --version
rustup 1.3.0 (124170c 2017-05-09)

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

$ rustc +nightly --version
rustc 1.19.0-nightly (826d8f385 2017-05-13)

$ cargo +nightly --version
cargo 0.20.0-nightly (cf17c9f71 2017-05-09)
$ cargo +nightly run --bin rustfmt
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target\debug\rustfmt.exe`
error: process didn't exit successfully: `target\debug\rustfmt.exe` (exit code: 3221225781)

It builds fine on Windows x86-64 but when I try to run I get a error. Am I missing something?

@johnthagen could you post the stacktrace for the error please?

@nrc I tried with set RUST_BACKTRACE=1 and it didn't seem to make a difference. I does pop up the following system error pop ups though in this order. I've never seen anything like this before (but I'm usually using stable on Windows). Maybe it's not even getting to execution and failing at some kind of linking step?

image

image

image

image

That suggests that it is not able to link against the compiler crates at runtime which it built against. I think you have to set some path variable so that it can find those crates, but I'm not exactly sure how to do that on Windows. I'll try and find out...

Thanks for trying this out!

No problem, feel free to ping me again if I can help out.

It sounds like you need to find the path to the dlls and add this to your PATH variable (or copy the dlls to the working directory of the exe). This path should be the same path as rustc.exe (or something quite close - maybe lib rather than bin), assuming you're not cross compiling or something.

Not cross compiling. Curious, but isn't this something rustup should take care of? For example, I tried running my Piston game on Windows nightly and it worked fine. So the difference comes from rustfmt's dependencies?

I'm not exactly sure, but I think Rustup does not handle dependencies into the compiler unless the program is a Rustup component.

@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)

@johnthagen great, thanks for checking!

Was this page helpful?
0 / 5 - 0 ratings