Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move PartialOrd impl out of rustc
Rustdoc's ordering requirements are probably not relevant to the rest of
the compiler.
  • Loading branch information
jyn514 committed Oct 11, 2020
1 parent 85c0479 commit 96b0446
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
14 changes: 0 additions & 14 deletions compiler/rustc_attr/src/builtin.rs
Expand Up @@ -9,7 +9,6 @@ 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;

Expand Down Expand Up @@ -163,19 +162,6 @@ 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 { .. })
Expand Down
12 changes: 6 additions & 6 deletions src/librustdoc/html/render/mod.rs
Expand Up @@ -1984,12 +1984,12 @@ fn item_module(w: &mut Buffer, cx: &Context, item: &clean::Item, items: &[clean:
}
let s1 = i1.stability.as_ref().map(|s| s.level);
let s2 = i2.stability.as_ref().map(|s| s.level);
match (s1, s2) {
(Some(a), Some(b)) => match a.partial_cmp(&b) {
Some(Ordering::Equal) | None => {}
Some(other) => return other,
},
_ => {}
if let (Some(a), Some(b)) = (s1, s2) {
match (a.is_stable(), b.is_stable()) {
(true, true) | (false, false) => {}
(false, true) => return Ordering::Less,
(true, false) => return Ordering::Greater,
}
}
let lhs = i1.name.as_ref().map_or("", |s| &**s);
let rhs = i2.name.as_ref().map_or("", |s| &**s);
Expand Down

0 comments on commit 96b0446

Please sign in to comment.