diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2025-03-14 17:18:41 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2025-03-14 18:34:08 +0300 |
| commit | a891139df1f7b3c8c4a07b3d6ca79a459d6d81d1 (patch) | |
| tree | d355ba721269c1ab3398f07ee2ec8cde50393dbf /compiler/rustc_data_structures/src | |
| parent | f7b43542838f0a4a6cfdb17fbeadf45002042a77 (diff) | |
resolve: Avoid some unstable iteration
Diffstat (limited to 'compiler/rustc_data_structures/src')
| -rw-r--r-- | compiler/rustc_data_structures/src/unord.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/unord.rs b/compiler/rustc_data_structures/src/unord.rs index 34895d3efe6..90a77e1e580 100644 --- a/compiler/rustc_data_structures/src/unord.rs +++ b/compiler/rustc_data_structures/src/unord.rs @@ -259,6 +259,12 @@ impl<V: Eq + Hash> UnordSet<V> { self.inner.is_empty() } + /// If the set has only one element, returns it, otherwise returns `None`. + #[inline] + pub fn get_only(&self) -> Option<&V> { + if self.inner.len() == 1 { self.inner.iter().next() } else { None } + } + #[inline] pub fn insert(&mut self, v: V) -> bool { self.inner.insert(v) |
