Skip to content

Support for showing explicit enum discriminant values in rustdoc #101337

Closed
@Enselic

Description

@Enselic

Currently, enum discriminant values are not included in the HTML output. The code

pub enum E {
    V = 42,
}

renders like this:
187080081-aa71e5f4-8304-4574-8de1-a16a7aefccd4

However, it is easy to imagine a public API where the discriminant value matters. For example, some lib code could look like this:

#[repr(u8)]
pub enum Key {
    A = 65, // the value is the ASCII code for 'A'
}

and client code like this:

let key = std::io::stdin().bytes().next().unwrap().unwrap();
if key == Key::A as u8 {
    println!("A was typed")
}

In this example, the enum discriminant value is part of the public API of the library, so it would make sense to somehow make rustdoc include enum discriminant values in the rendered HTML.

Depending on the context, it is however perfectly reasonable to consider enum discriminant values to be an implementation detail, even explicit enum discriminant values. So it should also be supported to make sure they are NOT displayed.

The exact mechanism for this is still to be decided. See Zulip for some discussion on this. But most likely rustdoc should never show the enum discriminant value if they are not explicitly defined.

@rustbot label T-rustdoc

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-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