Skip to content

Commit fa7a3f9

Browse files
committed
rustdoc: Elide const-unstable if also unstable overall
It's confusing because if a function is unstable overall, there's no need to highlight the constness is also unstable. Technically, these attributes (overall stability and const-stability) are separate, but in practice, we don't even show the const-unstable's feature flag (it's normally the same as the overall function).
1 parent 72d8d8d commit fa7a3f9

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/librustdoc/html/render/mod.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -1016,18 +1016,23 @@ fn render_stability_since_raw_with_extra(
10161016
.map(|since| (format!("const since {since}"), format!("const: {since}")))
10171017
}
10181018
Some(ConstStability { level: StabilityLevel::Unstable { issue, .. }, feature, .. }) => {
1019-
let unstable = if let Some(n) = issue {
1020-
format!(
1021-
"<a \
1019+
if stable_version.is_none() {
1020+
// don't display const unstable if entirely unstable
1021+
None
1022+
} else {
1023+
let unstable = if let Some(n) = issue {
1024+
format!(
1025+
"<a \
10221026
href=\"https://github.com/rust-lang/rust/issues/{n}\" \
10231027
title=\"Tracking issue for {feature}\"\
10241028
>unstable</a>"
1025-
)
1026-
} else {
1027-
String::from("unstable")
1028-
};
1029+
)
1030+
} else {
1031+
String::from("unstable")
1032+
};
10291033

1030-
Some((String::from("const unstable"), format!("const: {unstable}")))
1034+
Some((String::from("const unstable"), format!("const: {unstable}")))
1035+
}
10311036
}
10321037
_ => None,
10331038
};

tests/rustdoc/const-display.rs

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ pub const unsafe fn foo_unsafe() -> u32 { 42 }
2424
#[unstable(feature = "humans", issue = "none")]
2525
pub const fn foo2() -> u32 { 42 }
2626

27+
// @has 'foo/fn.foo3.html' '//pre' 'pub fn foo3() -> u32'
28+
// @!hasraw - '//span[@class="since"]'
29+
#[unstable(feature = "humans", issue = "none")]
30+
#[rustc_const_unstable(feature = "humans", issue = "none")]
31+
pub const fn foo3() -> u32 { 42 }
32+
2733
// @has 'foo/fn.bar2.html' '//pre' 'pub const fn bar2() -> u32'
2834
// @has - //span '1.0.0 (const: 1.0.0)'
2935
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)