avoid embedding StabilityLevel::Unstable reason string into metadata multiple times
This commit is contained in:
parent
1673f1450e
commit
b38c94857d
5 changed files with 46 additions and 9 deletions
|
@ -138,7 +138,7 @@ pub enum StabilityLevel {
|
|||
/// `#[unstable]`
|
||||
Unstable {
|
||||
/// Reason for the current stability level.
|
||||
reason: Option<Symbol>,
|
||||
reason: UnstableReason,
|
||||
/// Relevant `rust-lang/rust` issue.
|
||||
issue: Option<NonZeroU32>,
|
||||
is_soft: bool,
|
||||
|
@ -182,6 +182,32 @@ impl StabilityLevel {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Encodable, Decodable, PartialEq, Copy, Clone, Debug, Eq, Hash)]
|
||||
#[derive(HashStable_Generic)]
|
||||
pub enum UnstableReason {
|
||||
None,
|
||||
Default,
|
||||
Some(Symbol),
|
||||
}
|
||||
|
||||
impl UnstableReason {
|
||||
fn from_opt_reason(reason: Option<Symbol>) -> Self {
|
||||
// UnstableReason::Default constructed manually
|
||||
match reason {
|
||||
Some(r) => Self::Some(r),
|
||||
None => Self::None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_opt_reason(&self) -> Option<Symbol> {
|
||||
match self {
|
||||
Self::None => None,
|
||||
Self::Default => Some(sym::unstable_location_reason_default),
|
||||
Self::Some(r) => Some(*r),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Collects stability info from all stability attributes in `attrs`.
|
||||
/// Returns `None` if no stability attributes are found.
|
||||
pub fn find_stability(
|
||||
|
@ -371,7 +397,12 @@ where
|
|||
);
|
||||
continue;
|
||||
}
|
||||
let level = Unstable { reason, issue: issue_num, is_soft, implied_by };
|
||||
let level = Unstable {
|
||||
reason: UnstableReason::from_opt_reason(reason),
|
||||
issue: issue_num,
|
||||
is_soft,
|
||||
implied_by,
|
||||
};
|
||||
if sym::unstable == meta_name {
|
||||
stab = Some((Stability { level, feature }, attr.span));
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue