Skip to content

rustdoc prints the names of private consts when used as const generic parameter defaults #129035

Open
@kpreid

Description

@kpreid
const VALUE: usize = 1;
type Ty = ();
pub trait Foo<const N: usize = VALUE, T = Ty> {}

Rustdoc generates the following pseudocode for this trait’s documentation page:

pub trait Foo<const N: usize = VALUE, T = ()> { }

This seems inconsistent to me: non-public constants should be replaced with their value just like non-public type aliases are, because crates should be free to have aliases for their own things privately without affecting the public view.

Another case is when a public constant uses a private constant; in that case, the private constant is named and the final value is. I’m not sure whether that’s good, but it at least answers the question of what the value is.

Meta

rustc --version --verbose:

rustc 1.82.0-nightly (41dd149fd 2024-08-11)
binary: rustc
commit-hash: 41dd149fd6a6a06795fc6b9f54cb49af2f61775f
commit-date: 2024-08-11
host: x86_64-apple-darwin
release: 1.82.0-nightly
LLVM version: 19.1.0

@rustbot label +T-rustdoc

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-const-genericsArea: const generics (parameters and arguments)A-visibilityArea: Visibility / privacyC-bugCategory: This is a bug.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