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] Assertion error on blanket impls #83718

Closed
aDotInTheVoid opened this issue Mar 31, 2021 · 2 comments · Fixed by #93169
Closed

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

aDotInTheVoid opened this issue Mar 31, 2021 · 2 comments · Fixed by #93169
Labels
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

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

@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Mar 31, 2021
@jyn514
Copy link
Member

jyn514 commented Mar 31, 2021

MCVE:

pub trait Load {
    fn load() {}
}

impl<P> Load for P {
    fn load() {}
}

pub struct Wrapper {}

One has output: None while the other has output: Some(Tuple([])) - I bet one is going through HIR and the other is going through metadata, that could explain why the generic parameter matters.

@jyn514 jyn514 changed the title [rustdoc-json] Assertion error on traits [rustdoc-json] Assertion error on blanket impls Apr 16, 2021
@camelid camelid added the C-bug Category: This is a bug. label Sep 1, 2021
@philippeitis
Copy link
Contributor

philippeitis commented Nov 1, 2021

I have a similar MCVE generated from unicode-normalization v0.1.19, but the only item that differs in the assertion is the visibility:

pub struct A {}

pub trait X {
    fn do_thing() -> A;
}

impl<I> X for I {
    fn do_thing() -> A {
        unimplemented!()
    }
}
thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `Item { id: Id("0:8"), crate_id: 0, name: Some("do_thing"), span: Some(Span { filename: "src/lib.rs", begin: (18, 4), end: (20, 5) }), visibility: Public, docs: None, links: {}, attrs: [], deprecation: None, inner: Method(Method { decl: FnDecl { inputs: [], output: Some(ResolvedPath { name: "A", id: Id("0:3"), args: Some(AngleBracketed { args: [], bindings: [] }), param_names: [] }), c_variadic: false }, generics: Generics { params: [], where_predicates: [] }, header: {}, abi: "\"Rust\"", has_body: true }) }`,
 right: `Item { id: Id("0:8"), crate_id: 0, name: Some("do_thing"), span: Some(Span { filename: "src/lib.rs", begin: (18, 4), end: (20, 5) }), visibility: Default, docs: None, links: {}, attrs: [], deprecation: None, inner: Method(Method { decl: FnDecl { inputs: [], output: Some(ResolvedPath { name: "A", id: Id("0:3"), args: Some(AngleBracketed { args: [], bindings: [] }), param_names: [] }), c_variadic: false }, generics: Generics { params: [], where_predicates: [] }, header: {}, abi: "\"Rust\"", has_body: true }) }`', src/librustdoc/json/mod.rs:195:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The left has a visibility of Public, and the right has a visibility of Default.

A similar MCVE, with self as a parameter, has self as an input for the right side, but not for the left (and the Public/Default visibility issue):

pub struct A {}

pub trait X {
    fn do_thing(self) -> A;
}

impl<I> X for I {
    fn do_thing(self) -> A {
        unimplemented!()
    }
}
thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `Item { id: Id("0:8"), crate_id: 0, name: Some("do_thing"), span: Some(Span { filename: "src/lib.rs", begin: (18, 4), end: (20, 5) }), visibility: Public, docs: None, links: {}, attrs: [], deprecation: None, inner: Method(Method { decl: FnDecl { inputs: [("", Generic("Self"))], output: Some(ResolvedPath { name: "A", id: Id("0:3"), args: Some(AngleBracketed { args: [], bindings: [] }), param_names: [] }), c_variadic: false }, generics: Generics { params: [], where_predicates: [] }, header: {}, abi: "\"Rust\"", has_body: true }) }`,
 right: `Item { id: Id("0:8"), crate_id: 0, name: Some("do_thing"), span: Some(Span { filename: "src/lib.rs", begin: (18, 4), end: (20, 5) }), visibility: Default, docs: None, links: {}, attrs: [], deprecation: None, inner: Method(Method { decl: FnDecl { inputs: [("self", Generic("Self"))], output: Some(ResolvedPath { name: "A", id: Id("0:3"), args: Some(AngleBracketed { args: [], bindings: [] }), param_names: [] }), c_variadic: false }, generics: Generics { params: [], where_predicates: [] }, header: {}, abi: "\"Rust\"", has_body: true }) }`', src/librustdoc/json/mod.rs:195:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 20, 2022
…r=jsha

Fix errors on blanket impls by ignoring the children of generated impls

Related to rust-lang#83718

We can safely skip the children, as they don't contain any new info, and may be subtly different for reasons hard to track down, in ways that are consistently worse than the actual generic impl.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 25, 2022
…ency, r=GuillaumeGomez

Fix inconsistency of local blanket impls

When a blanket impl is local, go through HIR instead of middle. This fixes inconsistencies with data detected during JSON generation.

Expected this change to take longer. I also tried doing the whole item through existing clean architecture, but it didn't work out trivially, and felt like it would have added more complexity than it removed.

Properly fixes rust-lang#83718
@bors bors closed this as completed in 677126c Jan 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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
Development

Successfully merging a pull request may close this issue.

6 participants