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

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

Closed
dsherret opened this issue Aug 9, 2021 · 1 comment · Fixed by #88391
Closed
Assignees
Labels
A-rustdoc-json Area: Rustdoc JSON backend C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. requires-nightly This issue requires a nightly compiler in some way. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@dsherret
Copy link

dsherret commented Aug 9, 2021

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
@dsherret dsherret added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Aug 9, 2021
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Aug 9, 2021
@GuillaumeGomez GuillaumeGomez 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 Aug 9, 2021
@camelid camelid added the requires-nightly This issue requires a nightly compiler in some way. label Aug 9, 2021
@camelid
Copy link
Member

camelid commented Aug 9, 2021

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

@jyn514 jyn514 added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-untriaged Untriaged performance or correctness regression. labels Aug 9, 2021
@GuillaumeGomez GuillaumeGomez self-assigned this Aug 27, 2021
@bors bors closed this as completed in f4f5dd5 Aug 31, 2021
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. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. requires-nightly This issue requires a nightly compiler in some way. 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.

5 participants