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

Panic when formatting #4479

Closed
ndmitchell opened this issue Oct 20, 2020 · 2 comments
Closed

Panic when formatting #4479

ndmitchell opened this issue Oct 20, 2020 · 2 comments
Labels
bug Panic, non-idempotency, invalid code, etc. duplicate

Comments

@ndmitchell
Copy link

Describe the bug

Given:

fn get_hashes() { x. 0. 0 }

I get:

thread 'main' panicked at 'bad span: `.`: ` 0`', src/tools/rustfmt/src/source_map.rs:52:13

To Reproduce

$ rustfmt test.rs
thread 'main' panicked at 'bad span: `.`: ` 0`', src/tools/rustfmt/src/source_map.rs:52:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected behavior

Not panic.

Meta

  • rustfmt version: rustfmt 1.4.22-nightly (97d03010 2020-10-04)
  • From where did you install rustfmt?: rustup
  • How do you run rustfmt: rustfmt
@ndmitchell ndmitchell added the bug Panic, non-idempotency, invalid code, etc. label Oct 20, 2020
@zgotsch
Copy link

zgotsch commented Oct 20, 2020

I am also getting this error. Interestingly, the message is a bit different (and less helpful!) without the spaces before the 0s:

Input:

fn get_hashes() { x.0.0 }

Output:

thread 'main' panicked at 'bad span: `.`: ``', src/tools/rustfmt/src/source_map.rs:52:13
stack backtrace:
   0: _rust_begin_unwind
   1: std::panicking::begin_panic_fmt
   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::stmt::format_stmt
   6: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
   7: rustfmt_nightly::visitor::FmtVisitor::visit_block
   8: rustfmt_nightly::visitor::FmtVisitor::visit_fn
   9: rustfmt_nightly::visitor::FmtVisitor::visit_item
  10: rustfmt_nightly::reorder::<impl rustfmt_nightly::visitor::FmtVisitor>::visit_items_with_reordering
  11: rustfmt_nightly::visitor::FmtVisitor::format_separate_mod
  12: rustfmt_nightly::formatting::format_project
  13: scoped_tls::ScopedKey<T>::set
  14: rustfmt_nightly::Session<T>::format
  15: rustfmt::format_and_emit_report
  16: rustfmt_nightly::Session<T>::override_config
  17: rustfmt::execute
  18: rustfmt::main

@calebcartwright
Copy link
Member

calebcartwright commented Oct 20, 2020

Duplicate of #4355, resolved in the upcoming 1.4.23 release

edit - typo fix

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. duplicate
Projects
None yet
Development

No branches or pull requests

3 participants