Skip to content

Commit

Permalink
rustdoc: Elide const-unstable if also unstable overall
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
camelid committed May 26, 2024
1 parent 72d8d8d commit fa7a3f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,18 +1016,23 @@ fn render_stability_since_raw_with_extra(
.map(|since| (format!("const since {since}"), format!("const: {since}")))
}
Some(ConstStability { level: StabilityLevel::Unstable { issue, .. }, feature, .. }) => {
let unstable = if let Some(n) = issue {
format!(
"<a \
if stable_version.is_none() {
// don't display const unstable if entirely unstable
None
} else {
let unstable = if let Some(n) = issue {
format!(
"<a \
href=\"https://github.com/rust-lang/rust/issues/{n}\" \
title=\"Tracking issue for {feature}\"\
>unstable</a>"
)
} else {
String::from("unstable")
};
)
} else {
String::from("unstable")
};

Some((String::from("const unstable"), format!("const: {unstable}")))
Some((String::from("const unstable"), format!("const: {unstable}")))
}
}
_ => None,
};
Expand Down
6 changes: 6 additions & 0 deletions tests/rustdoc/const-display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ pub const unsafe fn foo_unsafe() -> u32 { 42 }
#[unstable(feature = "humans", issue = "none")]
pub const fn foo2() -> u32 { 42 }

// @has 'foo/fn.foo3.html' '//pre' 'pub fn foo3() -> u32'
// @!hasraw - '//span[@class="since"]'
#[unstable(feature = "humans", issue = "none")]
#[rustc_const_unstable(feature = "humans", issue = "none")]
pub const fn foo3() -> u32 { 42 }

// @has 'foo/fn.bar2.html' '//pre' 'pub const fn bar2() -> u32'
// @has - //span '1.0.0 (const: 1.0.0)'
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down

0 comments on commit fa7a3f9

Please sign in to comment.