Skip to content

Rustdoc-Json: Report discriminant on all kinds of enum variant. #106299

Closed
@aDotInTheVoid

Description

@aDotInTheVoid

Rust now supports adding an explicit discriminant to all kinds of enum variant.

Eg:

#[repr(u8)]
enum Foo {
    Bar(i32) = 1,
    Baz { a: i32, b: i32 } = 2,
}

However we currently only report it for unit variants.

pub enum Variant {
/// A variant with no parentheses, and possible discriminant.
///
/// ```rust
/// enum Demo {
/// PlainVariant,
/// PlainWithDiscriminant = 1,
/// }
/// ```
Plain(Option<Discriminant>),
/// A variant with unnamed fields.
///
/// Unlike most of json, `#[doc(hidden)]` fields will be given as `None`
/// instead of being omitted, because order matters.
///
/// ```rust
/// enum Demo {
/// TupleVariant(i32),
/// EmptyTupleVariant(),
/// }
/// ```
Tuple(Vec<Option<Id>>),
/// A variant with named fields.
///
/// ```rust
/// enum Demo {
/// StructVariant { x: i32 },
/// EmptyStructVariant {},
/// }
/// ```
Struct { fields: Vec<Id>, fields_stripped: bool },
}

But it should be for all variants.

@rustbot claim

Metadata

Metadata

Assignees

Labels

A-rustdoc-jsonArea: Rustdoc JSON backendT-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions