Skip to content

Commit 8d393bf

Browse files
committed
display rustc_private APIs as "Internal"
1 parent 5f34316 commit 8d393bf

File tree

5 files changed

+52
-8
lines changed

5 files changed

+52
-8
lines changed

src/librustdoc/html/render.rs

+31-7
Original file line numberDiff line numberDiff line change
@@ -2703,13 +2703,16 @@ fn stability_tags(item: &clean::Item) -> String {
27032703
tags.push_str("[<div class='stab deprecated'>Deprecated</div>] ");
27042704
}
27052705

2706-
if item
2706+
if let Some(stab) = item
27072707
.stability
27082708
.as_ref()
27092709
.filter(|s| s.level == stability::Unstable)
2710-
.is_some()
27112710
{
2712-
tags.push_str("[<div class='stab unstable'>Experimental</div>] ");
2711+
if stab.feature.as_ref().map(|s| &**s) == Some("rustc_private") {
2712+
tags.push_str("[<div class='stab internal'>Internal</div>] ");
2713+
} else {
2714+
tags.push_str("[<div class='stab unstable'>Experimental</div>] ");
2715+
}
27132716
}
27142717

27152718
if let Some(ref cfg) = item.attrs.cfg {
@@ -2752,9 +2755,14 @@ fn short_stability(item: &clean::Item, cx: &Context) -> Vec<String> {
27522755
.as_ref()
27532756
.filter(|stab| stab.level == stability::Unstable)
27542757
{
2755-
let mut message = String::from(
2756-
"<span class=microscope>🔬</span> This is a nightly-only experimental API.",
2757-
);
2758+
let is_rustc_private = stab.feature.as_ref().map(|s| &**s) == Some("rustc_private");
2759+
2760+
let mut message = if is_rustc_private {
2761+
"<span class='emoji'>⚙️</span> This is an internal compiler API."
2762+
} else {
2763+
"<span class='emoji'>🔬</span> This is a nightly-only experimental API."
2764+
}
2765+
.to_owned();
27582766

27592767
if let Some(feature) = stab.feature.as_ref() {
27602768
let mut feature = format!("<code>{}</code>", Escape(&feature));
@@ -2770,6 +2778,17 @@ fn short_stability(item: &clean::Item, cx: &Context) -> Vec<String> {
27702778
}
27712779

27722780
if let Some(unstable_reason) = &stab.unstable_reason {
2781+
// Provide a more informative message than the compiler help.
2782+
let unstable_reason = if is_rustc_private {
2783+
"This crate is being loaded from the sysroot, a permanently unstable location \
2784+
for private compiler dependencies. It is not intended for general use. Prefer \
2785+
using a public version of this crate from \
2786+
[crates.io](https://crates.io) via [`Cargo.toml`]\
2787+
(https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html)."
2788+
} else {
2789+
unstable_reason
2790+
};
2791+
27732792
let mut ids = cx.id_map.borrow_mut();
27742793
message = format!(
27752794
"<details><summary>{}</summary>{}</details>",
@@ -2778,7 +2797,12 @@ fn short_stability(item: &clean::Item, cx: &Context) -> Vec<String> {
27782797
);
27792798
}
27802799

2781-
stability.push(format!("<div class='stab unstable'>{}</div>", message))
2800+
let class = if is_rustc_private {
2801+
"internal"
2802+
} else {
2803+
"unstable"
2804+
};
2805+
stability.push(format!("<div class='stab {}'>{}</div>", class, message));
27822806
}
27832807

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

src/librustdoc/html/static/rustdoc.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ body.blur > :not(#help) {
765765
display: list-item;
766766
}
767767

768-
.stab .microscope {
768+
.stab .emoji {
769769
font-size: 1.5em;
770770
}
771771

src/librustdoc/html/static/themes/dark.css

+5
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ a {
174174
color: #D2991D;
175175
}
176176

177+
.stab.internal a {
178+
color: #304FFE;
179+
}
180+
177181
a.test-arrow {
178182
color: #dedede;
179183
}
@@ -199,6 +203,7 @@ a.test-arrow {
199203
}
200204

201205
.stab.unstable { background: #FFF5D6; border-color: #FFC600; color: #404040; }
206+
.stab.internal { background: #FFB9B3; border-color: #B71C1C; color: #404040; }
202207
.stab.deprecated { background: #F3DFFF; border-color: #7F0087; color: #404040; }
203208
.stab.portability { background: #C4ECFF; border-color: #7BA5DB; color: #404040; }
204209

src/librustdoc/html/static/themes/light.css

+5
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ a {
174174
color: #3873AD;
175175
}
176176

177+
.stab.internal a {
178+
color: #304FFE;
179+
}
180+
177181
a.test-arrow {
178182
color: #f5f5f5;
179183
}
@@ -200,6 +204,7 @@ a.test-arrow {
200204
}
201205

202206
.stab.unstable { background: #FFF5D6; border-color: #FFC600; }
207+
.stab.internal { background: #FFB9B3; border-color: #B71C1C; }
203208
.stab.deprecated { background: #F3DFFF; border-color: #7F0087; }
204209
.stab.portability { background: #C4ECFF; border-color: #7BA5DB; }
205210

src/test/rustdoc/internal.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// compile-flags: -Z force-unstable-if-unmarked
2+
3+
// @matches internal/index.html '//*[@class="docblock-short"]' \
4+
// '^\[Internal\] Docs'
5+
// @has internal/struct.S.html '//*[@class="stab internal"]' \
6+
// 'This is an internal compiler API. (rustc_private)'
7+
/// Docs
8+
pub struct S;
9+
10+
fn main() {}

0 commit comments

Comments
 (0)