diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-03-15 11:29:26 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-15 11:29:26 +0100 |
| commit | 232ec5caeac4034f0ada5d7b159d86999f4d5aa0 (patch) | |
| tree | c322bace915e46c843c246479064ca3647cf34d2 /compiler/rustc_data_structures/src | |
| parent | 06b135f6bc4bf6df4f0fd9d7a625d168597b05df (diff) | |
| parent | a891139df1f7b3c8c4a07b3d6ca79a459d6d81d1 (diff) | |
| download | rust-232ec5caeac4034f0ada5d7b159d86999f4d5aa0.tar.gz rust-232ec5caeac4034f0ada5d7b159d86999f4d5aa0.zip | |
Rollup merge of #138502 - petrochenkov:resinstab, r=compiler-errors
resolve: Avoid some unstable iteration This PR replaces https://github.com/rust-lang/rust/pull/131213.
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) |
