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

Catch panics in the parser #753

Closed
msiemens opened this issue Jan 9, 2016 · 3 comments
Closed

Catch panics in the parser #753

msiemens opened this issue Jan 9, 2016 · 3 comments
Labels
bug Panic, non-idempotency, invalid code, etc.

Comments

@msiemens
Copy link

msiemens commented Jan 9, 2016

I'm not sure whether this is the right repo, but: When running rust-fmt on a special line of code, I get a panic from syntex_syntax.

Code:

use something;;  // two semicolons!

Error message + backtrace:

C:\Users\markus\Documents\Coding\rust\archer\src\model.rs:1:15: 1:16 error: expected item, found `;`
C:\Users\markus\Documents\Coding\rust\archer\src\model.rs:1 use something;;
                                                                          ^
thread '<main>' panicked at 'Box<Any>', C:/Users/markus/.multirust/toolchains/nightly/cargo\registry\src\github.com-88ac128001ac3a9a\syntex_syntax-0.23.0\src\parse/mod.rs:76
stack backtrace:
   0:           0x8cc88b - sys::backtrace::write::hf2d10e81df3aa926vhu
   1:           0x8d4d87 - panicking::default_handler::hd510b953de0f6c64kTy
   2:           0x8963f8 - sys_common::unwind::begin_unwind_inner::h6ed14856f3079d19S4s
   3:           0x53cb0a - sys_common::unwind::begin_unwind::h4979745220048331745
   4:           0x5a44de - parse::parse_crate_from_file::h18d39f10bbdb16322EV
   5:           0x42169f - format::hdf0dc7f44e863157Kom
   6:           0x4223d0 - run::ha2489810762bf588Qpm
   7:           0x40842e - main::hdc3f62eb7f8632afwha
   8:           0x8d4488 - sys_common::unwind::try::try_fn::h4279873565337993947
   9:           0x8bf84f - sys_common::unwind::try::inner_try::h5376f22191deffccq1s
  10:           0x8d438d - rt::lang_start::h311db593fb8707c7yLy
  11:           0x4013b4 - _tmainCRTStartup
  12:           0x4014e7 - mainCRTStartup
  13:         0x77965a4c - je_arena_alloc_junk_small.part.25

Versions:

rustfmt -V: 0.2.1
rustc -V: rustc 1.7.0-nightly (d5e229057 2016-01-04)
cargo -V: cargo 0.8.0-nightly (08da2f5 2015-12-21)
On Windows 7 64 bit with msys2
@nrc nrc added bug Panic, non-idempotency, invalid code, etc. and removed bug Panic, non-idempotency, invalid code, etc. labels Jan 10, 2016
@nrc
Copy link
Member

nrc commented Jan 10, 2016

The Rust parser reports some errors by panicking, the Rust compiler has a panic catcher to prevent these appearing as panics to the user. We don't do that in rustfmt, so when there is a parsing error like this, rustfmt panics. We should fix this by adding a panic catcher around the parser (or wait for the parser to become non-panicking, which should happen eventually).

@nrc nrc changed the title Thread '<main>' panicked at 'Box<Any>' Catch panics in the parser Jan 10, 2016
@boobiesinc
Copy link

debug $ dd if=/dev/zero of=c bs=1 count=1
1+0 records in
1+0 records out
1 byte copied, 0.0001716 s, 5.8 kB/s
Press any key to continue...

debug $ RUST_BACKTRACE=1 ./rustfmt  c
c:1:1: 1:2 error: unknown start of token: \u{0}
c:1 
    ^
thread '<main>' panicked at 'Box<Any>', /home/censoredbyfbi/.cargo/registry/src/github.com-1ecc6299db9ec823/syntex_syntax-0.32.0/src/parse/lexer/mod.rs:199
stack backtrace:
   1:     0x55a87ad946f0 - std::sys::backtrace::tracing::imp::write::h82353b94d9957b5a
   2:     0x55a87ad9764b - std::panicking::default_hook::_$u7b$$u7b$closure$u7d$$u7d$::hd08c9fd28a21a931
   3:     0x55a87ad972d3 - std::panicking::default_hook::h9f5ce461fe95b992
   4:     0x55a87ad88d18 - std::panicking::rust_panic_with_hook::hfb9137c9fa89bbb0
   5:     0x55a87ab0e796 - std::panicking::begin_panic::h68586c3453bafff6
                        at src/libstd/panicking.rs:327
   6:     0x55a87ab8bb27 - syntex_syntax::parse::lexer::StringReader::new::h2c3a6ffb705c7baa
                        at /home/censoredbyfbi/build/censoredbyfbi/rustfmt/<std macros>:3
   7:     0x55a87ab8b529 - syntex_syntax::parse::filemap_to_tts::h64dc05b9ab861c82
                        at /home/censoredbyfbi/.cargo/registry/src/github.com-1ecc6299db9ec823/syntex_syntax-0.32.0/src/parse/mod.rs:254
   8:     0x55a87ab8a707 - syntex_syntax::parse::filemap_to_parser::h8960db47fe0329aa
                        at /home/censoredbyfbi/.cargo/registry/src/github.com-1ecc6299db9ec823/syntex_syntax-0.32.0/src/parse/mod.rs:212
   9:     0x55a87ab868f9 - syntex_syntax::parse::new_parser_from_file::h9f65919cff698456
                        at /home/censoredbyfbi/.cargo/registry/src/github.com-1ecc6299db9ec823/syntex_syntax-0.32.0/src/parse/mod.rs:189
  10:     0x55a87ab8678c - syntex_syntax::parse::parse_crate_from_file::hdfa93fc2ba898f92
                        at /home/censoredbyfbi/.cargo/registry/src/github.com-1ecc6299db9ec823/syntex_syntax-0.32.0/src/parse/mod.rs:77
  11:     0x55a87a80f85a - rustfmt::parse_input::h35adeee7f5f2dbec
                        at src/lib.rs:389
  12:     0x55a87a81d373 - rustfmt::format_input::h5152d86c8e0e887d
                        at src/lib.rs:424
  13:     0x55a87a81a520 - rustfmt::run::hc3c3f45cca8c2090
                        at src/lib.rs:480
  14:     0x55a87a7eabdd - rustfmt::execute::h1567d35cf029b277
                        at src/bin/rustfmt.rs:231
  15:     0x55a87a7fa17f - rustfmt::main::h72bee7f7a14fa8c0
                        at src/bin/rustfmt.rs:243
  16:     0x55a87ad96f18 - std::panicking::try::call::h707222b2d912b2ed
  17:     0x55a87ada190b - __rust_try
  18:     0x55a87ada18ae - __rust_maybe_catch_panic
  19:     0x55a87ad96943 - std::rt::lang_start::h801b666f82634252
  20:     0x55a87a7fd169 - main
  21:     0x7f9ee390570f - __libc_start_main
  22:     0x55a87a7e3aa8 - _start
  23:                0x0 - <unknown>

@topecongiro
Copy link
Contributor

topecongiro commented May 28, 2017

Closing since this is not reproduced on the current master.
Actually, rustfmt still panics on some invalid code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

No branches or pull requests

4 participants