about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-04-29 21:06:15 +0000
committerbors <bors@rust-lang.org>2025-04-29 21:06:15 +0000
commit0fbb922e530399599aab8296ea975cb9e7ed67bf (patch)
tree349bbdee8d04a4735b3bc6f63b59087e3ff911ba /compiler/rustc_mir_transform/src
parent74509131e85a97353c67c503ea32e148a56cf4bd (diff)
parentd0d3021bf830e585e6bb5df43eb4ae90a54ddf31 (diff)
downloadrust-0fbb922e530399599aab8296ea975cb9e7ed67bf.tar.gz
rust-0fbb922e530399599aab8296ea975cb9e7ed67bf.zip
Auto merge of #140023 - cjgillot:arena-try-alloc, r=BoxyUwU
Introduce Arena::try_alloc_from_iter.

`alloc_from_iter` already collects the iterator for reentrancy. So adding an early exit for a fallible iterator integrates naturally into the code. This avoids the other solution to allocate and dump the allocation.
Diffstat (limited to 'compiler/rustc_mir_transform/src')
-rw-r--r--compiler/rustc_mir_transform/src/jump_threading.rs12
1 files changed, 2 insertions, 10 deletions
diff --git a/compiler/rustc_mir_transform/src/jump_threading.rs b/compiler/rustc_mir_transform/src/jump_threading.rs
index 9732225e48d..ada2c0b76cf 100644
--- a/compiler/rustc_mir_transform/src/jump_threading.rs
+++ b/compiler/rustc_mir_transform/src/jump_threading.rs
@@ -177,16 +177,8 @@ impl<'a> ConditionSet<'a> {
         arena: &'a DroplessArena,
         f: impl Fn(Condition) -> Option<Condition>,
     ) -> Option<ConditionSet<'a>> {
-        let mut all_ok = true;
-        let set = arena.alloc_from_iter(self.iter().map_while(|c| {
-            if let Some(c) = f(c) {
-                Some(c)
-            } else {
-                all_ok = false;
-                None
-            }
-        }));
-        all_ok.then_some(ConditionSet(set))
+        let set = arena.try_alloc_from_iter(self.iter().map(|c| f(c).ok_or(()))).ok()?;
+        Some(ConditionSet(set))
     }
 }