about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-04-11 20:06:06 +0000
committerbors <bors@rust-lang.org>2025-04-11 20:06:06 +0000
commitd2b3dd7c173de58881ead8109f7970b9cd926e2a (patch)
tree48ccfce095356e8edf1cbb247de02de9f37e7bb0 /compiler/rustc_data_structures/src
parented3a4aac8172c599c181120bddd2840843ecc9ad (diff)
parentc8992c90e003ada16d956bdf814f3d109c98dd31 (diff)
Auto merge of #139689 - jhpratt:rollup-wlkdyjg, r=jhpratt
Rollup of 7 pull requests

Successful merges:

 - #137835 (Use `BinOp::Cmp` for `iNN::signum`)
 - #139584 (Avoid a reverse map that is only used in diagnostics paths)
 - #139638 (Cleanup the `InstSimplify` MIR transformation)
 - #139653 (Handle a negated literal in `eat_token_lit`.)
 - #139662 (Tweak `DefPathData`)
 - #139664 (Reuse address-space computation from global alloc)
 - #139687 (Add spastorino to users_on_vacation)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_data_structures/src')
-rw-r--r--compiler/rustc_data_structures/src/unord.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/unord.rs b/compiler/rustc_data_structures/src/unord.rs
index baa66cd7c85..3d44fb1fd48 100644
--- a/compiler/rustc_data_structures/src/unord.rs
+++ b/compiler/rustc_data_structures/src/unord.rs
@@ -109,6 +109,16 @@ impl<T, I: Iterator<Item = T>> UnordItems<T, I> {
     pub fn collect<C: From<UnordItems<T, I>>>(self) -> C {
         self.into()
     }
+
+    /// If the iterator has only one element, returns it, otherwise returns `None`.
+    #[track_caller]
+    pub fn get_only(mut self) -> Option<T> {
+        let item = self.0.next();
+        if self.0.next().is_some() {
+            return None;
+        }
+        item
+    }
 }
 
 impl<T> UnordItems<T, std::iter::Empty<T>> {