Skip to content

Long lists of doc_cfg targets are not sorted in a useful way #156391

@elomatreb

Description

@elomatreb

The "Available on ..." badges about target-exclusive documentation items generated by the doc_cfg feature are not sorted and appear to reuse the order of predicates as they appear in the source code. This is problematic because:

  1. Popular, widely used targets can be buried among many niche ones
  2. A particular target a user is looking for could appear at any point in the list depending on what choices the author of the relevant cfg block in the source made.

Code

#![feature(doc_cfg)]

#[cfg(any(
    target_os = "android",
    target_os = "linux",
    target_os = "dragonfly",
    target_os = "freebsd",
    target_os = "netbsd",
    target_os = "openbsd",
    target_os = "nto",
    target_vendor = "apple",
    target_os = "cygwin"
))]
pub fn foo() {}

The cfg is taken from UnixStream::peer_cred.

Reproduction Steps

  1. cargo +nightly doc with the above code.

Expected Outcome

The lists are sorted in a deterministic and useful manner, e.g. in descending order of popularity/tier status and alphabetically.

An example ordered by tier status and alphabetically would be:

Available on Apple or Linux or FreeBSD or NetBSD or Android or Cygwin or Dragonfly BSD or OpenBSD or QNX Neutrino only.

Actual Output

Screenshots of the rendered docs listed under Code:

Image

Note where the major targets Linux and Apple that many people will be looking for appear in the list.

Version

rustdoc 1.97.0-nightly (82bee9650 2026-05-09)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cfgArea: `cfg` conditional compilationC-bugCategory: This is a bug.C-enhancementCategory: An issue proposing an enhancement or a PR with one.F-doc_cfg`#![feature(doc_cfg)]`T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions