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

rustfmt crashes with bad span error #4517

Closed
brmmm3 opened this issue Nov 8, 2020 · 6 comments
Closed

rustfmt crashes with bad span error #4517

brmmm3 opened this issue Nov 8, 2020 · 6 comments
Labels
bug Panic, non-idempotency, invalid code, etc.

Comments

@brmmm3
Copy link

brmmm3 commented Nov 8, 2020

rustfmt (nightly on Linux) crashes with error code -32900.

It is correct that it recognizes the unclosed delimiter, but I would expect a simple error message instead of a crash.

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (ffa2e7ae8 2020-10-24)
binary: rustc
commit-hash: ffa2e7ae8fbf9badc035740db949b9dae271c29f
commit-date: 2020-10-24
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly
LLVM version: 11.0
Backtrace

error: this file contains an unclosed delimiter
   --> <stdin>:434:3
    |
141 | pub fn add_to_archive(context: &Context) -> Result<(), Error> {
    |                                                               - unclosed delimiter
...
168 |         if let Err(err) = compressor.create_add_new_files(&context) {
    |                                                                     - this delimiter might not be properly closed...
...
173 |     }
    |     - ...as it matches this but it has different indentation
...
434 | }
    |   ^

error: this file contains an unclosed delimiter
   --> <stdin>:438:3
    |
141 | pub fn add_to_archive(context: &Context) -> Result<(), Error> {
    |                                                               - unclosed delimiter
...
168 |         match compressor.create_add_new_files(&context) {
    |                                                         - this delimiter might not be properly closed...
...
186 |     }
    |     - ...as it matches this but it has different indentation
...
438 | }
    |   ^

thread 'main' panicked at 'bad span: `.`: ``', src/tools/rustfmt/src/source_map.rs:52:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/panicking.rs:483:5
   1: std::panicking::begin_panic_fmt
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/panicking.rs:437:5
   2: <rustfmt_nightly::visitor::SnippetProvider as rustfmt_nightly::source_map::SpanUtils>::span_before::{{closure}}
   3: rustfmt_nightly::chains::rewrite_chain
   4: rustfmt_nightly::expr::format_expr
   5: rustfmt_nightly::expr::format_expr
   6: <rustfmt_nightly::chains::ChainItem as rustfmt_nightly::rewrite::Rewrite>::rewrite
   7: <rustfmt_nightly::chains::ChainFormatterBlock as rustfmt_nightly::chains::ChainFormatter>::format_root
   8: <rustfmt_nightly::chains::Chain as rustfmt_nightly::rewrite::Rewrite>::rewrite
   9: rustfmt_nightly::chains::rewrite_chain
  10: rustfmt_nightly::expr::format_expr
  11: rustfmt_nightly::closures::rewrite_closure_expr
  12: rustfmt_nightly::closures::rewrite_closure
  13: rustfmt_nightly::expr::format_expr
  14: rustfmt_nightly::closures::rewrite_last_closure
  15: rustfmt_nightly::overflow::Context::rewrite_items
  16: rustfmt_nightly::overflow::Context::rewrite
  17: rustfmt_nightly::expr::rewrite_call
  18: <rustfmt_nightly::chains::ChainItem as rustfmt_nightly::rewrite::Rewrite>::rewrite
  19: rustfmt_nightly::chains::ChainFormatterShared::format_last_child
  20: <rustfmt_nightly::chains::ChainFormatterBlock as rustfmt_nightly::chains::ChainFormatter>::format_last_child
  21: <rustfmt_nightly::chains::Chain as rustfmt_nightly::rewrite::Rewrite>::rewrite
  22: rustfmt_nightly::chains::rewrite_chain
  23: rustfmt_nightly::expr::format_expr
  24: rustfmt_nightly::stmt::format_stmt
  25: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  26: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  27: rustfmt_nightly::visitor::FmtVisitor::visit_block
  28: rustfmt_nightly::expr::rewrite_block_with_visitor
  29: <rustfmt_nightly::expr::ControlFlow as rustfmt_nightly::rewrite::Rewrite>::rewrite
  30: rustfmt_nightly::expr::format_expr
  31: rustfmt_nightly::stmt::format_stmt
  32: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  33: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  34: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  35: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  36: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  37: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  38: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  39: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  40: rustfmt_nightly::visitor::FmtVisitor::visit_block
  41: rustfmt_nightly::visitor::FmtVisitor::visit_fn
  42: rustfmt_nightly::visitor::FmtVisitor::visit_impl_item
  43: rustfmt_nightly::items::<impl rustfmt_nightly::visitor::FmtVisitor>::visit_impl_items
  44: rustfmt_nightly::items::format_impl
  45: rustfmt_nightly::visitor::FmtVisitor::visit_item
  46: rustfmt_nightly::reorder::<impl rustfmt_nightly::visitor::FmtVisitor>::visit_items_with_reordering
  47: rustfmt_nightly::visitor::FmtVisitor::format_separate_mod
  48: rustfmt_nightly::formatting::format_project
  49: scoped_tls::ScopedKey<T>::set
  50: rustfmt_nightly::Session<T>::format
  51: rustfmt::format_and_emit_report
  52: rustfmt::execute
  53: rustfmt::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 08:37:07] Request textDocument/formatting failed.
  Message: rustfmt exited with:
                           Status: exit code: 101
                           stdout: 
  Code: -32900 
thread 'main' panicked at 'bad span: `.`: ``', src/tools/rustfmt/src/source_map.rs:52:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/panicking.rs:483:5
   1: std::panicking::begin_panic_fmt
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/panicking.rs:437:5
   2: <rustfmt_nightly::visitor::SnippetProvider as rustfmt_nightly::source_map::SpanUtils>::span_before::{{closure}}
   3: rustfmt_nightly::chains::rewrite_chain
   4: rustfmt_nightly::expr::format_expr
   5: rustfmt_nightly::expr::format_expr
   6: <rustfmt_nightly::chains::ChainItem as rustfmt_nightly::rewrite::Rewrite>::rewrite
   7: <rustfmt_nightly::chains::ChainFormatterBlock as rustfmt_nightly::chains::ChainFormatter>::format_root
   8: <rustfmt_nightly::chains::Chain as rustfmt_nightly::rewrite::Rewrite>::rewrite
   9: rustfmt_nightly::chains::rewrite_chain
  10: rustfmt_nightly::expr::format_expr
  11: rustfmt_nightly::closures::rewrite_closure_expr
  12: rustfmt_nightly::closures::rewrite_closure
  13: rustfmt_nightly::expr::format_expr
  14: rustfmt_nightly::closures::rewrite_last_closure
  15: rustfmt_nightly::overflow::Context::rewrite_items
  16: rustfmt_nightly::overflow::Context::rewrite
  17: rustfmt_nightly::expr::rewrite_call
  18: <rustfmt_nightly::chains::ChainItem as rustfmt_nightly::rewrite::Rewrite>::rewrite
  19: rustfmt_nightly::chains::ChainFormatterShared::format_last_child
  20: <rustfmt_nightly::chains::ChainFormatterBlock as rustfmt_nightly::chains::ChainFormatter>::format_last_child
  21: <rustfmt_nightly::chains::Chain as rustfmt_nightly::rewrite::Rewrite>::rewrite
  22: rustfmt_nightly::chains::rewrite_chain
  23: rustfmt_nightly::expr::format_expr
  24: rustfmt_nightly::stmt::format_stmt
  25: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  26: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  27: rustfmt_nightly::visitor::FmtVisitor::visit_block
  28: rustfmt_nightly::expr::rewrite_block_with_visitor
  29: <rustfmt_nightly::expr::ControlFlow as rustfmt_nightly::rewrite::Rewrite>::rewrite
  30: rustfmt_nightly::expr::format_expr
  31: rustfmt_nightly::stmt::format_stmt
  32: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  33: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  34: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  35: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  36: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  37: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  38: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  39: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  40: rustfmt_nightly::visitor::FmtVisitor::visit_block
  41: rustfmt_nightly::visitor::FmtVisitor::visit_fn
  42: rustfmt_nightly::visitor::FmtVisitor::visit_impl_item
  43: rustfmt_nightly::items::<impl rustfmt_nightly::visitor::FmtVisitor>::visit_impl_items
  44: rustfmt_nightly::items::format_impl
  45: rustfmt_nightly::visitor::FmtVisitor::visit_item
  46: rustfmt_nightly::reorder::<impl rustfmt_nightly::visitor::FmtVisitor>::visit_items_with_reordering
  47: rustfmt_nightly::visitor::FmtVisitor::format_separate_mod
  48: rustfmt_nightly::formatting::format_project
  49: scoped_tls::ScopedKey<T>::set
  50: rustfmt_nightly::Session<T>::format
  51: rustfmt::format_and_emit_report
  52: rustfmt::execute
  53: rustfmt::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
[Error - 08:37:22] Request textDocument/formatting failed.
  Message: rustfmt exited with:
                           Status: exit code: 101
                           stdout: 
  Code: -32900 

@brmmm3 brmmm3 added the bug Panic, non-idempotency, invalid code, etc. label Nov 8, 2020
@calebcartwright
Copy link
Member

Could you please provide the rustfmt version (not the rustc version) as well as a snippet that can be used to reproduce?

@brmmm3
Copy link
Author

brmmm3 commented Nov 8, 2020

rustfmt 1.4.22-nightly (97d0301 2020-10-04)

@jyn514
Copy link
Member

jyn514 commented Nov 8, 2020

Originally reported at rust-lang/rust#78872.

btw @brmmm3 you still haven't added a code that causes the crash, that would be helpful for finding the cause of the bug.

@brmmm3
Copy link
Author

brmmm3 commented Nov 8, 2020

I know. The code I'm working on is rather big. So I have to create a small snipped which reproduces the bug.

@calebcartwright
Copy link
Member

I'm guessing that you have nested tuple access in there @brmmm3 and that this is likely another duplicate of #4355 (which is resolved in the next nightly btw), but without a full snippet hard to say that definitively.

The unclosed delimiter error is emitted by the rustc parser and is unrelated to the span panic that occurs later during formatting. Also worth noting that newer versions of rustfmt have been fixed to exit early in such cases, see v1.4.23 release notes.

If it's easier than boiling down to a small snippet, you could just grab the linux binaries from our latest v1.4.24 release and run against your existing code to see if that resolves your issue. This will be the included rustfmt version in the next nightly, so tomorrow you should be able to just update to the latest nightly.

@calebcartwright
Copy link
Member

@brmmm3 - going to close because best I can tell from the provided info, the span error is a duplicate of a fixed issue. If you're able to reproduce with rustfmt v1.4.23 or newer then feel free to re-open with relevant reproduction info

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

3 participants