aDotInTheVoid / xmark

GNU General Public License v3.0
0 stars 0 forks source link

Rustdoc json doesn't work #5

Closed aDotInTheVoid closed 3 years ago

aDotInTheVoid commented 3 years ago

58c4024bf0eb2f908492272aab57525c924750f3 panics 41f76da920fcd9ed80f35186373feb93d654562a is fine

aDotInTheVoid commented 3 years ago

0d88d824 is fine cae2d308 panics

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

aDotInTheVoid commented 3 years ago
[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 commented 3 years ago

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

aDotInTheVoid commented 3 years ago

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

aDotInTheVoid commented 3 years ago

eca9ecf0 panics a3cb263388c3cc32efa4570dc51d75b66da86d3a is fine

aDotInTheVoid commented 3 years ago

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 commented 3 years ago
```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 commented 3 years ago

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 commented 3 years ago

Closed by https://github.com/rust-lang/rust/pull/79751