1
Fork 0

Check for const_unstable before printing const

This commit is contained in:
Deadbeef 2021-06-20 08:39:54 +08:00
parent 9c495b30ef
commit 5fb27bca6c
No known key found for this signature in database
GPG key ID: 6525773485376D92
4 changed files with 65 additions and 44 deletions

View file

@ -9,6 +9,7 @@ use std::cell::Cell;
use std::fmt;
use std::iter;
use rustc_attr::{ConstStability, StabilityLevel};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir;
@ -1253,15 +1254,6 @@ impl PrintWithSpace for hir::Unsafety {
}
}
impl PrintWithSpace for hir::Constness {
fn print_with_space(&self) -> &str {
match self {
hir::Constness::Const => "const ",
hir::Constness::NotConst => "",
}
}
}
impl PrintWithSpace for hir::IsAsync {
fn print_with_space(&self) -> &str {
match self {
@ -1280,6 +1272,22 @@ impl PrintWithSpace for hir::Mutability {
}
}
crate fn print_constness_with_space(
c: &hir::Constness,
s: Option<&ConstStability>,
) -> &'static str {
match (c, s) {
// const stable or no stability attribute
(
hir::Constness::Const,
Some(ConstStability { level: StabilityLevel::Stable { .. }, .. }),
)
| (hir::Constness::Const, None) => "const ",
// const unstable or not const
(hir::Constness::Const, _) | (hir::Constness::NotConst, _) => "",
}
}
impl clean::Import {
crate fn print<'a, 'tcx: 'a>(
&'a self,