Skip to content

Commit f970632

Browse files
committed
Don't render unstable for rustc docs
As rustc is permanently unstable. So marking every items with unstable is essential useless.
1 parent 567ad74 commit f970632

File tree

2 files changed

+23
-32
lines changed

2 files changed

+23
-32
lines changed

src/librustdoc/html/render.rs

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,12 +2229,15 @@ fn stability_tags(item: &clean::Item) -> String {
22292229
tags += &tag_html("deprecated", message);
22302230
}
22312231

2232-
if let Some(stab) = item.stability.as_ref().filter(|s| s.level == stability::Unstable) {
2233-
if stab.feature.as_deref() == Some("rustc_private") {
2234-
tags += &tag_html("internal", "Internal");
2235-
} else {
2236-
tags += &tag_html("unstable", "Experimental");
2237-
}
2232+
// The "rustc_private" crates are permanently unstable so it makes no sense
2233+
// to render "unstable" everywhere.
2234+
if item
2235+
.stability
2236+
.as_ref()
2237+
.map(|s| s.level == stability::Unstable && s.feature.as_deref() != Some("rustc_private"))
2238+
== Some(true)
2239+
{
2240+
tags += &tag_html("unstable", "Experimental");
22382241
}
22392242

22402243
if let Some(ref cfg) = item.attrs.cfg {
@@ -2285,15 +2288,13 @@ fn short_stability(item: &clean::Item, cx: &Context) -> Vec<String> {
22852288
));
22862289
}
22872290

2288-
if let Some(stab) = item.stability.as_ref().filter(|stab| stab.level == stability::Unstable) {
2289-
let is_rustc_private = stab.feature.as_deref() == Some("rustc_private");
2290-
2291-
let mut message = if is_rustc_private {
2292-
"<span class='emoji'>⚙️</span> This is an internal compiler API."
2293-
} else {
2294-
"<span class='emoji'>🔬</span> This is a nightly-only experimental API."
2295-
}
2296-
.to_owned();
2291+
// Render unstable items. But don't render "rustc_private" crates (internal compiler crates).
2292+
// Those crates are permanently unstable so it makes no sense to render "unstable" everywhere.
2293+
if let Some(stab) = item.stability.as_ref().filter(|stab| {
2294+
stab.level == stability::Unstable && stab.feature.as_deref() != Some("rustc_private")
2295+
}) {
2296+
let mut message =
2297+
"<span class='emoji'>🔬</span> This is a nightly-only experimental API.".to_owned();
22972298

22982299
if let Some(feature) = stab.feature.as_deref() {
22992300
let mut feature = format!("<code>{}</code>", Escape(&feature));
@@ -2309,17 +2310,6 @@ fn short_stability(item: &clean::Item, cx: &Context) -> Vec<String> {
23092310
}
23102311

23112312
if let Some(unstable_reason) = &stab.unstable_reason {
2312-
// Provide a more informative message than the compiler help.
2313-
let unstable_reason = if is_rustc_private {
2314-
"This crate is being loaded from the sysroot, a permanently unstable location \
2315-
for private compiler dependencies. It is not intended for general use. Prefer \
2316-
using a public version of this crate from \
2317-
[crates.io](https://crates.io) via [`Cargo.toml`]\
2318-
(https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html)."
2319-
} else {
2320-
unstable_reason
2321-
};
2322-
23232313
let mut ids = cx.id_map.borrow_mut();
23242314
message = format!(
23252315
"<details><summary>{}</summary>{}</details>",
@@ -2335,8 +2325,7 @@ fn short_stability(item: &clean::Item, cx: &Context) -> Vec<String> {
23352325
);
23362326
}
23372327

2338-
let class = if is_rustc_private { "internal" } else { "unstable" };
2339-
stability.push(format!("<div class='stab {}'>{}</div>", class, message));
2328+
stability.push(format!("<div class='stab unstable'>{}</div>", message));
23402329
}
23412330

23422331
if let Some(ref cfg) = item.attrs.cfg {

src/test/rustdoc/internal.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// compile-flags: -Z force-unstable-if-unmarked
22

3-
// @matches internal/index.html '//*[@class="docblock-short"]/span[@class="stab internal"]' \
4-
// 'Internal'
3+
// Check that the unstable marker is not added for "rustc_private".
4+
5+
// @!matches internal/index.html '//*[@class="docblock-short"]/span[@class="stab unstable"]'
6+
// @!matches internal/index.html '//*[@class="docblock-short"]/span[@class="stab internal"]'
57
// @matches - '//*[@class="docblock-short"]' 'Docs'
68

7-
// @has internal/struct.S.html '//*[@class="stab internal"]' \
8-
// 'This is an internal compiler API. (rustc_private)'
9+
// @!has internal/struct.S.html '//*[@class="stab unstable"]'
10+
// @!has internal/struct.S.html '//*[@class="stab internal"]'
911
/// Docs
1012
pub struct S;
1113

0 commit comments

Comments
 (0)