Split StableCompare trait out of StableOrd trait.
StableCompare is a companion trait to `StableOrd`. Some types like `Symbol` can be compared in a cross-session stable way, but their `Ord` implementation is not stable. In such cases, a `StableOrd` implementation can be provided to offer a lightweight way for stable sorting. (The more heavyweight option is to sort via `ToStableHashKey`, but then sorting needs to have access to a stable hashing context and `ToStableHashKey` can also be expensive as in the case of `Symbol` where it has to allocate a `String`.)
This commit is contained in:
parent
090d5eac72
commit
739e5ef49e
9 changed files with 118 additions and 22 deletions
|
@ -9,7 +9,9 @@ pub use self::Level::*;
|
|||
use rustc_ast::node_id::NodeId;
|
||||
use rustc_ast::{AttrId, Attribute};
|
||||
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
|
||||
use rustc_data_structures::stable_hasher::{
|
||||
HashStable, StableCompare, StableHasher, ToStableHashKey,
|
||||
};
|
||||
use rustc_error_messages::{DiagnosticMessage, MultiSpan};
|
||||
use rustc_hir::HashStableContext;
|
||||
use rustc_hir::HirId;
|
||||
|
@ -541,6 +543,14 @@ impl<HCX> ToStableHashKey<HCX> for LintId {
|
|||
}
|
||||
}
|
||||
|
||||
impl StableCompare for LintId {
|
||||
const CAN_USE_UNSTABLE_SORT: bool = true;
|
||||
|
||||
fn stable_cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||
self.lint_name_raw().cmp(&other.lint_name_raw())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AmbiguityErrorDiag {
|
||||
pub msg: String,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue