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 doesn't work #5

Closed
aDotInTheVoid opened this issue Dec 4, 2020 · 9 comments
Closed

Rustdoc json doesn't work #5

aDotInTheVoid opened this issue Dec 4, 2020 · 9 comments

Comments

@aDotInTheVoid
Copy link
Owner

58c4024 panics
41f76da is fine

@aDotInTheVoid
Copy link
Owner Author

0d88d82 is fine
cae2d30 panics

cargo +stage1 rustdoc -vv -- --output-format json

@aDotInTheVoid
Copy link
Owner Author

[src/librustdoc/json/mod.rs:228] &output.index.get(&output.root).unwrap() = Item {
    id: Id(
        "0:0",
    ),
    crate_id: 0,
    name: None,
    source: Some(
        Span {
            filename: "src/html_render/content/mod.rs",
            begin: (
                10,
                0,
            ),
            end: (
                10,
                22,
            ),
        },
    ),
    visibility: Public,
    docs: "",
    links: {},
    attrs: [],
    deprecation: None,
    kind: Import,
    inner: ImportItem(
        Import {
            span: "collect::Dirs",
            name: "Dirs",
            id: Some(
                Id(
                    "0:562",
                ),
            ),
            glob: false,
        },
    ),
}

The thing is expected name to be Some here

@aDotInTheVoid
Copy link
Owner Author

Turns out this change is needed. I removed it in my PR, as I didn't understand, but it's nessesary

@aDotInTheVoid
Copy link
Owner Author

I'm pritty sure this has the wrong ID, as 0:0 should be the root.

@aDotInTheVoid
Copy link
Owner Author

eca9ecf panics
a3cb263 is fine

@aDotInTheVoid
Copy link
Owner Author

aDotInTheVoid commented Dec 4, 2020

A reproduction

pub mod l1 {
    pub mod l3 {
        pub struct L4;
    }
    pub use l3::L4;
}
rustdoc +stage1 src/lib.rs --edition 2018 --output-format json

@aDotInTheVoid
Copy link
Owner Author

aDotInTheVoid commented Dec 4, 2020

```rust Item { source: Span { filename: Real( Named( "egg.rs", ), ), cnum: crate0, loline: 7, locol: 4, hiline: 7, hicol: 19, original: Span { lo: BytePos( 65, ), hi: BytePos( 80, ), ctxt: #0, }, }, name: None, attrs: Attributes { doc_strings: [], other_attrs: [], cfg: None, span: None, links: [], inner_docs: true, }, kind: ImportItem( Import { kind: Simple( "L4", ), source: ImportSource { path: Path { global: false, res: Def( Struct, DefId(0:5), ), segments: [ PathSegment { name: "l3", args: AngleBracketed { args: [], bindings: [], }, }, PathSegment { name: "L4", args: AngleBracketed { args: [], bindings: [], }, }, ], }, did: Some( DefId(0:5), ), }, should_be_displayed: true, }, ), visibility: Public, def_id: DefId(0:0), stability: None, deprecation: None, } Item { source: Span { filename: Real( Named( "egg.rs", ), ), cnum: crate0, loline: 3, locol: 0, hiline: 8, hicol: 1, original: Span { lo: BytePos( 2, ), hi: BytePos( 82, ), ctxt: #0, }, }, name: Some( "egg", ), attrs: Attributes { doc_strings: [], other_attrs: [], cfg: None, span: None, links: [], inner_docs: true, }, kind: ModuleItem( Module { items: [ Item { source: Span { filename: Real( Named( "egg.rs", ), ), cnum: crate0, loline: 3, locol: 0, hiline: 8, hicol: 1, original: Span { lo: BytePos( 2, ), hi: BytePos( 82, ), ctxt: #0, }, }, name: Some( "l1", ), attrs: Attributes { doc_strings: [], other_attrs: [], cfg: None, span: None, links: [], inner_docs: true, }, kind: ModuleItem( Module { items: [ Item { source: Span { filename: Real( Named( "egg.rs", ), ), cnum: crate0, loline: 7, locol: 4, hiline: 7, hicol: 19, original: Span { lo: BytePos( 65, ), hi: BytePos( 80, ), ctxt: #0, }, }, name: None, attrs: Attributes { doc_strings: [], other_attrs: [], cfg: None, span: None, links: [], inner_docs: true, }, kind: ImportItem( Import { kind: Simple( "L4", ), source: ImportSource { path: Path { global: false, res: Def( Struct, DefId(0:5), ), segments: [ PathSegment { name: "l3", args: AngleBracketed { args: [], bindings: [], }, }, PathSegment { name: "L4", args: AngleBracketed { args: [], bindings: [], }, }, ], }, did: Some( DefId(0:5), ), }, should_be_displayed: true, }, ), visibility: Public, def_id: DefId(0:0), stability: None, deprecation: None, }, Item { source: Span { filename: Real( Named( "egg.rs", ), ), cnum: crate0, loline: 4, locol: 4, hiline: 6, hicol: 5, original: Span { lo: BytePos( 19, ), hi: BytePos( 60, ), ctxt: #0, }, }, name: Some( "l3", ), attrs: Attributes { doc_strings: [], other_attrs: [], cfg: None, span: None, links: [], inner_docs: true, }, kind: ModuleItem( Module { items: [ Item { source: Span { filename: Real( Named( "egg.rs", ), ), cnum: crate0, loline: 5, locol: 8, hiline: 5, hicol: 22, original: Span { lo: BytePos( 40, ), hi: BytePos( 54, ), ctxt: #0, }, }, name: Some( "L4", ), attrs: Attributes { doc_strings: [], other_attrs: [], cfg: None, span: None, links: [], inner_docs: true, }, kind: StructItem( Struct { struct_type: Unit, generics: Generics { params: [], where_predicates: [], }, fields: [], fields_stripped: false, }, ), visibility: Public, def_id: DefId(0:5), stability: None, deprecation: None, }, ], is_crate: false, }, ), visibility: Public, def_id: DefId(0:4), stability: None, deprecation: None, }, ], is_crate: false, }, ), visibility: Public, def_id: DefId(0:3), stability: None, deprecation: None, }, ], is_crate: true, }, ), visibility: Public, def_id: DefId(0:0), stability: None, deprecation: None, } Item { source: Span { filename: Real( Named( "egg.rs", ), ), cnum: crate0, loline: 7, locol: 4, hiline: 7, hicol: 19, original: Span { lo: BytePos( 65, ), hi: BytePos( 80, ), ctxt: #0, }, }, name: None, attrs: Attributes { doc_strings: [], other_attrs: [], cfg: None, span: None, links: [], inner_docs: true, }, kind: ImportItem( Import { kind: Simple( "L4", ), source: ImportSource { path: Path { global: false, res: Def( Struct, DefId(0:5), ), segments: [ PathSegment { name: "l3", args: AngleBracketed { args: [], bindings: [], }, }, PathSegment { name: "L4", args: AngleBracketed { args: [], bindings: [], }, }, ], }, did: Some( DefId(0:5), ), }, should_be_displayed: true, }, ), visibility: Public, def_id: DefId(0:0), stability: None, deprecation: None, } Item { source: Span { filename: Real( Named( "egg.rs", ), ), cnum: crate0, loline: 7, locol: 4, hiline: 7, hicol: 19, original: Span { lo: BytePos( 65, ), hi: BytePos( 80, ), ctxt: #0, }, }, name: None, attrs: Attributes { doc_strings: [], other_attrs: [], cfg: None, span: None, links: [], inner_docs: true, }, kind: ImportItem( Import { kind: Simple( "L4", ), source: ImportSource { path: Path { global: false, res: Def( Struct, DefId(0:5), ), segments: [ PathSegment { name: "l3", args: AngleBracketed { args: [], bindings: [], }, }, PathSegment { name: "L4", args: AngleBracketed { args: [], bindings: [], }, }, ], }, did: Some( DefId(0:5), ), }, should_be_displayed: true, }, ), visibility: Public, def_id: DefId(0:0), stability: None, deprecation: None, }

@aDotInTheVoid
Copy link
Owner Author

Rustc Patch

diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index 8c344338de7..4418a4f3864 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -2263,7 +2263,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Vec<Item> {
             name: None,
             attrs: self.attrs.clean(cx),
             source: self.span.clean(cx),
-            def_id: DefId::local(CRATE_DEF_INDEX),
+            def_id: cx.tcx.hir().local_def_id(self.id).to_def_id(), 
             visibility: self.vis.clean(cx),
             stability: None,
             const_stability: None,
diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs
index c080ad21c0f..38f40ac143c 100644
--- a/src/librustdoc/json/mod.rs
+++ b/src/librustdoc/json/mod.rs
@@ -151,7 +151,11 @@ fn item(&mut self, item: clean::Item, cache: &Cache) -> Result<(), Error> {
             } else if let types::ItemEnum::EnumItem(ref mut e) = new_item.inner {
                 e.impls = self.get_impls(id, cache)
             }
-            self.index.borrow_mut().insert(id.into(), new_item);
+            let res = self.index.borrow_mut().insert(id.into(), new_item.clone());
+
+            if let Some(res) = res {
+                dbg!((id, res == new_item));
+            }
         }
 
         Ok(())

Egg.rs

pub mod l1 {
    pub mod l3 {
        pub struct L4;
    }
    pub use l3::L4;
}
rustdoc +stage1 egg.rs --output-format json --edition 2018
Output (all true) ``` [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:7), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:7), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:10), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:11), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:12), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:14), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:15), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:5), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:4), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:3), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:10), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:11), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:12), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:14), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:15), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:5), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:4), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:10), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:11), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:12), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:14), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:15), true, ) [src/librustdoc/json/mod.rs:157] (id, res == new_item) = ( DefId(0:5), true, ) ```

@aDotInTheVoid
Copy link
Owner Author

Closed by rust-lang/rust#79751

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant