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 docstring contains ampersand link “[&]” followed by link to valid item in backticks #111896

Closed
taylordotfish opened this issue May 24, 2023 · 2 comments
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name 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

@taylordotfish
Copy link

cargo doc produces an ICE when [&] is followed by (with a space or other text in between) a link to a valid Rust item surrounded in backticks (e.g., [`u8`]).

For example, given this code:

/// [&] and [`u8`]
pub fn foo() {}

cargo doc produces the following error:

Backtrace

 Documenting doc-ice v0.1.0 (/tmp/doc-ice)
thread 'rustc' panicked at 'begin <= end (1 <= 0) when slicing `&`', src/librustdoc/html/markdown.rs:394:34
stack backtrace:
   0:     0x7fa5196ef531 - std::backtrace_rs::backtrace::libunwind::trace::h85353fbffbb5fad1
                               at /rustc/5ea3f0ae08c07472239a94ce55601e9b63eb1f45/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fa5196ef531 - std::backtrace_rs::backtrace::trace_unsynchronized::hfc7dfff9156f6f98
                               at /rustc/5ea3f0ae08c07472239a94ce55601e9b63eb1f45/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fa5196ef531 - std::sys_common::backtrace::_print_fmt::h648083d2cc9ba829
                               at /rustc/5ea3f0ae08c07472239a94ce55601e9b63eb1f45/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7fa5196ef531 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h432754e844e463da
                               at /rustc/5ea3f0ae08c07472239a94ce55601e9b63eb1f45/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fa51974fbbf - core::fmt::rt::Argument::fmt::h86d079eba54a9db7
                               at /rustc/5ea3f0ae08c07472239a94ce55601e9b63eb1f45/library/core/src/fmt/rt.rs:138:9
   5:     0x7fa51974fbbf - core::fmt::write::h9ec36ddf085af422
                               at /rustc/5ea3f0ae08c07472239a94ce55601e9b63eb1f45/library/core/src/fmt/mod.rs:1094:21
   6:     0x7fa5196e2831 - std::io::Write::write_fmt::h9072a6fe98b37072
                               at /rustc/5ea3f0ae08c07472239a94ce55601e9b63eb1f45/library/std/src/io/mod.rs:1712:15
   7:     0x7fa5196ef345 - std::sys_common::backtrace::_print::h42cf0a528b22cabe
                               at /rustc/5ea3f0ae08c07472239a94ce55601e9b63eb1f45/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fa5196ef345 - std::sys_common::backtrace::print::hf1676a4dba4fd321
                               at /rustc/5ea3f0ae08c07472239a94ce55601e9b63eb1f45/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fa5196f1ff7 - std::panicking::default_hook::{{closure}}::h26afb1d646554fbd
  10:     0x7fa5196f1de4 - std::panicking::default_hook::h86dd4c48a94450d5
                               at /rustc/5ea3f0ae08c07472239a94ce55601e9b63eb1f45/library/std/src/panicking.rs:288:9
  11:     0x7fa51c895a0b - rustc_driver_impl[d00b7a9cb5f2ce91]::install_ice_hook::{closure#0}
  12:     0x7fa5196f2717 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hfc9965ef7e796e3f
                               at /rustc/5ea3f0ae08c07472239a94ce55601e9b63eb1f45/library/alloc/src/boxed.rs:1999:9
  13:     0x7fa5196f2717 - std::panicking::rust_panic_with_hook::h6ce289fcafa1b5d6
                               at /rustc/5ea3f0ae08c07472239a94ce55601e9b63eb1f45/library/std/src/panicking.rs:695:13
  14:     0x7fa5196f2497 - std::panicking::begin_panic_handler::{{closure}}::hfbc29edfcefb8d0a
                               at /rustc/5ea3f0ae08c07472239a94ce55601e9b63eb1f45/library/std/src/panicking.rs:582:13
  15:     0x7fa5196ef966 - std::sys_common::backtrace::__rust_end_short_backtrace::h8021c3146e334c0a
                               at /rustc/5ea3f0ae08c07472239a94ce55601e9b63eb1f45/library/std/src/sys_common/backtrace.rs:151:18
  16:     0x7fa5196f2202 - rust_begin_unwind
                               at /rustc/5ea3f0ae08c07472239a94ce55601e9b63eb1f45/library/std/src/panicking.rs:578:5
  17:     0x7fa51974be43 - core::panicking::panic_fmt::h5d71f2ca8fbef52b
                               at /rustc/5ea3f0ae08c07472239a94ce55601e9b63eb1f45/library/core/src/panicking.rs:67:14
  18:     0x7fa519754b2f - core::str::slice_error_fail_rt::h0f13a99ac005d839
  19:     0x7fa519754987 - core::str::slice_error_fail::hb2c7e8f903dfdf2e
                               at /rustc/5ea3f0ae08c07472239a94ce55601e9b63eb1f45/library/core/src/str/mod.rs:87:9
  20:     0x5621acae1862 - rustdoc[3e41928430b2e821]::html::markdown::short_markdown_summary
  21:     0x5621acb4cb7d - <rustdoc[3e41928430b2e821]::formats::cache::CacheBuilder as rustdoc[3e41928430b2e821]::fold::DocFolder>::fold_item
  22:     0x5621acaaaa05 - <alloc[180c8788ec8caf0c]::vec::Vec<rustdoc[3e41928430b2e821]::clean::types::Item> as alloc[180c8788ec8caf0c]::vec::spec_from_iter::SpecFromIter<rustdoc[3e41928430b2e821]::clean::types::Item, core[2ef80f1aadaf56e9]::iter::adapters::filter_map::FilterMap<alloc[180c8788ec8caf0c]::vec::into_iter::IntoIter<rustdoc[3e41928430b2e821]::clean::types::Item>, <rustdoc[3e41928430b2e821]::formats::cache::CacheBuilder as rustdoc[3e41928430b2e821]::fold::DocFolder>::fold_inner_recur::{closure#5}>>>::from_iter
  23:     0x5621acb47548 - <rustdoc[3e41928430b2e821]::formats::cache::CacheBuilder as rustdoc[3e41928430b2e821]::fold::DocFolder>::fold_inner_recur
  24:     0x5621acb47b7e - <rustdoc[3e41928430b2e821]::formats::cache::CacheBuilder as rustdoc[3e41928430b2e821]::fold::DocFolder>::fold_item_recur
  25:     0x5621acb4d315 - <rustdoc[3e41928430b2e821]::formats::cache::CacheBuilder as rustdoc[3e41928430b2e821]::fold::DocFolder>::fold_item
  26:     0x5621acb4a6c6 - <rustdoc[3e41928430b2e821]::formats::cache::Cache>::populate
  27:     0x5621ac9d4090 - <rustc_session[31645572b8ab3492]::session::Session>::time::<rustdoc[3e41928430b2e821]::clean::types::Crate, rustdoc[3e41928430b2e821]::core::run_global_ctxt::{closure#10}>
  28:     0x5621acb45b8f - rustdoc[3e41928430b2e821]::core::run_global_ctxt
  29:     0x5621ac9d41d1 - <rustc_session[31645572b8ab3492]::session::Session>::time::<(rustdoc[3e41928430b2e821]::clean::types::Crate, rustdoc[3e41928430b2e821]::config::RenderOptions, rustdoc[3e41928430b2e821]::formats::cache::Cache), rustdoc[3e41928430b2e821]::main_args::{closure#1}::{closure#0}::{closure#0}::{closure#0}>
  30:     0x5621acbfdd33 - <rustc_middle[7e83052949f575b3]::ty::context::GlobalCtxt>::enter::<rustdoc[3e41928430b2e821]::main_args::{closure#1}::{closure#0}::{closure#0}, core[2ef80f1aadaf56e9]::result::Result<(), rustc_span[8df09863e4fe0d6]::ErrorGuaranteed>>
  31:     0x5621ac9f75c3 - <rustc_interface[cfd4f1bae86ee4d7]::interface::Compiler>::enter::<rustdoc[3e41928430b2e821]::main_args::{closure#1}::{closure#0}, core[2ef80f1aadaf56e9]::result::Result<(), rustc_span[8df09863e4fe0d6]::ErrorGuaranteed>>
  32:     0x5621acb7f726 - rustc_span[8df09863e4fe0d6]::set_source_map::<core[2ef80f1aadaf56e9]::result::Result<(), rustc_span[8df09863e4fe0d6]::ErrorGuaranteed>, rustc_interface[cfd4f1bae86ee4d7]::interface::run_compiler<core[2ef80f1aadaf56e9]::result::Result<(), rustc_span[8df09863e4fe0d6]::ErrorGuaranteed>, rustdoc[3e41928430b2e821]::main_args::{closure#1}>::{closure#0}::{closure#0}>
  33:     0x5621ac93b11d - <scoped_tls[802aab8aba063b4c]::ScopedKey<rustc_span[8df09863e4fe0d6]::SessionGlobals>>::set::<rustc_interface[cfd4f1bae86ee4d7]::interface::run_compiler<core[2ef80f1aadaf56e9]::result::Result<(), rustc_span[8df09863e4fe0d6]::ErrorGuaranteed>, rustdoc[3e41928430b2e821]::main_args::{closure#1}>::{closure#0}, core[2ef80f1aadaf56e9]::result::Result<(), rustc_span[8df09863e4fe0d6]::ErrorGuaranteed>>
  34:     0x5621acac0029 - std[8a699ae0d1f3c3b0]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[cfd4f1bae86ee4d7]::util::run_in_thread_pool_with_globals<rustc_interface[cfd4f1bae86ee4d7]::interface::run_compiler<core[2ef80f1aadaf56e9]::result::Result<(), rustc_span[8df09863e4fe0d6]::ErrorGuaranteed>, rustdoc[3e41928430b2e821]::main_args::{closure#1}>::{closure#0}, core[2ef80f1aadaf56e9]::result::Result<(), rustc_span[8df09863e4fe0d6]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[2ef80f1aadaf56e9]::result::Result<(), rustc_span[8df09863e4fe0d6]::ErrorGuaranteed>>
  35:     0x5621acb2c661 - <<std[8a699ae0d1f3c3b0]::thread::Builder>::spawn_unchecked_<rustc_interface[cfd4f1bae86ee4d7]::util::run_in_thread_pool_with_globals<rustc_interface[cfd4f1bae86ee4d7]::interface::run_compiler<core[2ef80f1aadaf56e9]::result::Result<(), rustc_span[8df09863e4fe0d6]::ErrorGuaranteed>, rustdoc[3e41928430b2e821]::main_args::{closure#1}>::{closure#0}, core[2ef80f1aadaf56e9]::result::Result<(), rustc_span[8df09863e4fe0d6]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[2ef80f1aadaf56e9]::result::Result<(), rustc_span[8df09863e4fe0d6]::ErrorGuaranteed>>::{closure#1} as core[2ef80f1aadaf56e9]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  36:     0x7fa5196fcb85 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf02aee76c98541f9
                               at /rustc/5ea3f0ae08c07472239a94ce55601e9b63eb1f45/library/alloc/src/boxed.rs:1985:9
  37:     0x7fa5196fcb85 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7ccec49a983fed78
                               at /rustc/5ea3f0ae08c07472239a94ce55601e9b63eb1f45/library/alloc/src/boxed.rs:1985:9
  38:     0x7fa5196fcb85 - std::sys::unix::thread::Thread::new::thread_start::hfa77c319ec7fdf2d
                               at /rustc/5ea3f0ae08c07472239a94ce55601e9b63eb1f45/library/std/src/sys/unix/thread.rs:108:17
  39:     0x7fa51959aea7 - start_thread
                               at ./nptl/pthread_create.c:477:8
  40:     0x7fa519376a2f - clone
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  41:                0x0 - <unknown>

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-rustdoc&template=ice.md

note: rustc 1.71.0-nightly (5ea3f0ae0 2023-05-23) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -Z unstable-options

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: could not document `doc-ice`

Caused by:
  process didn't exit successfully: `/home/taylor/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustdoc --edition=2021 --crate-type lib --crate-name doc_ice src/lib.rs -o /tmp/doc-ice/target/doc --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat -C metadata=7b72b63e900334b7 -L dependency=/tmp/doc-ice/target/debug/deps -Z unstable-options --extern-html-root-takes-precedence --crate-version 0.1.0` (exit status: 101)

If the [`u8`] is changed to [u8], or if the [`u8`] and [&] are reordered, cargo doc runs as expected, creating links to the documentation for u8 and the primitive reference type. If [`u8`] is changed so it does not refer to a valid Rust item, cargo doc will also run without error (just warnings).

Meta

rustc --version --verbose:

rustc 1.71.0-nightly (5ea3f0ae0 2023-05-23)
binary: rustc
commit-hash: 5ea3f0ae08c07472239a94ce55601e9b63eb1f45
commit-date: 2023-05-23
host: x86_64-unknown-linux-gnu
release: 1.71.0-nightly
LLVM version: 16.0.4
@taylordotfish taylordotfish added the C-bug Category: This is a bug. label May 24, 2023
@KittyBorgX KittyBorgX added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label May 24, 2023
@jyn514 jyn514 added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name labels May 24, 2023
@fmease
Copy link
Member

fmease commented Jun 7, 2023

This longer crashes in the current nightly. I think it was #108459 that fixed this.

@fmease
Copy link
Member

fmease commented Sep 6, 2023

Closing as fixed by #108459

@fmease fmease closed this as completed Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name 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

4 participants