rust-lang / rust-lang/rust

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

Open
#129,035 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-const-eval A-const-generics A-visibility C-bug T-rustdoc
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal Rust snippet in the issue and run rustdoc to reproduce the generated trait documentation. Trace the rustdoc entry point that renders const generic defaults; done means private constants are represented by their values rather than private names, with the public-constant case covered as well.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.