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 on macro input containing function signature #4101

Closed
dtolnay opened this issue Mar 28, 2020 · 1 comment
Closed

Crashes on macro input containing function signature #4101

dtolnay opened this issue Mar 28, 2020 · 1 comment

Comments

@dtolnay
Copy link
Member

dtolnay commented Mar 28, 2020

Minimal case:

m![fn f();];

I started hitting this in syn/tests/test_receiver.rs@189aea8 which hasn't been touched since October, so I guess this is a regression.

To reproduce against the current master branch of rustfmt (9124dd8):

$ echo 'm![fn f();];' | RUST_BACKTRACE=1 cargo +nightly-2020-03-22 run --bin rustfmt

thread 'main' panicked at 'internal error: entered unreachable code', rustfmt-core/rustfmt-lib/src/visitor.rs:367:18
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.45/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.45/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1427
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:511
  11: std::panicking::begin_panic
             at /rustc/38114ff16e7856f98b2b4be7ab4cd29b38bed59a/src/libstd/panicking.rs:438
  12: rustfmt_lib::visitor::FmtVisitor::visit_fn
             at rustfmt-core/rustfmt-lib/src/visitor.rs:367
  13: rustfmt_lib::visitor::FmtVisitor::visit_item
             at rustfmt-core/rustfmt-lib/src/visitor.rs:511
  14: rustfmt_lib::macros::rewrite_macro_with_items
             at rustfmt-core/rustfmt-lib/src/macros.rs:1537
  15: rustfmt_lib::macros::rewrite_macro_inner
             at rustfmt-core/rustfmt-lib/src/macros.rs:346
  16: rustfmt_lib::macros::rewrite_macro::{{closure}}
             at rustfmt-core/rustfmt-lib/src/macros.rs:204
  17: core::ops::function::FnOnce::call_once
             at /rustc/38114ff16e7856f98b2b4be7ab4cd29b38bed59a/src/libcore/ops/function.rs:232
  18: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/38114ff16e7856f98b2b4be7ab4cd29b38bed59a/src/libstd/panic.rs:318
  19: std::panicking::try::do_call
             at /rustc/38114ff16e7856f98b2b4be7ab4cd29b38bed59a/src/libstd/panicking.rs:331
  20: __rust_try
  21: std::panicking::try
             at /rustc/38114ff16e7856f98b2b4be7ab4cd29b38bed59a/src/libstd/panicking.rs:274
  22: std::panic::catch_unwind
             at /rustc/38114ff16e7856f98b2b4be7ab4cd29b38bed59a/src/libstd/panic.rs:394
  23: rustfmt_lib::macros::rewrite_macro
             at rustfmt-core/rustfmt-lib/src/macros.rs:203
  24: rustfmt_lib::visitor::FmtVisitor::visit_mac::{{closure}}
             at rustfmt-core/rustfmt-lib/src/visitor.rs:682
  25: rustfmt_lib::visitor::FmtVisitor::with_context
             at rustfmt-core/rustfmt-lib/src/visitor.rs:955
  26: rustfmt_lib::visitor::FmtVisitor::visit_mac
             at rustfmt-core/rustfmt-lib/src/visitor.rs:682
  27: rustfmt_lib::visitor::FmtVisitor::visit_item
             at rustfmt-core/rustfmt-lib/src/visitor.rs:496
  28: rustfmt_lib::reorder::<impl rustfmt_lib::visitor::FmtVisitor>::visit_items_with_reordering
             at rustfmt-core/rustfmt-lib/src/reorder.rs:261
  29: rustfmt_lib::visitor::FmtVisitor::walk_mod_items
             at rustfmt-core/rustfmt-lib/src/visitor.rs:854
  30: rustfmt_lib::visitor::FmtVisitor::format_separate_mod
             at rustfmt-core/rustfmt-lib/src/visitor.rs:931
  31: rustfmt_lib::formatting::FormatContext<T>::format_file
             at ./rustfmt-core/rustfmt-lib/src/formatting.rs:182
  32: rustfmt_lib::formatting::format_project
             at ./rustfmt-core/rustfmt-lib/src/formatting.rs:109
  33: rustfmt_lib::formatting::<impl rustfmt_lib::Session<T>>::format_input_inner::{{closure}}
             at ./rustfmt-core/rustfmt-lib/src/formatting.rs:44
  34: scoped_tls::ScopedKey<T>::set
             at /home/david/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  35: rustc_ap_syntax::attr::with_globals::{{closure}}
             at /home/david/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-ap-syntax-642.0.0/attr/mod.rs:44
  36: scoped_tls::ScopedKey<T>::set
             at /home/david/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  37: rustc_ap_syntax::attr::with_globals
             at /home/david/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-ap-syntax-642.0.0/attr/mod.rs:44
  38: rustfmt_lib::formatting::<impl rustfmt_lib::Session<T>>::format_input_inner
             at ./rustfmt-core/rustfmt-lib/src/formatting.rs:32
  39: rustfmt_lib::Session<T>::format
             at ./rustfmt-core/rustfmt-lib/src/lib.rs:426
  40: rustfmt::format_and_emit_report
             at rustfmt-core/rustfmt-bin/src/bin/main.rs:530
  41: rustfmt::format_string
             at rustfmt-core/rustfmt-bin/src/bin/main.rs:415
  42: rustfmt::format
             at rustfmt-core/rustfmt-bin/src/bin/main.rs:472
  43: rustfmt::execute
             at rustfmt-core/rustfmt-bin/src/bin/main.rs:364
  44: rustfmt::main
             at rustfmt-core/rustfmt-bin/src/bin/main.rs:25
  45: std::rt::lang_start::{{closure}}
             at /rustc/38114ff16e7856f98b2b4be7ab4cd29b38bed59a/src/libstd/rt.rs:67
  46: std::rt::lang_start_internal::{{closure}}
             at src/libstd/rt.rs:52
  47: std::panicking::try::do_call
             at src/libstd/panicking.rs:331
  48: std::panicking::try
             at src/libstd/panicking.rs:274
  49: std::panic::catch_unwind
             at src/libstd/panic.rs:394
  50: std::rt::lang_start_internal
             at src/libstd/rt.rs:51
  51: std::rt::lang_start
             at /rustc/38114ff16e7856f98b2b4be7ab4cd29b38bed59a/src/libstd/rt.rs:67
  52: main
  53: __libc_start_main
  54: _start
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
@calebcartwright
Copy link
Member

Different input, but same underlying issue as #4068 and #4077.

This has been fixed and will be included in the next release of rustfmt via #4100 and resolved on master once #4069 is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants