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: impl dyn Trait gets discarded #133719

Open
aDotInTheVoid opened this issue Dec 1, 2024 · 1 comment
Open

rustdoc-json: impl dyn Trait gets discarded #133719

aDotInTheVoid opened this issue Dec 1, 2024 · 1 comment
Labels
A-rustdoc-json Area: Rustdoc JSON backend A-trait-objects Area: trait objects, vtable layout 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

For the following code:

pub trait T1 {
    fn number(&self) -> i32;
}

impl dyn T1 {
    pub fn number_plus_one(&self) {
        self.number() + 1
    }
}

generates

{
  "format_version": 36,
  "includes_private": false,
  "index": {
    "0": {
      "attrs": [],
      "crate_id": 0,
      "deprecation": null,
      "docs": null,
      "id": 0,
      "inner": {"function": { ... }},
      "name": "number",
      "visibility": "default"
    },
    "1": {
      "attrs": [],
      "crate_id": 0,
      "deprecation": null,
      "docs": null,
      "id": 1,
      "inner": {
        "trait": {
          "bounds": [],
          "generics": {"params": [], "where_predicates": []},
          "implementations": [],
          "is_auto": false,
          "is_dyn_compatible": true,
          "is_unsafe": false,
          "items": [0]
        }
      },
      "name": "T1",
      "visibility": "public"
    },
    "2": {
      "attrs": [],
      "crate_id": 0,
      "deprecation": null,
      "docs": null,
      "id": 2,
      "inner": {"module": {"is_crate": true, "is_stripped": false, "items": [1]}},
      "name": "on_dyn_trait",
      "visibility": "public"
    }
  },
  "root": 2
}

(full).

There's nothing included for the number_plus_one method, but there should be.

The HTML backend get this right, so the releavent info is availible in clean:

Image

I'm not sure what's the best way to store this is in the format: Putting it into the implementations field seems wrong, as impl dyn T1 isn't an implementation of T1, but an implementation on dyn T1. I'd love to hear people's thoughts on this.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 1, 2024
@aDotInTheVoid aDotInTheVoid added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-rustdoc-json Area: Rustdoc JSON backend and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 1, 2024
@obi1kenobi
Copy link
Member

obi1kenobi commented Dec 2, 2024

I'd expect a few things to happen in the rustdoc JSON here:

  • an impl item corresponding to the impl dyn T1 block
  • that impl item containing a number_plus_one function ("method") item
  • some form of "relationship" from T1 to impl dyn T1, which isn't the implementations field but something else.

Ideally, the approach would rhyme with how we represent other edge cases like impl .. for &mut:

pub trait T1 {}

struct Example;

impl T1 for Example {}

// This impl is unrelated to the one above, and isn't technically on `Example`!
// And yet it's related to `Example` so it probably should be linked
// from the `Example` item in some manner.
impl T1 for &mut Example {}

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Dec 2, 2024
…laumeGomez

rustdoc-json: Add test for `impl Trait for dyn Trait`

Found while investigating rust-lang#133719

Helps with rust-lang#81359

r? `@GuillaumeGomez`
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 2, 2024
Rollup merge of rust-lang#133721 - aDotInTheVoid:rdj-dyn-link, r=GuillaumeGomez

rustdoc-json: Add test for `impl Trait for dyn Trait`

Found while investigating rust-lang#133719

Helps with rust-lang#81359

r? `@GuillaumeGomez`
@fmease fmease added A-trait-objects Area: trait objects, vtable layout C-bug Category: This is a bug. labels Dec 6, 2024
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 A-trait-objects Area: trait objects, vtable layout 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

No branches or pull requests

4 participants