Skip to content

Commit b5b353b

Browse files
Improve display of const unstable feature
1 parent 9a1d156 commit b5b353b

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/librustdoc/html/render/mod.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,12 @@ enum ShortItemInfo {
684684
Portability {
685685
message: String,
686686
},
687+
/// The feature corresponding to a const unstable item, and optionally
688+
/// a tracking issue URL and number.
689+
ConstUnstable {
690+
feature: String,
691+
tracking: Option<u32>,
692+
},
687693
}
688694

689695
/// Render the stability, deprecation and portability information that is displayed at the top of
@@ -723,10 +729,10 @@ fn short_item_info(
723729
extra_info.push(ShortItemInfo::Deprecation { message });
724730
}
725731

732+
let stability = item.stability(cx.tcx());
726733
// Render unstable items. But don't render "rustc_private" crates (internal compiler crates).
727734
// Those crates are permanently unstable so it makes no sense to render "unstable" everywhere.
728-
if let Some((StabilityLevel::Unstable { reason: _, issue, .. }, feature)) = item
729-
.stability(cx.tcx())
735+
if let Some((StabilityLevel::Unstable { reason: _, issue, .. }, feature)) = stability
730736
.as_ref()
731737
.filter(|stab| stab.feature != sym::rustc_private)
732738
.map(|stab| (stab.level, stab.feature))
@@ -740,6 +746,18 @@ fn short_item_info(
740746
extra_info.push(ShortItemInfo::Unstable { feature: feature.to_string(), tracking });
741747
}
742748

749+
// Only display const unstable if NOT entirely unstable.
750+
if stability.and_then(|stability| stability.stable_since()).is_some()
751+
&& let Some(ConstStability {
752+
level: StabilityLevel::Unstable { issue, .. }, feature, ..
753+
}) = item.const_stability(cx.tcx())
754+
{
755+
extra_info.push(ShortItemInfo::ConstUnstable {
756+
feature: feature.to_string(),
757+
tracking: issue.map(|issue| issue.get()),
758+
});
759+
}
760+
743761
if let Some(message) = portability(item, parent) {
744762
extra_info.push(ShortItemInfo::Portability { message });
745763
}

src/librustdoc/html/templates/short_item_info.html

+12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818
) {# #}
1919
</span> {# #}
2020
</div>
21+
{% when Self::ConstUnstable with { feature, tracking } %}
22+
<div class="stab unstable"> {# #}
23+
<span class="emoji">🔬</span> {# #}
24+
<span> {# #}
25+
The const version is a nightly-only experimental API. ({# #}
26+
<code>{{feature}}</code>
27+
{% if let Some(num) = tracking %}
28+
&nbsp;<a href="https://github.com/rust-lang/rust/issues/{{num}}">#{{num}}</a>
29+
{% endif %}
30+
) {# #}
31+
</span> {# #}
32+
</div>
2133
{% when Self::Portability with { message } %}
2234
<div class="stab portability">{{message|safe}}</div>
2335
{% endmatch %}

tests/rustdoc/const-display.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub const fn foo() -> u32 { 42 }
1414
//@ has 'foo/fn.foo_unsafe.html' '//pre' 'pub unsafe fn foo_unsafe() -> u32'
1515
//@ has - '//span[@class="since"]' '1.0.0 (const: unstable)'
1616
#[stable(feature = "rust1", since = "1.0.0")]
17-
#[rustc_const_unstable(feature="foo", issue = "none")]
17+
#[rustc_const_unstable(feature="foo", issue = "111")]
1818
pub const unsafe fn foo_unsafe() -> u32 { 42 }
1919

2020
//@ has 'foo/fn.foo2.html' '//pre' 'pub const fn foo2() -> u32'

0 commit comments

Comments
 (0)