Auto merge of #125599 - camelid:clarify-stability, r=notriddle,Guilla… · rust-lang/rust@f00b02e
@@ -13,7 +13,7 @@ use std::fmt::{self, Display, Write};
1313use std::iter::{self, once};
14141515use rustc_ast as ast;
16-use rustc_attr::{ConstStability, StabilityLevel};
16+use rustc_attr::{ConstStability, StabilityLevel, StableSince};
1717use rustc_data_structures::captures::Captures;
1818use rustc_data_structures::fx::FxHashSet;
1919use rustc_hir as hir;
@@ -1633,17 +1633,24 @@ impl PrintWithSpace for hir::Mutability {
1633163316341634pub(crate) fn print_constness_with_space(
16351635c: &hir::Constness,
1636-s: Option<ConstStability>,
1636+overall_stab: Option<StableSince>,
1637+const_stab: Option<ConstStability>,
16371638) -> &'static str {
1638-match (c, s) {
1639-// const stable or when feature(staged_api) is not set
1640-(
1641- hir::Constness::Const,
1642-Some(ConstStability { level: StabilityLevel::Stable { .. }, .. }),
1643-)
1644- | (hir::Constness::Const, None) => "const ",
1645-// const unstable or not const
1646- _ => "",
1639+match c {
1640+ hir::Constness::Const => match (overall_stab, const_stab) {
1641+// const stable...
1642+(_, Some(ConstStability { level: StabilityLevel::Stable { .. }, .. }))
1643+// ...or when feature(staged_api) is not set...
1644+ | (_, None)
1645+// ...or when const unstable, but overall unstable too
1646+ | (None, Some(ConstStability { level: StabilityLevel::Unstable { .. }, .. })) => {
1647+"const "
1648+}
1649+// const unstable (and overall stable)
1650+(Some(_), Some(ConstStability { level: StabilityLevel::Unstable { .. }, .. })) => "",
1651+},
1652+// not const
1653+ hir::Constness::NotConst => "",
16471654}
16481655}
16491656