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 panics when formatting #4539

Closed
svalaskevicius opened this issue Nov 20, 2020 · 5 comments
Closed

rustfmt panics when formatting #4539

svalaskevicius opened this issue Nov 20, 2020 · 5 comments
Labels
bug Panic, non-idempotency, invalid code, etc.

Comments

@svalaskevicius
Copy link

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
@svalaskevicius svalaskevicius added the bug Panic, non-idempotency, invalid code, etc. label Nov 20, 2020
@taiki-e
Copy link
Member

taiki-e commented Nov 20, 2020

I think this is a duplicate of #4355 and fixed in the latest nightly.

@svalaskevicius
Copy link
Author

you're right! rustup update fixed things. sorry for not doing that before raising the ticket :)

@svalaskevicius
Copy link
Author

(btw it does add the strange space now but ... .not a problem for me x.1 .0 == t.dimension)

@taiki-e
Copy link
Member

taiki-e commented Nov 20, 2020

(btw it does add the strange space now but ... .not a problem for me x.1 .0 == t.dimension)

See #4355 (comment)

However, please note that for historical reasons (that predate the semi-recent rustc changes) rustfmt formats these with a space inserted to prevent syntax errors (#1063). Due to rustfmt's stability guarantee, we cannot change that default behavior as it would break existing formatting. If you find that space to be problematic, then you can opt into the v2 formatting by adding version = "Two" to the rustfmt config file or use the work around with ()

@svalaskevicius
Copy link
Author

right, thanks again :)

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

2 participants