Skip to content

Follow up PR of distinguish experimental/internal features in rustdoc - #165017

Closed
yilin0518 wants to merge 2 commits into
rust-lang:mainfrom
yilin0518:rustdoc-internal
Closed

yilin0518 wants to merge 2 commits into
rust-lang:mainfrom
yilin0518:rustdoc-internal

Conversation

@yilin0518

@yilin0518 yilin0518 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

This PR serves as a follow-up PR of PR #163488, which distinguish experimental/internal features in rustdoc. This PR provides a solution to fix compile error that exists in #163488 and adds some test cases.

The solution is adding an internal API check in librustdoc/html/render/mod.rs. This check contains the same criteria used in

pub fn internal(&self, feature: Symbol) -> bool {
match feature {
$(
// Match guard to avoid duplicating `cannot find $feature in module sym` error.
f if f == sym::$feature => status_to_enum!($status) == FeatureStatus::Internal,
)*
_ if self.enabled_features.contains(&feature) => {
// This could be accepted/removed, or a libs feature.
// Accepted/removed features aren't in this file but are never internal
// (a removed feature might have been internal, but that's now irrelevant).
// Libs features are internal if they end in `_internal` or `_internals`.
// As a special exception we also consider `core_intrinsics` internal;
// renaming that age-old feature is just not worth the hassle.
// We just always test the name; it's not a big deal if we accidentally hit
// an accepted/removed lang feature that way.
let name = feature.as_str();
name == "core_intrinsics" || name.ends_with("_internal") || name.ends_with("_internals")
}
_ => panic!("`{}` was not listed in `declare_features`", feature),
}
}
, but only checks the name of the feature. The reason not to check whether this feature is in self.enabled_features is: I think we only generate HTML tags and warnings about internal features, and we don't care whether this feature is enabled.

Another solution is adding a new check method in rustc_feature/src/unstable.rs, which performs the check. For example, adding this function in rustc_feature/src/unstable.rs:

pub fn is_internal_feature(feature: &Symbol) -> bool {
    let name = feature.as_str();
    name == "core_intrinsics" || name.ends_with("_internal") || name.ends_with("_internals")
}

So we can use is_internal_feature in rustdoc to check whether this feature is internal. I think this is a better way because rustc_feature and rustdoc share the same check.

I use the LLM to help me understand how to write test cases, because this is my first time writing test case for rustdoc. All the test cases are writen by myself and all are passed.

r? rustdoc

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Oct 27, 2026
@rustbot

This comment has been minimized.

@yilin0518 yilin0518 changed the title Tracking PR of distinguish experimental/internal features in rustdoc Follow up PR of distinguish experimental/internal features in rustdoc Oct 27, 2026

@camelid camelid left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I like this idea, but I think the implementation needs some more work.

View changes since this review

Comment thread src/librustdoc/html/render/mod.rs Outdated

fn is_internal_lib_feature(feature: Symbol) -> bool {
let name = feature.as_str();
name == "core_intrinsics" || name.ends_with("_internal") || name.ends_with("_internals")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems fragile to check if the name ends with _internal/_internals since there are non-internal features that could have names ending with this. It would be better to have an explicit exhaustive list since false negatives (marking an internal feature as normal experimental) are better than false positives (marking a normal experimental feature as internal).

This also allows matching against symbols like sym::core_intrinsics instead of using as_str(), which you should change as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding an explicit exhaustive list is feasible, but I have a question: According to the judgement standard defined in rustc_feature, I find that there are some internal features that used on APIs marked by #[doc(hidden)](for example, alloc_internals). So if I want to add symbols in

Symbols {
// tidy-alphabetical-start
Abi,
AcqRel,
Acquire,
Active,
ActiveOnly,
Alignment,
Arc,
ArcWeak,
Array,
ArrayToPointer,
, should I consider the entirely invisible features?

Comment on lines +546 to +547
if stability.is_some_and(|s| s.is_unstable() && s.feature != sym::rustc_private) {
write!(f, "{}", tag_html("unstable", "", "Experimental"))?;
if super::is_internal_lib_feature(stability.unwrap().feature) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this to an if let so that you can avoid unwrapping.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 19, 2026
@rustbot

rustbot commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@camelid

camelid commented Nov 19, 2026

Copy link
Copy Markdown
Member

I'm also a little confused about how this PR relates to the approach taken in #163488. What led you to make the changes that you did?

@yilin0518

Copy link
Copy Markdown
Contributor Author

I'm also a little confused about how this PR relates to the approach taken in #163488. What led you to make the changes that you did?

I found that #163488 failed, and the reason why it failed is it accessed nonexistent field:

  error[E0609]: no field `span` on type `&rustc_attr_ir::Stability`
     --> src/librustdoc/html/render/mod.rs:936:39
      |
  936 |         .map(|stab| (stab.level, stab.span, stab.feature))
      |                                       ^^^^ unknown field
      |
      = note: available fields are: `level`, `feature`

So I make the changes to implement this feature.

@yilin0518

Copy link
Copy Markdown
Contributor Author

I redesign this PR, concretely:

  • Add new symbols in rustc_span/src/symbol.rs according to the standard defined in rustc_feature/src/unstable.rs. These new symbols are used for matching internal APIs in librustdoc/html/render/print_item.rs.
  • In librustdoc/html/render/mod.rs, refactor is_internal_lib_feature. Change it into an exhaustive list and the elements in this list are those used in Rust standard library in the form of #[unstable(feature = ...)] or #![unstable(feature = ...)].
  • Change the test case.

But there remains a question. In PR#163488, Clar add the new enum Internal in ShortItemInfo:

enum ShortItemInfo {
    /// A message describing the deprecation of this item
    Deprecation {
        message: String,
    },
    /// The feature corresponding to an unstable item, and optionally
    /// a tracking issue URL and number.
    Unstable {
        feature: String,
        tracking: Option<(String, u32)>,
    },
    /// Internal feature, which won't have a tracking issue.
    Internal {
        feature: String,
    },
    Portability {
        message: String,
    },
}

He wrote that Internal feature doe not have a tracking issue. But I found that cmp_splat_internals, contracts_internals, generic_assert_internals have tracking issues, and these are internal features according the standard defined in rustc_feature/src/unstable.rs. So should I change that annotation?

@yilin0518

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 23, 2026

@camelid camelid left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @rust-lang/rustdoc -- any opinion on this feature and implementation? no need for FCP but I'm wondering what you think of the approach

View changes since this review

Comment on lines +986 to +987
| sym::hash_map_internals
| sym::hashmap_internals

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd probably be a good idea to change the std code to deduplicate this and just use one spelling.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind distinguishing "normal" vs internal feature gates, but having a list of feature gates in rustdoc is IMO a no-go. rustdoc shouldn't be in the business of maintaining that list.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like @Urgau said.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's how I feel as well, but I'm not sure what the right approach is. Maybe we should have dedicated support from staged_api to declare features as "internal", but that's a much bigger change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something centralized would be better in any case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind distinguishing "normal" vs internal feature gates, but having a list of feature gates in rustdoc is IMO a no-go. rustdoc shouldn't be in the business of maintaining that list.

I agree that. Once a new internal feature is used, it has to be inserted into this list. I think this way can avoid false positives, but it should be maintained.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yilin0518 sorry for the back and forth, but based on this I think this PR should probably be closed since a new approach will need to be taken. If you want you could open an issue about changing the staged_api rustc feature to allow specifying features as internal-only, and see what the compiler and library teams think about that. That would be a prerequisite for supporting it in rustdoc.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this though!

@rust-bors

rust-bors Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

@camelid camelid closed this Nov 24, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants