1
Fork 0

Switch rustdoc from clean::Stability to rustc_attr::Stability

This gives greater type safety and is less work to maintain on the
rustdoc end.
This commit is contained in:
Joshua Nelson 2020-10-11 09:55:17 -04:00
parent c38f001db5
commit cc0d140bae
5 changed files with 59 additions and 59 deletions

View file

@ -9,6 +9,7 @@ use rustc_session::parse::{feature_err, ParseSess};
use rustc_session::Session;
use rustc_span::hygiene::Transparency;
use rustc_span::{symbol::sym, symbol::Symbol, Span};
use std::cmp;
use std::num::NonZeroU32;
use version_check::Version;
@ -154,7 +155,7 @@ pub struct ConstStability {
}
/// The available stability levels.
#[derive(Encodable, Decodable, PartialEq, PartialOrd, Copy, Clone, Debug, Eq, Hash)]
#[derive(Encodable, Decodable, PartialEq, Copy, Clone, Debug, Eq, Hash)]
#[derive(HashStable_Generic)]
pub enum StabilityLevel {
// Reason for the current stability level and the relevant rust-lang issue
@ -162,6 +163,19 @@ pub enum StabilityLevel {
Stable { since: Symbol },
}
impl cmp::PartialOrd for StabilityLevel {
// This only take into account stability, not any fields.
// Therefore it is only `PartialOrd` and not `Ord`.
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
match (self, other) {
(Self::Unstable { .. }, Self::Unstable { .. }) => Some(cmp::Ordering::Equal),
(Self::Stable { .. }, Self::Stable { .. }) => Some(cmp::Ordering::Equal),
(Self::Unstable { .. }, Self::Stable { .. }) => Some(cmp::Ordering::Less),
(Self::Stable { .. }, Self::Unstable { .. }) => Some(cmp::Ordering::Greater),
}
}
}
impl StabilityLevel {
pub fn is_unstable(&self) -> bool {
matches!(self, StabilityLevel::Unstable { .. })