Skip to content

rustfmt panics when formatting #4539

Closed
Closed
@svalaskevicius

Description

@svalaskevicius

Describe the bug

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: <rustc_ap_rustc_ast::ast::Expr as rustfmt_nightly::pairs::FlattenPair>::flatten
   6: rustfmt_nightly::pairs::rewrite_all_pairs
   7: rustfmt_nightly::expr::format_expr
   8: rustfmt_nightly::closures::rewrite_closure_expr
   9: rustfmt_nightly::closures::rewrite_closure
  10: rustfmt_nightly::expr::format_expr
  11: rustfmt_nightly::closures::rewrite_last_closure
  12: rustfmt_nightly::overflow::Context::rewrite_items
  13: rustfmt_nightly::overflow::Context::rewrite
  14: rustfmt_nightly::expr::rewrite_call
  15: <rustfmt_nightly::chains::ChainItem as rustfmt_nightly::rewrite::Rewrite>::rewrite
  16: rustfmt_nightly::chains::ChainFormatterShared::format_last_child
  17: <rustfmt_nightly::chains::ChainFormatterBlock as rustfmt_nightly::chains::ChainFormatter>::format_last_child
  18: <rustfmt_nightly::chains::Chain as rustfmt_nightly::rewrite::Rewrite>::rewrite
  19: rustfmt_nightly::chains::rewrite_chain
  20: rustfmt_nightly::expr::format_expr

To Reproduce

if let Some(xxx) = yyy.iter().enumerate().find(|x| x.1.0 == t.aaa) {}

this works fine:

if let Some(xxx) = yyy.iter().enumerate().find(|x| { let x1 = x.1 ; x1.0 == t.aaa } ) {}

Expected behavior

no panic. formatted code

Meta

  • rustfmt version: rustfmt 1.4.22-nightly (97d0301 2020-10-04)
  • From where did you install rustfmt?: rustup, on nixos
  • How do you run rustfmt: rustfmt, and via vim

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPanic, non-idempotency, invalid code, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions