Skip to content

Panic in source_span_for_markdown_range #141665

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

Closed
GuillaumeGomez opened this issue May 27, 2025 · 4 comments · Fixed by #141666
Closed

Panic in source_span_for_markdown_range #141665

GuillaumeGomez opened this issue May 27, 2025 · 4 comments · Fixed by #141666
Assignees
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name A-markdown-parsing Area: Markdown parsing for doc-comments A-Unicode Area: Unicode C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@GuillaumeGomez
Copy link
Member

Seems like we do something wrong with strings indexing.

thread 'rustc' panicked at compiler/rustc_resolve/src/rustdoc.rs:573:52:
byte index 829 is not a char boundary; it is inside '⚠' (bytes 828..831) of `# sysinfo [![][img_crates]][crates] [![][img_doc]][doc]

`sysinfo` is a crate used to get a system's information.

## Supported OSes

It currently supports the following OSes (alphabetically sorted):

 * Android
 * FreeBSD
 * iOS
 * Linux
 * macOS
 * Raspb`[...]
stack backtrace:
   0:     0x7fedf6187f53 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hf9e24adbe3047db4
   1:     0x7fedf6805877 - core::fmt::write::h69464b7c3fd5e556
   2:     0x7fedf7976911 - std::io::Write::write_fmt::hb26edb100dd5950f
   3:     0x7fedf6187db2 - std::sys::backtrace::BacktraceLock::print::hb1091998081da5bd
   4:     0x7fedf618b9aa - std::panicking::default_hook::{{closure}}::h7c3d49848ce65ffc
   5:     0x7fedf618b52f - std::panicking::default_hook::h672644795455c113
   6:     0x7fedf51aef53 - std[21fde1207f00070e]::panicking::update_hook::<alloc[1588af6cffbc44e0]::boxed::Box<rustc_driver_impl[456a604eb730744d]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7fedf618c223 - std::panicking::rust_panic_with_hook::h4f1cef12e25d9010
   8:     0x7fedf618bf1a - std::panicking::begin_panic_handler::{{closure}}::hb55116864d318499
   9:     0x7fedf6188419 - std::sys::backtrace::__rust_end_short_backtrace::ha8a50b7257306f2c
  10:     0x7fedf618bbdd - __rustc[9b349d1953572bc6]::rust_begin_unwind
  11:     0x7fedf2a8e100 - core::panicking::panic_fmt::h935c41405e3972bf
  12:     0x7fedf4b28038 - core::str::slice_error_fail_rt::h2d86afe338b76f24
  13:     0x7fedf46c87fa - core::str::slice_error_fail::h4bd3819b8b032771
  14:     0x7fedf5d2ea93 - rustc_resolve[7cbb14a8f088e415]::rustdoc::source_span_for_markdown_range
  15:     0x55d0dd339c3e - clippy_lints[b00f0ebaf4999f0]::doc::check_doc::<pulldown_cmark[317fdb1271aed187]::parse::OffsetIter<&mut clippy_lints[b00f0ebaf4999f0]::doc::check_attrs::fake_broken_link_callback>>
  16:     0x55d0dd337798 - <clippy_lints[b00f0ebaf4999f0]::doc::Documentation as rustc_lint[40842392e773dd3f]::passes::LateLintPass>::check_attributes
  17:     0x7fedf770cb42 - rustc_lint[40842392e773dd3f]::late::check_crate::{closure#0}
  18:     0x7fedf770ceab - rustc_lint[40842392e773dd3f]::late::check_crate
  19:     0x7fedf771081f - rustc_interface[a7a41a29f08ea03]::passes::analysis
  20:     0x7fedf77105f5 - rustc_query_impl[601dcc0868136b20]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[601dcc0868136b20]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5eb5ed378518d9da]::query::erase::Erased<[u8; 0usize]>>
  21:     0x7fedf77126fa - rustc_query_system[10aaad7a65d627b6]::query::plumbing::try_execute_query::<rustc_query_impl[601dcc0868136b20]::DynamicConfig<rustc_query_system[10aaad7a65d627b6]::query::caches::SingleCache<rustc_middle[5eb5ed378518d9da]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[601dcc0868136b20]::plumbing::QueryCtxt, false>
  22:     0x7fedf77123cf - rustc_query_impl[601dcc0868136b20]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  23:     0x7fedf79a3207 - rustc_interface[a7a41a29f08ea03]::passes::create_and_enter_global_ctxt::<core[2969579d35182c01]::option::Option<rustc_interface[a7a41a29f08ea03]::queries::Linker>, rustc_driver_impl[456a604eb730744d]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  24:     0x7fedf798744f - rustc_interface[a7a41a29f08ea03]::interface::run_compiler::<(), rustc_driver_impl[456a604eb730744d]::run_compiler::{closure#0}>::{closure#1}
  25:     0x7fedf78acdc6 - std[21fde1207f00070e]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[a7a41a29f08ea03]::util::run_in_thread_with_globals<rustc_interface[a7a41a29f08ea03]::util::run_in_thread_pool_with_globals<rustc_interface[a7a41a29f08ea03]::interface::run_compiler<(), rustc_driver_impl[456a604eb730744d]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  26:     0x7fedf78aca6b - <<std[21fde1207f00070e]::thread::Builder>::spawn_unchecked_<rustc_interface[a7a41a29f08ea03]::util::run_in_thread_with_globals<rustc_interface[a7a41a29f08ea03]::util::run_in_thread_pool_with_globals<rustc_interface[a7a41a29f08ea03]::interface::run_compiler<(), rustc_driver_impl[456a604eb730744d]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[2969579d35182c01]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  27:     0x7fedf78addbd - std::sys::pal::unix::thread::Thread::new::thread_start::h4356d888f81dd7e9
  28:     0x7fedf149caa4 - <unknown>
  29:     0x7fedf1529c3c - <unknown>
  30:                0x0 - <unknown>

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

I'll try to write a small reproducer.

@GuillaumeGomez GuillaumeGomez added the C-bug Category: This is a bug. label May 27, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 27, 2025
@fmease fmease added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-markdown-parsing Area: Markdown parsing for doc-comments A-Unicode Area: Unicode A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 27, 2025
@lolbinarycat
Copy link
Contributor

I see the problem, this is a case where treating utf-8 as bytes will give you the correct result due to its self-synchronizing nature, but rust still doesn't let us split a codepoint.

@lolbinarycat lolbinarycat self-assigned this May 27, 2025
@lolbinarycat
Copy link
Contributor

annoyingly, the fix would be a lot easier if we had either ByteStr::contains or str::advance_char.

@fmease fmease added E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. and removed S-needs-repro Status: This issue has no reproduction and needs a reproduction to make progress. labels May 27, 2025
@fmease
Copy link
Member

fmease commented May 27, 2025

For everyone's information, the repro steps are:

  1. git clone --depth=1 https://github.com/GuillaumeGomez/sysinfo.git
  2. cargo clippy --all-features

@fmease
Copy link
Member

fmease commented May 27, 2025

Manually minimized (still requires Clippy tho):

cat file.rs:

#![doc = "⚠️"]
#![doc = ""]

hexdump file.rs -C:

00000000  23 21 5b 64 6f 63 20 3d  20 22 e2 9a a0 ef b8 8f  |#![doc = "......|
00000010  22 5d 0a 23 21 5b 64 6f  63 20 3d 20 22 22 5d 0a  |"].#![doc = ""].|
00000020

clippy-driver file.rs --crate-type=lib:

thread 'rustc' panicked at compiler/rustc_resolve/src/rustdoc.rs:573:52:
byte index 2 is not a char boundary; it is inside '⚠' (bytes 1..4) of `"⚠️"`

@fmease fmease added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels May 27, 2025
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jun 1, 2025
…or_markdown_range-bug-141665, r=GuillaumeGomez

source_span_for_markdown_range: fix utf8 violation

it is non-trivial to reproduce this bug through rustdoc, which uses this function less than clippy, so the regression test was added as a unit test instead of an integration test.

fixes rust-lang#141665

r? `@GuillaumeGomez`
@bors bors closed this as completed in d843809 Jun 1, 2025
rust-timer added a commit that referenced this issue Jun 1, 2025
Rollup merge of #141666 - lolbinarycat:rustdoc-source_span_for_markdown_range-bug-141665, r=GuillaumeGomez

source_span_for_markdown_range: fix utf8 violation

it is non-trivial to reproduce this bug through rustdoc, which uses this function less than clippy, so the regression test was added as a unit test instead of an integration test.

fixes #141665

r? ``@GuillaumeGomez``
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Jun 3, 2025
…wn_range-bug-141665, r=GuillaumeGomez

source_span_for_markdown_range: fix utf8 violation

it is non-trivial to reproduce this bug through rustdoc, which uses this function less than clippy, so the regression test was added as a unit test instead of an integration test.

fixes rust-lang/rust#141665

r? ``@GuillaumeGomez``
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 A-markdown-parsing Area: Markdown parsing for doc-comments A-Unicode Area: Unicode C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants