Skip to content

Commit 5909730

Browse files
committed
derive PartialOrd for Severity
The old custom implementation can be replaced by a derive with exactly the same behaviour, since the derive is based on the order the elements appear in in the source.
1 parent 8d1762e commit 5909730

1 file changed

Lines changed: 1 addition & 20 deletions

File tree

codespan-reporting/src/diagnostic.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::string::ToString;
1717
/// assert!(Severity::Warning > Severity::Note);
1818
/// assert!(Severity::Note > Severity::Help);
1919
/// ```
20-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
20+
#[derive(Copy, Clone, Hash, Debug, PartialEq, Eq, PartialOrd, Ord)]
2121
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
2222
pub enum Severity {
2323
/// An unexpected bug.
@@ -32,25 +32,6 @@ pub enum Severity {
3232
Help,
3333
}
3434

35-
impl Severity {
36-
/// We want bugs to be the maximum severity, errors next, etc...
37-
fn to_cmp_int(self) -> u8 {
38-
match self {
39-
Severity::Bug => 5,
40-
Severity::Error => 4,
41-
Severity::Warning => 3,
42-
Severity::Note => 2,
43-
Severity::Help => 1,
44-
}
45-
}
46-
}
47-
48-
impl PartialOrd for Severity {
49-
fn partial_cmp(&self, other: &Severity) -> Option<std::cmp::Ordering> {
50-
u8::partial_cmp(&self.to_cmp_int(), &other.to_cmp_int())
51-
}
52-
}
53-
5435
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd)]
5536
#[cfg_attr(feature = "serialization", derive(Serialize, Deserialize))]
5637
pub enum LabelStyle {

0 commit comments

Comments
 (0)