Skip to content

Commit a6a4c78

Browse files
authored
refactor(lowering): Using as_mut instead of take + assignment. (#9867)
1 parent 9811014 commit a6a4c78

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

  • crates/cairo-lang-lowering/src/lower

crates/cairo-lang-lowering/src/lower/mod.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,19 +1565,16 @@ fn lower_expr_loop<'db>(
15651565
.intern(db);
15661566

15671567
// Generate the function.
1568-
let encapsulating_ctx = ctx.encapsulating_ctx.take().unwrap();
1569-
let loop_ctx = LoopContext { loop_expr_id, early_return_info: early_return_info.clone() };
1568+
let encapsulating_ctx = ctx.encapsulating_ctx.as_mut().unwrap();
15701569
let lowered = lower_loop_function(
15711570
encapsulating_ctx,
15721571
function,
15731572
loop_signature.clone(),
1574-
loop_ctx,
1573+
LoopContext { loop_expr_id, early_return_info: early_return_info.clone() },
15751574
ctx.return_type,
15761575
)
15771576
.map_err(LoweringFlowError::Failed)?;
1578-
// TODO(spapini): Recursive call.
15791577
encapsulating_ctx.lowerings.insert(GeneratedFunctionKey::Loop(stable_ptr), lowered);
1580-
ctx.encapsulating_ctx = Some(encapsulating_ctx);
15811578
let call_loop_expr = call_loop_func_ex(
15821579
ctx,
15831580
loop_signature,
@@ -1949,16 +1946,14 @@ fn add_capture_destruct_impl<'db>(
19491946

19501947
let location_id = LocationId::from_stable_location(db, location);
19511948

1952-
let encapsulating_ctx = ctx.encapsulating_ctx.take().unwrap();
1949+
let encapsulating_ctx = ctx.encapsulating_ctx.as_mut().unwrap();
19531950
let return_type = signature.return_type;
19541951
let lowered_impl_res = get_destruct_lowering(
19551952
LoweringContext::new(encapsulating_ctx, function_id, signature, return_type)?,
19561953
location_id,
19571954
closure_info,
1958-
);
1959-
// Restore the encapsulating context before unwrapping the result.
1960-
ctx.encapsulating_ctx = Some(encapsulating_ctx);
1961-
ctx.lowerings.insert(func_key, lowered_impl_res?);
1955+
)?;
1956+
ctx.lowerings.insert(func_key, lowered_impl_res);
19621957
Ok(())
19631958
}
19641959

0 commit comments

Comments
 (0)