Skip to content

Commit 9c495b3

Browse files
committed
"(const: unstable)" for stable-but-const-unstable
1 parent 39260f6 commit 9c495b3

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

src/librustdoc/html/render/mod.rs

+29-7
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use std::str;
4242
use std::string::ToString;
4343

4444
use rustc_ast_pretty::pprust;
45-
use rustc_attr::{Deprecation, StabilityLevel};
45+
use rustc_attr::{ConstStability, Deprecation, StabilityLevel};
4646
use rustc_data_structures::fx::FxHashSet;
4747
use rustc_hir as hir;
4848
use rustc_hir::def::CtorKind;
@@ -826,20 +826,42 @@ fn assoc_type(
826826
fn render_stability_since_raw(
827827
w: &mut Buffer,
828828
ver: Option<&str>,
829-
const_ver: Option<&str>,
829+
const_stability: Option<&ConstStability>,
830830
containing_ver: Option<&str>,
831831
containing_const_ver: Option<&str>,
832832
) {
833833
let ver = ver.filter(|inner| !inner.is_empty());
834-
let const_ver = const_ver.filter(|inner| !inner.is_empty());
835834

836-
match (ver, const_ver) {
837-
(Some(v), Some(cv)) if const_ver != containing_const_ver => {
835+
match (ver, const_stability) {
836+
(Some(v), Some(ConstStability { level: StabilityLevel::Stable { since }, .. }))
837+
if Some(since.as_str()).as_deref() != containing_const_ver =>
838+
{
838839
write!(
839840
w,
840841
"<span class=\"since\" title=\"Stable since Rust version {0}, const since {1}\">{0} (const: {1})</span>",
841-
v, cv
842+
v,
843+
since.as_str()
844+
);
845+
}
846+
(
847+
Some(v),
848+
Some(ConstStability { level: StabilityLevel::Unstable { issue, .. }, feature, .. }),
849+
) => {
850+
write!(
851+
w,
852+
"<span class=\"since\" title=\"Stable since Rust version {0}, const unstable\">{0} (const: ",
853+
v
842854
);
855+
if let Some(n) = issue {
856+
write!(
857+
w,
858+
"<a href=\"https://github.com/rust-lang/rust/issues/{}\" title=\"Tracking issue for {}\">unstable</a>",
859+
n, feature
860+
);
861+
} else {
862+
write!(w, "unstable");
863+
}
864+
write!(w, ")</span>");
843865
}
844866
(Some(v), _) if ver != containing_ver => {
845867
write!(
@@ -1583,7 +1605,7 @@ fn render_rightside(
15831605
render_stability_since_raw(
15841606
w,
15851607
item.stable_since(tcx).as_deref(),
1586-
item.const_stable_since(tcx).as_deref(),
1608+
item.const_stability(tcx),
15871609
containing_item.stable_since(tcx).as_deref(),
15881610
containing_item.const_stable_since(tcx).as_deref(),
15891611
);

src/librustdoc/html/render/print_item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub(super) fn print_item(cx: &Context<'_>, item: &clean::Item, buf: &mut Buffer,
9494
render_stability_since_raw(
9595
buf,
9696
item.stable_since(cx.tcx()).as_deref(),
97-
item.const_stable_since(cx.tcx()).as_deref(),
97+
item.const_stability(cx.tcx()),
9898
None,
9999
None,
100100
);
@@ -1291,7 +1291,7 @@ fn render_stability_since(
12911291
render_stability_since_raw(
12921292
w,
12931293
item.stable_since(tcx).as_deref(),
1294-
item.const_stable_since(tcx).as_deref(),
1294+
item.const_stability(tcx),
12951295
containing_item.stable_since(tcx).as_deref(),
12961296
containing_item.const_stable_since(tcx).as_deref(),
12971297
)

src/test/rustdoc/const-display.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![feature(staged_api)]
99

1010
// @has 'foo/fn.foo.html' '//pre' 'pub unsafe fn foo() -> u32'
11+
// @has - '//span[@class="since"]' '1.0.0 (const: unstable)'
1112
#[stable(feature = "rust1", since = "1.0.0")]
1213
#[rustc_const_unstable(feature="foo", issue = "none")]
1314
pub const unsafe fn foo() -> u32 { 42 }
@@ -39,6 +40,7 @@ pub struct Foo;
3940

4041
impl Foo {
4142
// @has 'foo/struct.Foo.html' '//div[@id="method.gated"]/code' 'pub unsafe fn gated() -> u32'
43+
// @has - '//span[@class="since"]' '1.0.0 (const: unstable)'
4244
#[stable(feature = "rust1", since = "1.0.0")]
4345
#[rustc_const_unstable(feature="foo", issue = "none")]
4446
pub const unsafe fn gated() -> u32 { 42 }

0 commit comments

Comments
 (0)