From a891139df1f7b3c8c4a07b3d6ca79a459d6d81d1 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 14 Mar 2025 17:18:41 +0300 Subject: resolve: Avoid some unstable iteration --- compiler/rustc_data_structures/src/unord.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'compiler/rustc_data_structures') 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 UnordSet { 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) -- cgit 1.4.1-3-g733a5