Repository navigation
Conversation
This comment has been minimized.
This comment has been minimized.
71c5c30 to
635c892
Compare
635c892 to
d8f00d3
Compare
|
|
||
| fn is_internal_lib_feature(feature: Symbol) -> bool { | ||
| let name = feature.as_str(); | ||
| name == "core_intrinsics" || name.ends_with("_internal") || name.ends_with("_internals") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
rust/compiler/rustc_span/src/symbol.rs
Lines 155 to 166 in b46c90c
| 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) { |
There was a problem hiding this comment.
Please change this to an if let so that you can avoid unwrapping.
|
Reminder, once the PR becomes ready for a review, use |
|
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. |
d8f00d3 to
ec90421
Compare
|
I redesign this PR, concretely:
But there remains a question. In PR#163488, Clar add the new enum 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 |
|
@rustbot ready |
| | sym::hash_map_internals | ||
| | sym::hashmap_internals |
There was a problem hiding this comment.
It'd probably be a good idea to change the std code to deduplicate this and just use one spelling.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Something centralized would be better in any case.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
Thank you for working on this though!
|
☔ The latest upstream changes made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
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 inrust/compiler/rustc_feature/src/unstable.rs
Lines 172 to 192 in b46c90c
self.enabled_featuresis: 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 inrustc_feature/src/unstable.rs:So we can use
is_internal_featureinrustdocto check whether this feature is internal. I think this is a better way becauserustc_featureandrustdocshare 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