Closed
Description
Similar to #80664, another ICE due to non identical items.
Cargo.toml
[package]
name = "ice_demo"
version = "0.1.0"
edition="2018"
[dependencies]
foo = { path = "./foo" }
src/lib.rs
#[doc(inline)]
pub use foo::Foo;
pub mod bar {
pub use foo::Foo;
}
foo/src/lib.rs
pub struct Foo;
Run cargo +nightly rustdoc -- -w json
, and it panics here
left: `Item { id: Id("16:3"), crate_id: 16, name: Some("Foo"), source: Some(Span { filename: "/private/tmp/ice_demo/foo/src/lib.rs", begin: (1, 0), end: (1, 15) }), visibility: Public, docs: None, links: {}, attrs: [], deprecation: None, inner: Struct(Struct { struct_type: Unit, generics: Generics { params: [], where_predicates: [] }, fields_stripped: false, fields: [], impls: [] }) }`,
right: `Item { id: Id("16:3"), crate_id: 16, name: Some("Foo"), source: Some(Span { filename: "/private/tmp/ice_demo/foo/src/lib.rs", begin: (1, 0), end: (1, 15) }), visibility: Public, docs: None, links: {}, attrs: ["#[doc(inline)]"], deprecation: None, inner: Struct(Struct { struct_type: Unit, generics: Generics { params: [], where_predicates: [] }, fields_stripped: false, fields: [], impls: [] }) }`', src/librustdoc/json/mod.rs:175:17
The difference is one has attrs: []
and the other has attrs: ["#[doc(inline)]"]
.
This occors as foo::Foo
is used twice, once with and once without #[doc(inline)]
Non ICE versions
Import from local
When foo
is a internal module and not a crate, this works
mod foo {
pub struct Foo;
}
#[doc(inline)]
pub use foo::Foo;
pub mod bar {
pub use crate::foo::Foo;
}
JSON output (redacted for clarity)
{
"index": {
"0:0": {
"attrs": ["#![feature(no_core)]", "#![no_core]"],
"inner": {"is_crate": true, "items": ["0:5", "0:2"]},
"kind": "module",
"name": "ice_demo"
},
"0:2": {
"attrs": [],
"kind": "struct",
"name": "Foo"
},
"0:5": {
"attrs": [],
"inner": {"is_crate": false, "items": ["0:2"]},
"kind": "module",
"name": "bar"
}
},
"paths": {
"0:0": {"crate_id": 0, "kind": "module", "path": ["ice_demo"]},
"0:2": {"crate_id": 0, "kind": "struct", "path": ["ice_demo", "bar", "Foo"]},
"0:5": {"crate_id": 0, "kind": "module", "path": ["ice_demo", "bar"]}
},
"root": "0:0"
}
Here we drop the #[doc(inline)]
, which is probably wrong.
This is actualy correct,
Import only once
#[doc(inline)]
pub use foo::Foo;
JSON output
{
"crate_version": "0.1.0",
"external_crates": {"1": {"html_root_url": null, "name": "foo"}},
"format_version": 4,
"includes_private": false,
"index": {
"0:0": {
"attrs": ["#![no_core]", "#![feature(no_core)]"],
"inner": {"is_crate": true, "items": ["1:1"]},
"kind": "module",
"name": "ice_demo"
},
"0:1": {
"attrs": ["#[doc(inline)]"],
"inner": {"glob": false, "id": "1:1", "name": "Foo", "span": "foo::Foo"},
"kind": "import"
},
"1:1": {
"attrs": ["#[doc(inline)]"],
"kind": "struct",
"links": {},
"name": "Foo"
}
},
"paths": {
"0:0": {"crate_id": 0, "kind": "module", "path": ["ice_demo"]},
"1:0": {"crate_id": 1, "kind": "module", "path": ["foo"]},
"1:1": {"crate_id": 1, "kind": "struct", "path": ["foo", "Foo"]}
},
"root": "0:0"
}
This is also wrong, as id 0:1
is not referenced anywhere, and 1:1
is given #[doc(inline)]
, even though it should have it.
@rustbot modify labels: +C-bug +A-rustdoc-json +T-rustdoc +A-attributes