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

Crashes when formatting tuple heavy code example #4486

Closed
drbartling opened this issue Oct 22, 2020 · 3 comments
Closed

Crashes when formatting tuple heavy code example #4486

drbartling opened this issue Oct 22, 2020 · 3 comments
Labels
bug Panic, non-idempotency, invalid code, etc. duplicate

Comments

@drbartling
Copy link

drbartling commented Oct 22, 2020

Describe the bug

Rustfmt crashes on the following code example. I had it saved to edge.rs This code compiles fine. No promises on the accuracy of edge the logic, though ;)

To Reproduce

Run rustfmt on this code sample:

e1: ((f64, f64), (f64, f64)),
e2: ((f64, f64), (f64, f64)),
) -> bool {
let slope_1 = (e1.1.1 - e1.0.1) / (e1.1.0 - e1.0.0);
let slope_2 = (e2.1.1 - e2.0.1) / (e2.1.0 - e2.0.0);
slope_1 != slope_2
}

Expected behavior

thread 'main' panicked at 'bad span: `.`: ``', src/tools/rustfmt/src/source_map.rs:52:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39/library/std/src/panicking.rs:475
   1: std::panicking::begin_panic_fmt
             at /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39/library/std/src/panicking.rs:429
   2: <rustfmt_nightly::visitor::SnippetProvider as rustfmt_nightly::source_map::SpanUtils>::span_before::{{closure}}
   3: <rustfmt_nightly::visitor::SnippetProvider as rustfmt_nightly::source_map::SpanUtils>::span_before
   4: rustfmt_nightly::chains::rewrite_chain
   5: rustfmt_nightly::expr::format_expr
   6: <rustc_ap_rustc_ast::ast::Expr as rustfmt_nightly::pairs::FlattenPair>::flatten
   7: rustfmt_nightly::pairs::rewrite_all_pairs
   8: rustfmt_nightly::expr::format_expr
   9: rustfmt_nightly::expr::format_expr
  10: <rustc_ap_rustc_ast::ast::Expr as rustfmt_nightly::pairs::FlattenPair>::flatten
  11: rustfmt_nightly::pairs::rewrite_all_pairs
  12: rustfmt_nightly::expr::format_expr
  13: rustfmt_nightly::expr::rewrite_assign_rhs_with
  14: rustfmt_nightly::items::<impl rustfmt_nightly::rewrite::Rewrite for rustc_ap_rustc_ast::ast::Local>::rewrite
  15: rustfmt_nightly::stmt::format_stmt
  16: rustfmt_nightly::visitor::FmtVisitor::walk_stmts
  17: rustfmt_nightly::visitor::FmtVisitor::visit_block
  18: rustfmt_nightly::visitor::FmtVisitor::visit_fn
  19: rustfmt_nightly::visitor::FmtVisitor::visit_item
  20: rustfmt_nightly::reorder::<impl rustfmt_nightly::visitor::FmtVisitor>::visit_items_with_reordering
  21: rustfmt_nightly::visitor::FmtVisitor::format_separate_mod
  22: rustfmt_nightly::formatting::format_project
  23: scoped_tls::ScopedKey<T>::set
  24: rustc_ap_rustc_ast::attr::with_session_globals
  25: rustfmt_nightly::Session<T>::format
  26: rustfmt::format_and_emit_report
  27: rustfmt_nightly::Session<T>::override_config
  28: rustfmt::execute
  29: rustfmt::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Meta

  • rustfmt version: rustfmt 1.4.20-stable (48f6c32 2020-08-09)
  • From where did you install rustfmt?: rustup component add rustfmt
  • How do you run rustfmt: cargo fmt
@drbartling drbartling added the bug Panic, non-idempotency, invalid code, etc. label Oct 22, 2020
@swooster
Copy link

swooster commented Oct 22, 2020

I've encountered the same issue. An even smaller reproducible test-case is:

fn foo(x: ((u32,),)) {
    x.0.0;
}

Changing x.0.0 to (x.0).0 avoids the crash.

@calebcartwright
Copy link
Member

Duplicate of #4355, resolved in the upcoming 1.4.23 release

@drbartling
Copy link
Author

I've encountered the same issue. An even smaller reproducible test-case is:

fn foo(x: ((u32,),)) {
    x.0.0;
}

Changing x.0.0 to (x.0).0 avoids the crash.

Thanks for the work-around :)

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