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

Rustdoc ICE when stripping doc comment decorations #47197

Closed
mystor opened this issue Jan 4, 2018 · 1 comment
Closed

Rustdoc ICE when stripping doc comment decorations #47197

mystor opened this issue Jan 4, 2018 · 1 comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@mystor
Copy link
Contributor

mystor commented Jan 4, 2018

/**
* a

* b
*/
pub fn x() { }

Running rustdoc on this causes an ICE.

quicksilver[Jan 04@15:31:19] rustdoc-test
$ RUST_BACKTRACE=1 cargo doc
 Documenting rustdoc-test v0.1.0 (file:///home/nika/Code/rustdoc-test)
error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https:/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.24.0-nightly (2dad872a2 2017-12-29) running on x86_64-unknown-linux-gnu

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'byte index 1 is out of bounds of ``', /checkout/src/libcore/str/mod.rs:2217:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at /checkout/src/libstd/sys_common/backtrace.rs:68
             at /checkout/src/libstd/sys_common/backtrace.rs:57
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/panicking.rs:381
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:391
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:577
   5: std::panicking::begin_panic
             at /checkout/src/libstd/panicking.rs:538
   6: std::panicking::begin_panic_fmt
             at /checkout/src/libstd/panicking.rs:522
   7: rust_begin_unwind
             at /checkout/src/libstd/panicking.rs:498
   8: core::panicking::panic_fmt
             at /checkout/src/libcore/panicking.rs:71
   9: core::str::slice_error_fail
             at /checkout/src/libcore/str/mod.rs:0
  10: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
  11: syntax::parse::lexer::comments::strip_doc_comment_decoration
  12: syntax::attr::<impl syntax::ast::Attribute>::with_desugared_doc
             at /checkout/src/libsyntax/attr.rs:373
  13: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
             at /checkout/src/librustdoc/clean/mod.rs:727
             at /checkout/src/libcore/iter/mod.rs:1497
             at /checkout/src/liballoc/vec.rs:1801
  14: rustdoc::clean::Attributes::from_ast
             at /checkout/src/liballoc/vec.rs:1713
             at /checkout/src/libcore/iter/iterator.rs:1298
             at /checkout/src/librustdoc/clean/mod.rs:726
  15: <rustdoc::doctree::Function as rustdoc::clean::Clean<rustdoc::clean::Item>>::clean
             at /checkout/src/librustdoc/clean/mod.rs:800
             at /checkout/src/librustdoc/clean/mod.rs:1357
  16: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::spec_extend
             at /checkout/src/librustdoc/clean/mod.rs:475
             at /checkout/src/libcore/ops/function.rs:271
             at /checkout/src/libcore/option.rs:404
             at /checkout/src/libcore/iter/mod.rs:1251
             at /checkout/src/liballoc/vec.rs:1844
  17: <rustdoc::doctree::Module as rustdoc::clean::Clean<rustdoc::clean::Item>>::clean
             at /checkout/src/liballoc/vec.rs:1782
             at /checkout/src/librustdoc/clean/mod.rs:475
  18: <rustdoc::visit_ast::RustdocVisitor<'a, 'tcx> as rustdoc::clean::Clean<rustdoc::clean::Crate>>::clean
             at /checkout/src/librustdoc/clean/mod.rs:148
  19: rustdoc::core::run_core::{{closure}}
             at /checkout/src/librustdoc/core.rs:218
  20: <std::thread::local::LocalKey<T>>::with
             at /checkout/src/librustc_driver/driver.rs:1101
             at /checkout/src/librustc/ty/context.rs:1573
             at /checkout/src/libstd/thread/local.rs:377
             at /checkout/src/libstd/thread/local.rs:288
  21: <std::thread::local::LocalKey<T>>::with
             at /checkout/src/librustc/ty/context.rs:1570
             at /checkout/src/librustc/ty/context.rs:1557
             at /checkout/src/libstd/thread/local.rs:377
             at /checkout/src/libstd/thread/local.rs:288
  22: rustc::ty::context::TyCtxt::create_and_enter
             at /checkout/src/librustc/ty/context.rs:1554
             at /checkout/src/librustc/ty/context.rs:1197
  23: rustc_driver::driver::phase_3_run_analysis_passes
             at /checkout/src/librustc_driver/driver.rs:1024
  24: rustdoc::core::run_core
             at /checkout/src/librustdoc/core.rs:180

error: Could not document `rustdoc-test`.

Caused by:
  process didn't exit successfully: `rustdoc --crate-name rustdoc_test src/lib.rs -o /home/nika/Code/rustdoc-test/target/doc -L dependency=/home/nika/Code/rustdoc-test/target/debug/deps` (exit code: 101)
@mystor
Copy link
Contributor Author

mystor commented Jan 4, 2018

cc @jrmuizel @QuietMisdreavus

@QuietMisdreavus QuietMisdreavus added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Jan 4, 2018
zackmdavis added a commit to zackmdavis/rust that referenced this issue Jan 6, 2018
This `horizontal_trim` function strips the leading whitespace from
doc-comments that have a left-asterisk-margin:

  /**
   * You know what I mean—
   *
   * comments like this!
   */

The index of the column of asterisks is `i`, and if trimming is deemed
possible, we slice each line from `i+1` to the end of the line. But if, in
particular, `i` was 0 _and_ there was an empty line (as in the example
given in the reporting issue), we ended up panicking trying to slice an
empty string from 0+1 (== 1).

Let's tighten our check to say that we can't trim when `i` is even the same
as the length of the line, not just when it's greater. (Any such cases
would panic trying to slice `line` from `line.len()+1`.)

Resolves rust-lang#47197.
kennytm added a commit to kennytm/rust that referenced this issue Jan 8, 2018
…blems_in_computer_science, r=QuietMisdreavus

fix the doc-comment-decoration-trimming edge-case rustdoc ICE

This `horizontal_trim` function strips the leading whitespace from
doc-comments that have a left-asterisk-margin:

```
  /**
   * You know what I mean—
   *
   * comments like this!
   */
```

The index of the column of asterisks is `i`, and if trimming is deemed
possible, we slice each line from `i+1` to the end of the line. But if, in
particular, `i` was 0 _and_ there was an empty line (as in the example
given in the reporting issue), we ended up panicking trying to slice an
empty string from 0+1 (== 1).

Let's tighten our check to say that we can't trim when `i` is even the same
as the length of the line, not just when it's greater. (Any such cases
would panic trying to slice `line` from `line.len()+1`.)

Resolves rust-lang#47197.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants