Skip to content

cargo rustdoc -- --output-format json now says a tuple variant is a struct variant #87887

Closed

Description

@dsherret

Note the current type of Variant in rustdoc-json-types:

pub enum Variant {
Plain,
Tuple(Vec<Type>),
Struct(Vec<Id>),
}

Code

I tried this code:

pub enum MyEnum {
    Variant(MyStruct),
}

pub struct MyStruct {
}

And ran this:

cargo +nightly rustdoc -- --output-format json -Z unstable-options 

I expected to see this happen (or something along these lines saying it's a tuple variant):

    "0:3": {
      "id": "0:3",
      "crate_id": 0,
      "name": "MyEnum",
      "span": { "filename": "src\\lib.rs", "begin": [1, 0], "end": [3, 1] },
      "visibility": "public",
      "docs": null,
      "links": {},
      "attrs": [],
      "deprecation": null,
      "kind": "enum",
      "inner": {
        "generics": { "params": [], "where_predicates": [] },
        "variants_stripped": false,
        "variants": ["0:4"],
        "impls": [
          "F0:0",
          "F0:1",
          "F0:2",
          "F0:4",
          "F0:5",
          "F0:6",
          "F0:7",
          "F0:8",
          "F0:9",
          "F0:10",
          "F0:11",
          "F0:12"
        ]
      }
    },
    "0:4": {
      "id": "0:4",
      "crate_id": 0,
      "name": "Variant",
      "span": { "filename": "src\\lib.rs", "begin": [2, 4], "end": [2, 21] },
      "visibility": "default",
      "docs": null,
      "links": {},
      "attrs": [],
      "deprecation": null,
      "kind": "variant",
      "inner": {
        "variant_kind": "tuple",
        "variant_inner": [
          {
            "kind": "resolved_path",
            "inner": {
              "name": "MyStruct",
              "id": "0:7",
              "args": { "angle_bracketed": { "args": [], "bindings": [] } },
              "param_names": []
            }
          }
        ]
      }
    }

Instead, this happened:

    "0:3": {
      "id": "0:3",
      "crate_id": 0,
      "name": "MyEnum",
      "span": { "filename": "src\\lib.rs", "begin": [1, 0], "end": [3, 1] },
      "visibility": "public",
      "docs": null,
      "links": {},
      "attrs": [],
      "deprecation": null,
      "kind": "enum",
      "inner": {
        "generics": { "params": [], "where_predicates": [] },
        "variants_stripped": false,
        "variants": ["0:4"],
        "impls": [
          "a:2:2881-0:3",
          "a:2:2893-0:3",
          "a:2:2922-0:3",
          "a:1:5759-0:3",
          "a:1:5760-0:3",
          "b:2:2814-0:3",
          "b:2:2810-0:3",
          "b:2:2825-0:3",
          "b:2:2820-0:3",
          "b:2:2486-0:3",
          "b:2:2489-0:3",
          "b:2:3546-0:3"
        ]
      }
    },
    "0:4": {
      "id": "0:4",
      "crate_id": 0,
      "name": "Variant",
      "span": { "filename": "src\\lib.rs", "begin": [2, 4], "end": [2, 21] },
      "visibility": "default",
      "docs": null,
      "links": {},
      "attrs": [],
      "deprecation": null,
      "kind": "variant",
      "inner": { "variant_kind": "struct", "variant_inner": ["0:6"] }
    },

Another Example

Here's a more complicated example:

pub enum MyEnum {
    Variant(MyStruct<String>, MyStruct<String>),
}

pub struct MyStruct<T> {
    pub value: T,
}

Outputs:

    "0:3": {
      "id": "0:3",
      "crate_id": 0,
      "name": "MyEnum",
      "span": { "filename": "src\\lib.rs", "begin": [1, 0], "end": [3, 1] },
      "visibility": "public",
      "docs": null,
      "links": {},
      "attrs": [],
      "deprecation": null,
      "kind": "enum",
      "inner": {
        "generics": { "params": [], "where_predicates": [] },
        "variants_stripped": false,
        "variants": ["0:4"],
        "impls": [
          "a:2:2881-0:3",
          "a:2:2893-0:3",
          "a:2:2922-0:3",
          "a:1:5759-0:3",
          "a:1:5760-0:3",
          "b:2:2814-0:3",
          "b:2:2810-0:3",
          "b:2:2825-0:3",
          "b:2:2820-0:3",
          "b:2:2486-0:3",
          "b:2:2489-0:3",
          "b:2:3546-0:3"
        ]
      }
    },
    "0:4": {
      "id": "0:4",
      "crate_id": 0,
      "name": "Variant",
      "span": { "filename": "src\\lib.rs", "begin": [2, 4], "end": [2, 47] },
      "visibility": "default",
      "docs": null,
      "links": {},
      "attrs": [],
      "deprecation": null,
      "kind": "variant",
      "inner": { "variant_kind": "struct", "variant_inner": ["0:6", "0:7"] }
    },
    "0:6": {
      "id": "0:6",
      "crate_id": 0,
      "name": "0",
      "span": { "filename": "src\\lib.rs", "begin": [2, 12], "end": [2, 28] },
      "visibility": "default",
      "docs": null,
      "links": {},
      "attrs": [],
      "deprecation": null,
      "kind": "struct_field",
      "inner": {
        "kind": "resolved_path",
        "inner": {
          "name": "MyStruct",
          "id": "0:8",
          "args": {
            "angle_bracketed": {
              "args": [
                {
                  "type": {
                    "kind": "resolved_path",
                    "inner": {
                      "name": "String",
                      "id": "5:7431",
                      "args": {
                        "angle_bracketed": { "args": [], "bindings": [] }
                      },
                      "param_names": []
                    }
                  }
                }
              ],
              "bindings": []
            }
          },
          "param_names": []
        }
      }
    },
    "0:7": {
      "id": "0:7",
      "crate_id": 0,
      "name": "1",
      "span": { "filename": "src\\lib.rs", "begin": [2, 30], "end": [2, 46] },
      "visibility": "default",
      "docs": null,
      "links": {},
      "attrs": [],
      "deprecation": null,
      "kind": "struct_field",
      "inner": {
        "kind": "resolved_path",
        "inner": {
          "name": "MyStruct",
          "id": "0:8",
          "args": {
            "angle_bracketed": {
              "args": [
                {
                  "type": {
                    "kind": "resolved_path",
                    "inner": {
                      "name": "String",
                      "id": "5:7431",
                      "args": {
                        "angle_bracketed": { "args": [], "bindings": [] }
                      },
                      "param_names": []
                    }
                  }
                }
              ],
              "bindings": []
            }
          },
          "param_names": []
        }
      }
    }

Version it worked on

It most recently worked on: nightly-2021-06-27 -- I did not do any tests for the specific version it started failing in

Version with regression

rustc +nightly --version --verbose:

rustc 1.56.0-nightly (ad981d58e 2021-08-08)
binary: rustc
commit-hash: ad981d58e1ca16bcf4072577934630deb11c5e14
commit-date: 2021-08-08
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 12.0.1

Activity

  1. added
    C-bugCategory: This is a bug.
    regression-untriagedUntriaged performance or correctness regression.
    on Aug 9, 2021
  2. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Aug 9, 2021
  3. added
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    on Aug 9, 2021
  4. added
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    on Aug 9, 2021
  5. camelid commented on Aug 9, 2021

    @camelid
    Member

    Regression occurred sometime between nightly-2021-07-28 and nightly-2021-08-08, and #87451 seems likely to be the cause anyway.

  6. added and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    regression-untriagedUntriaged performance or correctness regression.
    on Aug 9, 2021
  7. added a commit that references this issue on Aug 31, 2021
    f4f5dd5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions