Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/cfg/src/lib.rs')
| -rw-r--r-- | crates/cfg/src/lib.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/crates/cfg/src/lib.rs b/crates/cfg/src/lib.rs index 08545b6851..906106ca5d 100644 --- a/crates/cfg/src/lib.rs +++ b/crates/cfg/src/lib.rs @@ -9,7 +9,7 @@ use std::fmt; use rustc_hash::FxHashSet; -use intern::{sym, Symbol}; +use intern::{Symbol, sym}; pub use cfg_expr::{CfgAtom, CfgExpr}; pub use dnf::DnfExpr; @@ -31,7 +31,7 @@ pub struct CfgOptions { impl Default for CfgOptions { fn default() -> Self { - Self { enabled: FxHashSet::from_iter([CfgAtom::Flag(sym::true_.clone())]) } + Self { enabled: FxHashSet::from_iter([CfgAtom::Flag(sym::true_)]) } } } @@ -104,6 +104,17 @@ impl CfgOptions { _ => None, }) } + + pub fn to_hashable(&self) -> HashableCfgOptions { + let mut enabled = self.enabled.iter().cloned().collect::<Box<[_]>>(); + enabled.sort_unstable(); + HashableCfgOptions { _enabled: enabled } + } + + #[inline] + pub fn shrink_to_fit(&mut self) { + self.enabled.shrink_to_fit(); + } } impl Extend<CfgAtom> for CfgOptions { @@ -256,3 +267,9 @@ impl fmt::Display for InactiveReason { Ok(()) } } + +/// A `CfgOptions` that implements `Hash`, for the sake of hashing only. +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct HashableCfgOptions { + _enabled: Box<[CfgAtom]>, +} |