diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs
index 9a9ce31caaa4c..885b3c10965b3 100644
--- a/src/librustdoc/html/render/mod.rs
+++ b/src/librustdoc/html/render/mod.rs
@@ -684,6 +684,12 @@ enum ShortItemInfo {
Portability {
message: String,
},
+ /// The feature corresponding to a const unstable item, and optionally
+ /// a tracking issue URL and number.
+ ConstUnstable {
+ feature: String,
+ tracking: Option,
+ },
}
/// Render the stability, deprecation and portability information that is displayed at the top of
@@ -723,10 +729,10 @@ fn short_item_info(
extra_info.push(ShortItemInfo::Deprecation { message });
}
+ let stability = item.stability(cx.tcx());
// Render unstable items. But don't render "rustc_private" crates (internal compiler crates).
// Those crates are permanently unstable so it makes no sense to render "unstable" everywhere.
- if let Some((StabilityLevel::Unstable { reason: _, issue, .. }, feature)) = item
- .stability(cx.tcx())
+ if let Some((StabilityLevel::Unstable { reason: _, issue, .. }, feature)) = stability
.as_ref()
.filter(|stab| stab.feature != sym::rustc_private)
.map(|stab| (stab.level, stab.feature))
@@ -740,6 +746,18 @@ fn short_item_info(
extra_info.push(ShortItemInfo::Unstable { feature: feature.to_string(), tracking });
}
+ // Only display const unstable if NOT entirely unstable.
+ if stability.and_then(|stability| stability.stable_since()).is_some()
+ && let Some(ConstStability {
+ level: StabilityLevel::Unstable { issue, .. }, feature, ..
+ }) = item.const_stability(cx.tcx())
+ {
+ extra_info.push(ShortItemInfo::ConstUnstable {
+ feature: feature.to_string(),
+ tracking: issue.map(|issue| issue.get()),
+ });
+ }
+
if let Some(message) = portability(item, parent) {
extra_info.push(ShortItemInfo::Portability { message });
}
diff --git a/src/librustdoc/html/templates/short_item_info.html b/src/librustdoc/html/templates/short_item_info.html
index e76b98541cf61..b1a5ac1965922 100644
--- a/src/librustdoc/html/templates/short_item_info.html
+++ b/src/librustdoc/html/templates/short_item_info.html
@@ -18,6 +18,18 @@
) {# #}
{# #}
+ {% when Self::ConstUnstable with { feature, tracking } %}
+ {# #}
+
🔬 {# #}
+
{# #}
+ The const version is a nightly-only experimental API. ({# #}
+ {{feature}}
+ {% if let Some(num) = tracking %}
+ #{{num}}
+ {% endif %}
+ ) {# #}
+ {# #}
+
{% when Self::Portability with { message } %}
{{message|safe}}
{% endmatch %}
diff --git a/tests/rustdoc/const-display.rs b/tests/rustdoc/const-display.rs
index bc4270c421d5d..9877286ff59fd 100644
--- a/tests/rustdoc/const-display.rs
+++ b/tests/rustdoc/const-display.rs
@@ -7,14 +7,20 @@
//@ has 'foo/fn.foo.html' '//pre' 'pub fn foo() -> u32'
//@ has - '//span[@class="since"]' '1.0.0 (const: unstable)'
+//@ has - '//span[@class="item-info"]//span' 'The const version is a \
+// nightly-only experimental API. (foo)'
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature="foo", issue = "none")]
pub const fn foo() -> u32 { 42 }
//@ has 'foo/fn.foo_unsafe.html' '//pre' 'pub unsafe fn foo_unsafe() -> u32'
//@ has - '//span[@class="since"]' '1.0.0 (const: unstable)'
+//@ has - '//span[@class="item-info"]//span' 'The const version is a \
+// nightly-only experimental API. (foo #111)'
+//@ has - '//span[@class="item-info"]//a[@href="https://github.com/rust-lang/rust/issues/111"]' \
+// '#111'
#[stable(feature = "rust1", since = "1.0.0")]
-#[rustc_const_unstable(feature="foo", issue = "none")]
+#[rustc_const_unstable(feature="foo", issue = "111")]
pub const unsafe fn foo_unsafe() -> u32 { 42 }
//@ has 'foo/fn.foo2.html' '//pre' 'pub const fn foo2() -> u32'
@@ -63,12 +69,18 @@ pub struct Foo;
impl Foo {
//@ has 'foo/struct.Foo.html' '//*[@id="method.gated"]/h4[@class="code-header"]' 'pub fn gated() -> u32'
//@ has - '//span[@class="since"]' '1.0.0 (const: unstable)'
+ //@ has - '//span[@class="item-info"]//span' 'The const version is a \
+ // nightly-only experimental API. (foo #112)'
+ //@ has - '//span[@class="item-info"]//a[@href="https://github.com/rust-lang/rust/issues/112"]' \
+ // '#112'
#[stable(feature = "rust1", since = "1.0.0")]
- #[rustc_const_unstable(feature="foo", issue = "none")]
+ #[rustc_const_unstable(feature="foo", issue = "112")]
pub const fn gated() -> u32 { 42 }
//@ has 'foo/struct.Foo.html' '//*[@id="method.gated_unsafe"]/h4[@class="code-header"]' 'pub unsafe fn gated_unsafe() -> u32'
//@ has - '//span[@class="since"]' '1.0.0 (const: unstable)'
+ //@ has - '//span[@class="item-info"]//span' 'The const version is a \
+ // nightly-only experimental API. (foo)'
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature="foo", issue = "none")]
pub const unsafe fn gated_unsafe() -> u32 { 42 }