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-json] ICE/incorect results when reexporting with #[doc(inline)] #83057

Closed
aDotInTheVoid opened this issue Mar 12, 2021 · 1 comment · Fixed by #99287
Closed

[rustdoc-json] ICE/incorect results when reexporting with #[doc(inline)] #83057

aDotInTheVoid opened this issue Mar 12, 2021 · 1 comment · Fixed by #99287
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustdoc-json Area: Rustdoc JSON backend C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@aDotInTheVoid
Copy link
Member

aDotInTheVoid commented Mar 12, 2021

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.

cc @CraftSpider @P1n3appl3

@rustbot modify labels: +C-bug +A-rustdoc-json +T-rustdoc +A-attributes

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustdoc-json Area: Rustdoc JSON backend C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Mar 12, 2021
@aDotInTheVoid
Copy link
Member Author

aDotInTheVoid commented Mar 19, 2021

The import only once case also has the unreference item without #[doc(inline)]

And the reason for the ICE in the first report is attrs: ["#[doc(inline)]"] is being applyed to 1:1, which conflicts when it is used without being inlined.

The Unreferenced 0:1 is a entirely seperate issue (it appears)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustdoc-json Area: Rustdoc JSON backend C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
3 participants