Skip to content

[rustdoc-json] Assertion error on blanket impls #83718

Closed
@aDotInTheVoid

Description

@aDotInTheVoid
pub trait Get {
    type Target;
    fn get(&self) -> &Self::Target;
}

pub trait LoadNum {
    fn load_num(&self) -> i32;
}

impl<A: LoadNum, P: Get<Target = A>> LoadNum for P {
    fn load_num(&self) -> i32 {
        self.get().load_num()
    }
}

pub struct Wrapper<T>(T);
impl<T> Get for Wrapper<T> {
    type Target = T;
    fn get(&self) -> &T {
        &self.0
    }
}

rustdoc +stage1 trait.rs -w json

thread 'rustc' panicked at 'assertion failed: `(left == right)`

Diff < left / right > :
 Item {
     id: Id(
         "0:11",
     ),
     crate_id: 0,
     name: Some(
         "load_num",
     ),
     span: Some(
         Span {
             filename: "trait.rs",
             begin: (
                 11,
                 4,
             ),
             end: (
                 13,
                 5,
             ),
         },
     ),
<    visibility: Default,
>    visibility: Public,
     docs: None,
     links: {},
     attrs: [],
     deprecation: None,
     inner: Method(
         Method {
             decl: FnDecl {
                 inputs: [
                     (
<                        "self",
>                        "",
                         BorrowedRef {
                             lifetime: None,
                             mutable: false,
                             type_: Generic(
                                 "Self",
                             ),
                         },
                     ),
                 ],
                 output: Some(
                     Primitive(
                         "i32",
                     ),
                 ),
                 c_variadic: false,
             },
             generics: Generics {
                 params: [],
                 where_predicates: [],
             },
             header: {},
             abi: "\"Rust\"",
             has_body: true,
         },
     ),
 }

', src/librustdoc/json/mod.rs:179:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Interesingly, and shockingly If you remove pub struct Wrapper<T>(T); and impl<T> Get for Wrapper<T>, this doesn't panic.

rustdoc +stage1 --version --verbose
rustdoc 1.53.0-nightly (a5029ac0a 2021-03-31)
binary: rustdoc
commit-hash: a5029ac0ab372aec515db2e718da6d7787f3d122
commit-date: 2021-03-31
host: x86_64-unknown-linux-gnu
release: 1.53.0-nightly
LLVM version: 12.0.0
Whats up with the diff?

The assetion format is differnt to usual as I've patch rustc with

diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs
index db3a0c5ceb1..434286e72f9 100644
--- a/src/librustdoc/json/mod.rs
+++ b/src/librustdoc/json/mod.rs
@@ -176,7 +176,7 @@ fn item(&mut self, item: clean::Item) -> Result<(), Error> {
             // to make sure the items are unique. The main place this happens is when an item, is
             // reexported in more than one place. See `rustdoc-json/reexport/in_root_and_mod`
             if let Some(old_item) = removed {
-                assert_eq!(old_item, new_item);
+                pretty_assertions::assert_eq!(old_item, new_item);
             }
         }

to make it readable, but this can also be repoduced with the latest nightly

rustdoc +nightly trait.rs -w json 
thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `Item { id: Id("0:11"), crate_id: 0, name: Some("load_num"), span: Some(Span { filename: "trait.rs", begin: (11, 4), end: (13, 5) }), visibility: Default, docs: None, links: {}, attrs: [], deprecation: None, inner: Method(Method { decl: FnDecl { inputs: [("self", BorrowedRef { lifetime: None, mutable: false, type_: Generic("Self") })], output: Some(Primitive("i32")), c_variadic: false }, generics: Generics { params: [], where_predicates: [] }, header: {}, abi: "\"Rust\"", has_body: true }) }`,
 right: `Item { id: Id("0:11"), crate_id: 0, name: Some("load_num"), span: Some(Span { filename: "trait.rs", begin: (11, 4), end: (13, 5) }), visibility: Public, docs: None, links: {}, attrs: [], deprecation: None, inner: Method(Method { decl: FnDecl { inputs: [("", BorrowedRef { lifetime: None, mutable: false, type_: Generic("Self") })], output: Some(Primitive("i32")), c_variadic: false }, generics: Generics { params: [], where_predicates: [] }, header: {}, abi: "\"Rust\"", has_body: true }) }`', src/librustdoc/json/mod.rs:175:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

error: Unrecognized option: 'w'
rustdoc 1.53.0-nightly (07e0e2ec2 2021-03-24)
binary: rustdoc
commit-hash: 07e0e2ec268c140e607e1ac7f49f145612d0f597
commit-date: 2021-03-24
host: x86_64-unknown-linux-gnu
release: 1.53.0-nightly
LLVM version: 12.0.0

@rustbot modify labels: +A-rustdoc-json +T-rustdoc

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-rustdoc-jsonArea: Rustdoc JSON backendC-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions