Skip to content

ICE: rustdoc json when #[doc(primitive)] mod name is same as primitive name. #102363

Closed

Description

@matthiaskrgr

Code

#![feature(no_core)]
#![no_core]

#[doc(primitive = "usize")]
/// This is the built-in type `usize`.
mod usize {
}

This is a regression that started happening between
rustdoc 1.66.0-nightly (8b705839c 2022-09-26) (no ice) and
rustdoc 1.66.0-nightly (57ee5cf5a 2022-09-27) (ice)

rustdoc --document-private-items -Zunstable-options --output-format=json

Backtrace

warning: `doc(primitive)` should never have been stable
 --> 98006.rs:6:7
  |
6 | #[doc(primitive = "usize")]
  |       ^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(invalid_doc_attributes)]` on by default
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>

thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `Item { id: Id("0:1:1516"), crate_id: 0, name: Some("usize"), span: Some(Span { filename: "98006.rs", begin: (8, 0), end: (8, 9) }), visibility: Crate, docs: Some("This is the built-in type `usize`."), links: {}, attrs: ["#[doc(primitive = \"usize\")]"], deprecation: None, inner: Module(Module { is_crate: false, items: [], is_stripped: false }) }`,
 right: `Item { id: Id("0:1:1516"), crate_id: 0, name: Some("usize"), span: Some(Span { filename: "98006.rs", begin: (8, 0), end: (9, 1) }), visibility: Public, docs: Some("This is the built-in type `usize`."), links: {}, attrs: ["#[doc(primitive = \"usize\")]"], deprecation: None, inner: Primitive(Primitive { name: "usize", impls: [] }) }`', src/librustdoc/json/mod.rs:258:21
stack backtrace:
   0:     0x7f8b1b682170 - std::backtrace_rs::backtrace::libunwind::trace::h18072076057b94d0
                               at /rustc/57ee5cf5a93923dae9c98bffb11545fc3a31368d/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   1:     0x7f8b1b682170 - std::backtrace_rs::backtrace::trace_unsynchronized::h532d7bcf1e66d957
                               at /rustc/57ee5cf5a93923dae9c98bffb11545fc3a31368d/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f8b1b682170 - std::sys_common::backtrace::_print_fmt::h97186aed02d3795a
                               at /rustc/57ee5cf5a93923dae9c98bffb11545fc3a31368d/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f8b1b682170 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h112f6af2ce1fe574
                               at /rustc/57ee5cf5a93923dae9c98bffb11545fc3a31368d/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f8b1b6dce2e - core::fmt::write::h3881197b972a8ed1
                               at /rustc/57ee5cf5a93923dae9c98bffb11545fc3a31368d/library/core/src/fmt/mod.rs:1209:17
   5:     0x7f8b1b672cb5 - std::io::Write::write_fmt::h1b373ce231ecbbd3
                               at /rustc/57ee5cf5a93923dae9c98bffb11545fc3a31368d/library/std/src/io/mod.rs:1679:15
   6:     0x7f8b1b684ef3 - std::sys_common::backtrace::_print::hc775c17a0b8c6b1b
                               at /rustc/57ee5cf5a93923dae9c98bffb11545fc3a31368d/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f8b1b684ef3 - std::sys_common::backtrace::print::ha88e092611b4deb6
                               at /rustc/57ee5cf5a93923dae9c98bffb11545fc3a31368d/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f8b1b684ef3 - std::panicking::default_hook::{{closure}}::h5b92fe4806ec2836
                               at /rustc/57ee5cf5a93923dae9c98bffb11545fc3a31368d/library/std/src/panicking.rs:267:22
   9:     0x7f8b1b684bdf - std::panicking::default_hook::h75816c7fe1dfa8fc
                               at /rustc/57ee5cf5a93923dae9c98bffb11545fc3a31368d/library/std/src/panicking.rs:286:9
  10:     0x7f8b1dec10e1 - rustc_driver[c6fdf2c45090383f]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f8b1b68572b - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hcb24b686ebdf651a
                               at /rustc/57ee5cf5a93923dae9c98bffb11545fc3a31368d/library/alloc/src/boxed.rs:1952:9
  12:     0x7f8b1b68572b - std::panicking::rust_panic_with_hook::h9ff72342096b4ba9
                               at /rustc/57ee5cf5a93923dae9c98bffb11545fc3a31368d/library/std/src/panicking.rs:673:13
  13:     0x7f8b1b685587 - std::panicking::begin_panic_handler::{{closure}}::h44b52a3dcbc6194f
                               at /rustc/57ee5cf5a93923dae9c98bffb11545fc3a31368d/library/std/src/panicking.rs:560:13
  14:     0x7f8b1b68261c - std::sys_common::backtrace::__rust_end_short_backtrace::h3f28777c5c6b6c07
                               at /rustc/57ee5cf5a93923dae9c98bffb11545fc3a31368d/library/std/src/sys_common/backtrace.rs:138:18
  15:     0x7f8b1b6852a2 - rust_begin_unwind
                               at /rustc/57ee5cf5a93923dae9c98bffb11545fc3a31368d/library/std/src/panicking.rs:556:5
  16:     0x7f8b1b6d9a03 - core::panicking::panic_fmt::h78ff0847a851546f
                               at /rustc/57ee5cf5a93923dae9c98bffb11545fc3a31368d/library/core/src/panicking.rs:142:14
  17:     0x7f8b1b6d9c0b - core::panicking::assert_failed_inner::h5c9e7ac3b8a65a4e
  18:     0x561a4a38dcab - core[7bc7496ae1e2fee9]::panicking::assert_failed::<rustdoc_json_types[5cc9bbe84b676943]::Item, rustdoc_json_types[5cc9bbe84b676943]::Item>
  19:     0x561a4a55d8e5 - <rustdoc[e0c88defa146e256]::json::JsonRenderer as rustdoc[e0c88defa146e256]::formats::renderer::FormatRenderer>::item
  20:     0x561a4a5586a9 - <rustdoc[e0c88defa146e256]::json::JsonRenderer as rustdoc[e0c88defa146e256]::formats::renderer::FormatRenderer>::item
  21:     0x561a4a54d3bc - rustdoc[e0c88defa146e256]::formats::renderer::run_format::<rustdoc[e0c88defa146e256]::json::JsonRenderer>
  22:     0x561a4a277962 - rustdoc[e0c88defa146e256]::run_renderer::<rustdoc[e0c88defa146e256]::json::JsonRenderer>
  23:     0x561a4a519c58 - <rustc_session[25cfbabaae5db07f]::session::Session>::time::<core[7bc7496ae1e2fee9]::result::Result<(), rustc_errors[3785ec4f24cf7dcd]::ErrorGuaranteed>, rustdoc[e0c88defa146e256]::main_options::{closure#0}::{closure#0}::{closure#1}::{closure#2}>
  24:     0x561a4a46d588 - <rustc_interface[30c3b065dc69ec4b]::passes::QueryContext>::enter::<rustdoc[e0c88defa146e256]::main_options::{closure#0}::{closure#0}::{closure#1}, core[7bc7496ae1e2fee9]::result::Result<(), rustc_errors[3785ec4f24cf7dcd]::ErrorGuaranteed>>
  25:     0x561a4a3bc95b - <rustc_interface[30c3b065dc69ec4b]::interface::Compiler>::enter::<rustdoc[e0c88defa146e256]::main_options::{closure#0}::{closure#0}, core[7bc7496ae1e2fee9]::result::Result<(), rustc_errors[3785ec4f24cf7dcd]::ErrorGuaranteed>>
  26:     0x561a4a5911b0 - rustc_span[7cf632b9cf8d883f]::with_source_map::<core[7bc7496ae1e2fee9]::result::Result<(), rustc_errors[3785ec4f24cf7dcd]::ErrorGuaranteed>, rustc_interface[30c3b065dc69ec4b]::interface::create_compiler_and_run<core[7bc7496ae1e2fee9]::result::Result<(), rustc_errors[3785ec4f24cf7dcd]::ErrorGuaranteed>, rustdoc[e0c88defa146e256]::main_options::{closure#0}>::{closure#1}>
  27:     0x561a4a3c0d8e - rustc_interface[30c3b065dc69ec4b]::interface::create_compiler_and_run::<core[7bc7496ae1e2fee9]::result::Result<(), rustc_errors[3785ec4f24cf7dcd]::ErrorGuaranteed>, rustdoc[e0c88defa146e256]::main_options::{closure#0}>
  28:     0x561a4a279680 - rustdoc[e0c88defa146e256]::main_options
  29:     0x561a4a3be0bb - <scoped_tls[a7b6c99e8efb4b77]::ScopedKey<rustc_span[7cf632b9cf8d883f]::SessionGlobals>>::set::<rustdoc[e0c88defa146e256]::main_args::{closure#0}, core[7bc7496ae1e2fee9]::result::Result<(), rustc_errors[3785ec4f24cf7dcd]::ErrorGuaranteed>>
  30:     0x561a4a52fef0 - std[3920356c99757f55]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[30c3b065dc69ec4b]::util::run_in_thread_pool_with_globals<rustdoc[e0c88defa146e256]::main_args::{closure#0}, core[7bc7496ae1e2fee9]::result::Result<(), rustc_errors[3785ec4f24cf7dcd]::ErrorGuaranteed>>::{closure#0}, core[7bc7496ae1e2fee9]::result::Result<(), rustc_errors[3785ec4f24cf7dcd]::ErrorGuaranteed>>
  31:     0x561a4a3f065c - <<std[3920356c99757f55]::thread::Builder>::spawn_unchecked_<rustc_interface[30c3b065dc69ec4b]::util::run_in_thread_pool_with_globals<rustdoc[e0c88defa146e256]::main_args::{closure#0}, core[7bc7496ae1e2fee9]::result::Result<(), rustc_errors[3785ec4f24cf7dcd]::ErrorGuaranteed>>::{closure#0}, core[7bc7496ae1e2fee9]::result::Result<(), rustc_errors[3785ec4f24cf7dcd]::ErrorGuaranteed>>::{closure#1} as core[7bc7496ae1e2fee9]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  32:     0x7f8b1b68f393 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd5fc23daeb019c95
                               at /rustc/57ee5cf5a93923dae9c98bffb11545fc3a31368d/library/alloc/src/boxed.rs:1938:9
  33:     0x7f8b1b68f393 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3edde1a879c58522
                               at /rustc/57ee5cf5a93923dae9c98bffb11545fc3a31368d/library/alloc/src/boxed.rs:1938:9
  34:     0x7f8b1b68f393 - std::sys::unix::thread::Thread::new::thread_start::h7d0849b25413c998
                               at /rustc/57ee5cf5a93923dae9c98bffb11545fc3a31368d/library/std/src/sys/unix/thread.rs:108:17
  35:     0x7f8b1b3c778d - <unknown>
  36:     0x7f8b1b4488e4 - clone
  37:                0x0 - <unknown>

error: internal compiler error: unexpected panic

note: 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-compiler&template=ice.md

note: rustc 1.66.0-nightly (57ee5cf5a 2022-09-27) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z unstable-options

query stack during panic:
end of query stack
warning: 1 warning emitted

Activity

  1. added
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    C-bugCategory: This is a bug.
    on Sep 27, 2022
  2. matthiaskrgr commented on Sep 27, 2022

    @matthiaskrgr
    MemberAuthor

    searched toolchains 8b70583 through 57ee5cf


    Regression in cd4d9d9


  3. matthiaskrgr commented on Sep 27, 2022

    @matthiaskrgr
    MemberAuthor

    maybe #102321 ?

  4. aDotInTheVoid commented on Sep 27, 2022

    @aDotInTheVoid
    Member

    The problem is here, where primitives are given the same id as the module they are contained in.

    m.items.extend(primitives.iter().map(|&(def_id, prim)| {
    Item::from_def_id_and_parts(
    def_id,
    Some(prim.as_sym()),
    ItemKind::PrimitiveItem(prim),
    cx,
    )
    }));

    Instead, they should use an ItemId::Primitve

    @rustbot claim

  5. aDotInTheVoid commented on Sep 29, 2022

    @aDotInTheVoid
    Member

    Turns out that isn’t a viable approach, as the whole rustdoc primitve infrastructure assumes that primitives have a defid, which is the one that actually belongs to the module.

    An alternative approach would be for the json backend to just ignore module labelled #[doc(primitive)]. This would make rustdoc json be slightly inaccurate when documenting core with —document-private-items, but only by loosing mod prim_i32 etc, which i feel is acceptable as they are empty and only exists to help rustdoc.

  6. aDotInTheVoid commented on Sep 29, 2022

    @aDotInTheVoid
    Member

    Upon further investigation, it turns out that this only occurs is when the name of the primitive is the name of the module. When the prim name != the mod name, everything is fine: We test for this https://github.com/rust-lang/rust/blob/master/src/test/rustdoc-json/primitives/primitive_overloading.rs

    Given that core/std use different names for the mod/primitve, and #[doc(primitive)] is just meant to be an implementation detail of std/core, and not for general purpose use, I don't think it is an issue that we ice here.

    Proof that it works fine for core
    ne321@vertex39:rust$ rm -rf build/x86_64-unknown-linux-gnu/doc/
    ne321@vertex39:rust$ RUSTDOCFLAGS="--output-format=json --document-private-items" ./x.py doc library/std --stage 2
    Building rustbuild
        Finished dev [unoptimized] target(s) in 0.54s
    Documenting stage2 std (x86_64-unknown-linux-gnu) in HTML format
    Building rustdoc for stage2 (x86_64-unknown-linux-gnu)
       Compiling rustdoc v0.0.0 (/data/ne321/rust/src/librustdoc)
       Compiling rustdoc-tool v0.0.0 (/data/ne321/rust/src/tools/rustdoc)
        Finished release [optimized] target(s) in 9.61s
     Documenting core v0.0.0 (/data/ne321/rust/library/core)
        Finished release [optimized] target(s) in 7.53s
     Documenting alloc v0.0.0 (/data/ne321/rust/library/alloc)
        Finished release [optimized] target(s) in 1.71s
     Documenting std v0.0.0 (/data/ne321/rust/library/std)
        Finished release [optimized] target(s) in 2.78s
    Build completed successfully in 0:00:22
    ne321@vertex39:rust$ oj -x "$.index[?(@.name=='usize' && @.kind=='primitive')]" -d "$..impls" -p 200.9 build/x86_64-unknown-linux-gnu/doc/core.json 
    {
      "attrs": ["#[doc(primitive = \"usize\")]", "#[stable(feature = \"rust1\", since = \"1.0.0\")]"],
      "crate_id": 0,
      "deprecation": null,
      "docs": "The pointer-sized unsigned integer type.\n\nThe size of this primitive is how many bytes it takes to reference any\nlocation in memory. For example, on a 32 bit target, this is 4 bytes\nand on a 64 bit target, this is 8 bytes.",
      "id": "0:75795:1516",
      "inner": {"name": "usize"},
      "kind": "primitive",
      "links": {},
      "name": "usize",
      "span": {"begin": [1241, 0], "end": [1241, 17], "filename": "library/core/src/primitive_docs.rs"},
      "visibility": "public"
    }
    ne321@vertex39:rust$ oj -x "$.index[?(@.name=='prim_usize')]" -p 200.9 build/x86_64-unknown-linux-gnu/doc/core.json
    {
      "attrs": ["#[doc(primitive = \"usize\")]", "#[stable(feature = \"rust1\", since = \"1.0.0\")]"],
      "crate_id": 0,
      "deprecation": null,
      "docs": "The pointer-sized unsigned integer type.\n\nThe size of this primitive is how many bytes it takes to reference any\nlocation in memory. For example, on a 32 bit target, this is 4 bytes\nand on a 64 bit target, this is 8 bytes.",
      "id": "0:75795:77753",
      "inner": {"is_crate": false, "is_stripped": false, "items": []},
      "kind": "module",
      "links": {},
      "name": "prim_usize",
      "span": {"begin": [1241, 0], "end": [1241, 14], "filename": "library/core/src/primitive_docs.rs"},
      "visibility": "crate"
    }
    
  7. changed the title [-]ICE: rustdoc assertion failed: `(left == right), rustdoc json[/-] [+]ICE: rustdoc json when #[doc(primitive)] mod name is same as primitive name.[/+] on Jan 1, 2023
  8. JohnTitor commented on Apr 3, 2023

    @JohnTitor
    Member

    Triage: nightly-2023-04-01 fixes the issue, marking as E-needs-test.

  9. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    on Apr 3, 2023
  10. workingjubilee commented on Jul 11, 2023

    @workingjubilee
    Member

    There are already tests for the feature gate's general functionality (which do verify that things work appropriately), and this is just one of those tests executed in a different way. We've effectively agreed we're not going to sweat ICEs when rustc_attrs and its friends are required, per:

    Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-rustdoc-jsonArea: Rustdoc JSON backendC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions