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

format_code_in_doc_comments causes panic for empty code blocks. #5234

Closed
andrewgazelka opened this issue Feb 22, 2022 · 1 comment · Fixed by #5601
Closed

format_code_in_doc_comments causes panic for empty code blocks. #5234

andrewgazelka opened this issue Feb 22, 2022 · 1 comment · Fixed by #5601
Labels
a-comments bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce p-medium

Comments

@andrewgazelka
Copy link

format_code_in_doc_comments causes panic for empty code blocks. For instance:

/// This breaks rustfmt
/// ```
///
/// ```
fn tester() {}

Reproducing

thread 'main' panicked at 'begin <= end (12 <= 11) when slicing `fn main() {}
`', src/tools/rustfmt/src/lib.rs:399:47
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::str::slice_error_fail
   3: rustfmt_nightly::format_code_block
   4: rustfmt_nightly::comment::rewrite_comment_inner
   5: rustfmt_nightly::comment::identify_comment
   6: rustfmt_nightly::attr::rewrite_initial_doc_comments
   7: <[rustc_ast::ast::Attribute] as rustfmt_nightly::rewrite::Rewrite>::rewrite
   8: <rustfmt_nightly::visitor::FmtVisitor>::visit_attrs
   9: <rustfmt_nightly::visitor::FmtVisitor>::visit_item
  10: <rustfmt_nightly::visitor::FmtVisitor>::visit_items_with_reordering
  11: <rustfmt_nightly::visitor::FmtVisitor>::format_separate_mod
  12: rustfmt_nightly::formatting::format_project::<rustfmt_nightly::Session<std::io::stdio::Stdout>>
  13: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::with::<<rustfmt_nightly::Session<std::io::stdio::Stdout>>::format_input_inner::{closure#0}, core::result::Result<rustfmt_nightly::FormatReport, rustfmt_nightly::ErrorKind>>
  14: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_span::create_session_if_not_set_then<core::result::Result<rustfmt_nightly::FormatReport, rustfmt_nightly::ErrorKind>, <rustfmt_nightly::Session<std::io::stdio::Stdout>>::format_input_inner::{closure#0}>::{closure#0}, core::result::Result<rustfmt_nightly::FormatReport, rustfmt_nightly::ErrorKind>>
  15: <rustfmt_nightly::Session<std::io::stdio::Stdout>>::format
  16: rustfmt::format_and_emit_report::<std::io::stdio::Stdout>
  17: <rustfmt_nightly::Session<std::io::stdio::Stdout>>::override_config::<rustfmt::format::{closure#0}, ()>
  18: rustfmt::execute
  19: rustfmt::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Related

andrewgazelka added a commit to andrewgazelka/rustfmt that referenced this issue Feb 22, 2022
@ytmimi ytmimi added a-comments bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce labels Feb 23, 2022
@ytmimi
Copy link
Contributor

ytmimi commented Jul 27, 2022

linking tracking issue for format_code_in_doc_comments #3348

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-comments bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce p-medium
Projects
None yet
2 participants