rustdoc: Show "const" for const-unstable if also overall unstable
If a const function is unstable overall (and thus, in all circumstances I know of, also const-unstable), we should show the option to use it as const. You need to enable a feature to use the function at all anyway. If the function is stabilized without also being const-stabilized, then we do not show the const keyword and instead show "const: unstable" in the version info.
This commit is contained in:
parent
fa7a3f9049
commit
699d28f968
5 changed files with 39 additions and 20 deletions
|
@ -627,7 +627,7 @@ impl Item {
|
||||||
) -> hir::FnHeader {
|
) -> hir::FnHeader {
|
||||||
let sig = tcx.fn_sig(def_id).skip_binder();
|
let sig = tcx.fn_sig(def_id).skip_binder();
|
||||||
let constness =
|
let constness =
|
||||||
if tcx.is_const_fn(def_id) && is_unstable_const_fn(tcx, def_id).is_none() {
|
if tcx.is_const_fn(def_id) || is_unstable_const_fn(tcx, def_id).is_some() {
|
||||||
hir::Constness::Const
|
hir::Constness::Const
|
||||||
} else {
|
} else {
|
||||||
hir::Constness::NotConst
|
hir::Constness::NotConst
|
||||||
|
@ -649,9 +649,8 @@ impl Item {
|
||||||
hir::Safety::Unsafe
|
hir::Safety::Unsafe
|
||||||
},
|
},
|
||||||
abi,
|
abi,
|
||||||
constness: if abi == Abi::RustIntrinsic
|
constness: if tcx.is_const_fn(def_id)
|
||||||
&& tcx.is_const_fn(def_id)
|
|| is_unstable_const_fn(tcx, def_id).is_some()
|
||||||
&& is_unstable_const_fn(tcx, def_id).is_none()
|
|
||||||
{
|
{
|
||||||
hir::Constness::Const
|
hir::Constness::Const
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -13,7 +13,7 @@ use std::fmt::{self, Display, Write};
|
||||||
use std::iter::{self, once};
|
use std::iter::{self, once};
|
||||||
|
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_attr::{ConstStability, StabilityLevel};
|
use rustc_attr::{ConstStability, StabilityLevel, StableSince};
|
||||||
use rustc_data_structures::captures::Captures;
|
use rustc_data_structures::captures::Captures;
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
|
@ -1633,17 +1633,24 @@ impl PrintWithSpace for hir::Mutability {
|
||||||
|
|
||||||
pub(crate) fn print_constness_with_space(
|
pub(crate) fn print_constness_with_space(
|
||||||
c: &hir::Constness,
|
c: &hir::Constness,
|
||||||
s: Option<ConstStability>,
|
overall_stab: Option<StableSince>,
|
||||||
|
const_stab: Option<ConstStability>,
|
||||||
) -> &'static str {
|
) -> &'static str {
|
||||||
match (c, s) {
|
match c {
|
||||||
// const stable or when feature(staged_api) is not set
|
hir::Constness::Const => match (overall_stab, const_stab) {
|
||||||
(
|
// const stable...
|
||||||
hir::Constness::Const,
|
(_, Some(ConstStability { level: StabilityLevel::Stable { .. }, .. }))
|
||||||
Some(ConstStability { level: StabilityLevel::Stable { .. }, .. }),
|
// ...or when feature(staged_api) is not set...
|
||||||
)
|
| (_, None)
|
||||||
| (hir::Constness::Const, None) => "const ",
|
// ...or when const unstable, but overall unstable too
|
||||||
// const unstable or not const
|
| (None, Some(ConstStability { level: StabilityLevel::Unstable { .. }, .. })) => {
|
||||||
_ => "",
|
"const "
|
||||||
|
}
|
||||||
|
// const unstable (and overall stable)
|
||||||
|
(Some(_), Some(ConstStability { level: StabilityLevel::Unstable { .. }, .. })) => "",
|
||||||
|
},
|
||||||
|
// not const
|
||||||
|
hir::Constness::NotConst => "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -928,9 +928,11 @@ fn assoc_method(
|
||||||
// FIXME: Once https://github.com/rust-lang/rust/issues/67792 is implemented, we can remove
|
// FIXME: Once https://github.com/rust-lang/rust/issues/67792 is implemented, we can remove
|
||||||
// this condition.
|
// this condition.
|
||||||
let constness = match render_mode {
|
let constness = match render_mode {
|
||||||
RenderMode::Normal => {
|
RenderMode::Normal => print_constness_with_space(
|
||||||
print_constness_with_space(&header.constness, meth.const_stability(tcx))
|
&header.constness,
|
||||||
}
|
meth.stable_since(tcx),
|
||||||
|
meth.const_stability(tcx),
|
||||||
|
),
|
||||||
RenderMode::ForDeref { .. } => "",
|
RenderMode::ForDeref { .. } => "",
|
||||||
};
|
};
|
||||||
let asyncness = header.asyncness.print_with_space();
|
let asyncness = header.asyncness.print_with_space();
|
||||||
|
|
|
@ -615,7 +615,18 @@ fn extra_info_tags<'a, 'tcx: 'a>(
|
||||||
fn item_function(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, f: &clean::Function) {
|
fn item_function(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, f: &clean::Function) {
|
||||||
let tcx = cx.tcx();
|
let tcx = cx.tcx();
|
||||||
let header = it.fn_header(tcx).expect("printing a function which isn't a function");
|
let header = it.fn_header(tcx).expect("printing a function which isn't a function");
|
||||||
let constness = print_constness_with_space(&header.constness, it.const_stability(tcx));
|
debug!(
|
||||||
|
"item_function/const: {:?} {:?} {:?} {:?}",
|
||||||
|
it.name,
|
||||||
|
&header.constness,
|
||||||
|
it.stable_since(tcx),
|
||||||
|
it.const_stability(tcx),
|
||||||
|
);
|
||||||
|
let constness = print_constness_with_space(
|
||||||
|
&header.constness,
|
||||||
|
it.stable_since(tcx),
|
||||||
|
it.const_stability(tcx),
|
||||||
|
);
|
||||||
let safety = header.safety.print_with_space();
|
let safety = header.safety.print_with_space();
|
||||||
let abi = print_abi_with_space(header.abi).to_string();
|
let abi = print_abi_with_space(header.abi).to_string();
|
||||||
let asyncness = header.asyncness.print_with_space();
|
let asyncness = header.asyncness.print_with_space();
|
||||||
|
|
|
@ -24,7 +24,7 @@ pub const unsafe fn foo_unsafe() -> u32 { 42 }
|
||||||
#[unstable(feature = "humans", issue = "none")]
|
#[unstable(feature = "humans", issue = "none")]
|
||||||
pub const fn foo2() -> u32 { 42 }
|
pub const fn foo2() -> u32 { 42 }
|
||||||
|
|
||||||
// @has 'foo/fn.foo3.html' '//pre' 'pub fn foo3() -> u32'
|
// @has 'foo/fn.foo3.html' '//pre' 'pub const fn foo3() -> u32'
|
||||||
// @!hasraw - '//span[@class="since"]'
|
// @!hasraw - '//span[@class="since"]'
|
||||||
#[unstable(feature = "humans", issue = "none")]
|
#[unstable(feature = "humans", issue = "none")]
|
||||||
#[rustc_const_unstable(feature = "humans", issue = "none")]
|
#[rustc_const_unstable(feature = "humans", issue = "none")]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue