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

'internal error: entered unreachable code' when formatting doc comment #4077

Closed
Aaron1011 opened this issue Mar 9, 2020 · 2 comments
Closed
Labels
bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce

Comments

@Aaron1011
Copy link
Member

The following code:

/// ```
/// # #[rustversion::since(1.36)]
/// # fn dox() {
/// # use std::pin::Pin;
/// # type Projection<'a> = &'a ();
/// # type ProjectionRef<'a> = &'a ();
/// # trait Dox {
/// fn project_ex(self: Pin<&mut Self>) -> Projection<'_>;
/// fn project_ref(self: Pin<&Self>) -> ProjectionRef<'_>;
/// # }
/// # }
/// ```
struct Foo;

produces the following error when formatted with rustfmt:

thread 'main' panicked at 'internal error: entered unreachable code', rustfmt-core/rustfmt-lib/src/visitor.rs:368:18
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/git.luolix.top-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/git.luolix.top-1ecc6299db9ec823/backtrace-0.3.44/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:1063
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1428
   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:204
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:224
  10: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:470
  11: std::panicking::begin_panic
             at /rustc/564758c4c329e89722454dd2fbb35f1ac0b8b47c/src/libstd/panicking.rs:397
  12: rustfmt_lib::visitor::FmtVisitor::visit_fn
             at rustfmt-core/rustfmt-lib/src/visitor.rs:368
  13: rustfmt_lib::visitor::FmtVisitor::visit_item
             at rustfmt-core/rustfmt-lib/src/visitor.rs:513
  14: rustfmt_lib::visitor::FmtVisitor::visit_stmt
             at rustfmt-core/rustfmt-lib/src/visitor.rs:132
  15: rustfmt_lib::visitor::FmtVisitor::walk_stmts
             at rustfmt-core/rustfmt-lib/src/visitor.rs:872
  16: rustfmt_lib::visitor::FmtVisitor::walk_block_stmts
             at rustfmt-core/rustfmt-lib/src/visitor.rs:881
  17: rustfmt_lib::visitor::FmtVisitor::visit_block
             at rustfmt-core/rustfmt-lib/src/visitor.rs:218
  18: rustfmt_lib::visitor::FmtVisitor::visit_fn
             at rustfmt-core/rustfmt-lib/src/visitor.rs:393
  19: rustfmt_lib::visitor::FmtVisitor::visit_item
             at rustfmt-core/rustfmt-lib/src/visitor.rs:513
  20: rustfmt_lib::reorder::<impl rustfmt_lib::visitor::FmtVisitor>::visit_items_with_reordering
             at rustfmt-core/rustfmt-lib/src/reorder.rs:261
  21: rustfmt_lib::visitor::FmtVisitor::walk_mod_items
             at rustfmt-core/rustfmt-lib/src/visitor.rs:856
  22: rustfmt_lib::visitor::FmtVisitor::format_separate_mod
             at rustfmt-core/rustfmt-lib/src/visitor.rs:933
  23: rustfmt_lib::formatting::FormatContext<T>::format_file
             at rustfmt-core/rustfmt-lib/src/formatting.rs:182
  24: rustfmt_lib::formatting::format_project
             at rustfmt-core/rustfmt-lib/src/formatting.rs:109
  25: rustfmt_lib::formatting::<impl rustfmt_lib::Session<T>>::format_input_inner::{{closure}}
             at rustfmt-core/rustfmt-lib/src/formatting.rs:44
  26: scoped_tls::ScopedKey<T>::set
             at /home/aaron/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  27: rustc_ap_syntax::attr::with_globals::{{closure}}
             at /home/aaron/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/rustc-ap-syntax-642.0.0/attr/mod.rs:44
  28: scoped_tls::ScopedKey<T>::set
             at /home/aaron/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  29: rustc_ap_syntax::attr::with_globals
             at /home/aaron/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/rustc-ap-syntax-642.0.0/attr/mod.rs:44
  30: rustfmt_lib::formatting::<impl rustfmt_lib::Session<T>>::format_input_inner
             at rustfmt-core/rustfmt-lib/src/formatting.rs:32
  31: rustfmt_lib::Session<T>::format
             at rustfmt-core/rustfmt-lib/src/lib.rs:426
  32: rustfmt_lib::format_snippet::{{closure}}
             at rustfmt-core/rustfmt-lib/src/lib.rs:288
  33: std::panicking::try::do_call
             at /rustc/564758c4c329e89722454dd2fbb35f1ac0b8b47c/src/libstd/panicking.rs:303
  34: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:86
  35: std::panicking::try
             at /rustc/564758c4c329e89722454dd2fbb35f1ac0b8b47c/src/libstd/panicking.rs:281
  36: std::panic::catch_unwind
             at /rustc/564758c4c329e89722454dd2fbb35f1ac0b8b47c/src/libstd/panic.rs:394
  37: rustfmt_lib::format_snippet
             at rustfmt-core/rustfmt-lib/src/lib.rs:279
  38: rustfmt_lib::format_code_block
             at rustfmt-core/rustfmt-lib/src/lib.rs:347
  39: rustfmt_lib::comment::CommentRewrite::handle_line
             at rustfmt-core/rustfmt-lib/src/comment.rs:662
  40: rustfmt_lib::comment::rewrite_comment_inner
             at rustfmt-core/rustfmt-lib/src/comment.rs:816
  41: rustfmt_lib::comment::identify_comment
             at rustfmt-core/rustfmt-lib/src/comment.rs:361
  42: rustfmt_lib::comment::rewrite_doc_comment
             at rustfmt-core/rustfmt-lib/src/comment.rs:244
  43: rustfmt_lib::attr::rewrite_initial_doc_comments
             at rustfmt-core/rustfmt-lib/src/attr.rs:179
  44: rustfmt_lib::attr::<impl rustfmt_lib::rewrite::Rewrite for [rustc_ap_syntax::ast::Attribute]>::rewrite
             at rustfmt-core/rustfmt-lib/src/attr.rs:385
  45: rustfmt_lib::visitor::FmtVisitor::visit_attrs
             at rustfmt-core/rustfmt-lib/src/visitor.rs:841
  46: rustfmt_lib::visitor::FmtVisitor::visit_item
             at rustfmt-core/rustfmt-lib/src/visitor.rs:420
  47: rustfmt_lib::reorder::<impl rustfmt_lib::visitor::FmtVisitor>::visit_items_with_reordering
             at rustfmt-core/rustfmt-lib/src/reorder.rs:261
  48: rustfmt_lib::visitor::FmtVisitor::walk_mod_items
             at rustfmt-core/rustfmt-lib/src/visitor.rs:856
  49: rustfmt_lib::visitor::FmtVisitor::format_separate_mod
             at rustfmt-core/rustfmt-lib/src/visitor.rs:933
  50: rustfmt_lib::formatting::FormatContext<T>::format_file
             at /home/aaron/repos/rustfmt/rustfmt-core/rustfmt-lib/src/formatting.rs:182
  51: rustfmt_lib::formatting::format_project
             at /home/aaron/repos/rustfmt/rustfmt-core/rustfmt-lib/src/formatting.rs:109
  52: rustfmt_lib::formatting::<impl rustfmt_lib::Session<T>>::format_input_inner::{{closure}}
             at /home/aaron/repos/rustfmt/rustfmt-core/rustfmt-lib/src/formatting.rs:44
  53: scoped_tls::ScopedKey<T>::set
             at /home/aaron/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  54: rustc_ap_syntax::attr::with_globals::{{closure}}
             at /home/aaron/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/rustc-ap-syntax-642.0.0/attr/mod.rs:44
  55: scoped_tls::ScopedKey<T>::set
             at /home/aaron/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137
  56: rustc_ap_syntax::attr::with_globals
             at /home/aaron/.cargo/registry/src/git.luolix.top-1ecc6299db9ec823/rustc-ap-syntax-642.0.0/attr/mod.rs:44
  57: rustfmt_lib::formatting::<impl rustfmt_lib::Session<T>>::format_input_inner
             at /home/aaron/repos/rustfmt/rustfmt-core/rustfmt-lib/src/formatting.rs:32
  58: rustfmt_lib::Session<T>::format
             at /home/aaron/repos/rustfmt/rustfmt-core/rustfmt-lib/src/lib.rs:426
  59: rustfmt::format_and_emit_report
             at rustfmt-core/rustfmt-bin/src/bin/main.rs:530
  60: rustfmt::format::{{closure}}
             at rustfmt-core/rustfmt-bin/src/bin/main.rs:511
  61: rustfmt_lib::Session<T>::override_config
             at /home/aaron/repos/rustfmt/rustfmt-core/rustfmt-lib/src/lib.rs:434
  62: rustfmt::format
             at rustfmt-core/rustfmt-bin/src/bin/main.rs:510
  63: rustfmt::execute
             at rustfmt-core/rustfmt-bin/src/bin/main.rs:364
  64: rustfmt::main
             at rustfmt-core/rustfmt-bin/src/bin/main.rs:25
  65: std::rt::lang_start::{{closure}}
             at /rustc/564758c4c329e89722454dd2fbb35f1ac0b8b47c/src/libstd/rt.rs:67
  66: std::rt::lang_start_internal::{{closure}}
             at src/libstd/rt.rs:52
  67: std::panicking::try::do_call
             at src/libstd/panicking.rs:303
  68: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:86
  69: std::panicking::try
             at src/libstd/panicking.rs:281
  70: std::panic::catch_unwind
             at src/libstd/panic.rs:394
  71: std::rt::lang_start_internal
             at src/libstd/rt.rs:51
  72: std::rt::lang_start
             at /rustc/564758c4c329e89722454dd2fbb35f1ac0b8b47c/src/libstd/rt.rs:67
  73: main
  74: __libc_start_main
  75: _start
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

The panic is caught, so rustfmt continues executing. However, it would be nice if rustfmt properly handled this kind of doc comment.

Found while working on taiki-e/pin-project#181

@calebcartwright
Copy link
Member

This is a different input (and an only-with-option type of issue with format_code_in_doc_comments config option) but same underlying cause as #4068 and this would also be resolved with #4069

@topecongiro topecongiro added bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce labels Mar 31, 2020
@topecongiro
Copy link
Contributor

Closed via #4069.

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. only-with-option requires a non-default option value to reproduce
Projects
None yet
Development

No branches or pull requests

3 participants