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 when same item is represented in different ways #97986

Closed
Enselic opened this issue Jun 11, 2022 · 1 comment · Fixed by #98053
Closed

rustdoc-json: ICE when same item is represented in different ways #97986

Enselic opened this issue Jun 11, 2022 · 1 comment · Fixed by #98053
Labels
A-rustdoc-json Area: Rustdoc JSON backend glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@Enselic
Copy link
Member

Enselic commented Jun 11, 2022

Minimal reproducer:

// src/lib.rs

pub mod m {
    pub struct S;
}

pub trait F {
    fn f() -> m::S;
}

impl<T> F for T {
    fn f() -> m::S {
        m::S
    }
}
% RUSTDOCFLAGS='-Z unstable-options --output-format json' cargo +nightly doc --lib --no-deps
thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `Item { id: Id("0:10:601"), crate_id: 0, name: Some("f"), span: Some(Span { filename: "src/lib.rs", begin: (10, 4), end: (12, 5) }), visibility: Default, docs: None, links: {}, attrs: [], deprecation: None, inner: Method(Method { decl: FnDecl { inputs: [], output: Some(ResolvedPath { name: "S", id: Id("0:4:1544"), args: Some(AngleBracketed { args: [], bindings: [] }), param_names: [] }), c_variadic: false }, generics: Generics { params: [], where_predicates: [] }, header: Header { const_: false, unsafe_: false, async_: false, abi: Rust }, has_body: true }) }`,
 right: `Item { id: Id("0:10:601"), crate_id: 0, name: Some("f"), span: Some(Span { filename: "src/lib.rs", begin: (10, 4), end: (12, 5) }), visibility: Default, docs: None, links: {}, attrs: [], deprecation: None, inner: Method(Method { decl: FnDecl { inputs: [], output: Some(ResolvedPath { name: "m::S", id: Id("0:4:1544"), args: Some(AngleBracketed { args: [], bindings: [] }), param_names: [] }), c_variadic: false }, generics: Generics { params: [], where_predicates: [] }, header: Header { const_: false, unsafe_: false, async_: false, abi: Rust }, has_body: true }) }`', src/librustdoc/json/mod.rs:202:17

The panic happens because ResolvedPath { name: "S" != ResolvedPath { name: "m::S", but they are of course equivalent, so we should not panic because of that.

This is (at least partially) a minimal reproducer for #93588.

@rustbot labels +A-rustdoc-json +I-ICE +T-rustdoc

@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jun 11, 2022
@Enselic Enselic changed the title rustdoc-json: ICE when equivalent items is represented in different ways rustdoc-json: ICE when equivalent item is represented in different ways Jun 11, 2022
@Enselic Enselic changed the title rustdoc-json: ICE when equivalent item is represented in different ways rustdoc-json: ICE when same item is represented in different ways Jun 11, 2022
matthiaskrgr added a commit to matthiaskrgr/glacier that referenced this issue Jun 11, 2022
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jun 11, 2022
@GuillaumeGomez
Copy link
Member

In this case, the problem is that the generic impl (and therefore its method) has the same DefId for all types (because it's implemented on all of them). In this case I think it's fine to just ignore it as it's the same method in any case.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jun 13, 2022
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jun 15, 2022
…n-ice, r=notriddle

Fix generic impl rustdoc json output

Fixes rust-lang#97986.

The problem in case of generic trait impl is that the trait's items are the same for all the types afterward. But since they're the same, it's safe for rustdoc-json to just ignore them.

A little representation of what's going on:

```rust
trait T {
    fn f(); // <- defid 0
}

impl<Y> T for Y {
    fn f() {} // <- defid 1
}

struct S; // <- defid 1 (since it matches `impl<Y> T for Y`
```

cc `@Urgau`

r? `@CraftSpider`
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jun 15, 2022
…n-ice, r=notriddle

Fix generic impl rustdoc json output

Fixes rust-lang#97986.

The problem in case of generic trait impl is that the trait's items are the same for all the types afterward. But since they're the same, it's safe for rustdoc-json to just ignore them.

A little representation of what's going on:

```rust
trait T {
    fn f(); // <- defid 0
}

impl<Y> T for Y {
    fn f() {} // <- defid 1
}

struct S; // <- defid 1 (since it matches `impl<Y> T for Y`
```

cc ``@Urgau``

r? ``@CraftSpider``
@bors bors closed this as completed in 4ee78a6 Jun 16, 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 glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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.

4 participants