Skip to content

Commit 44ebf49

Browse files
committed
Rely on scope cleanup for redundant explicit drops
Preserve callback ownership, release ordering, and retained argument owners. Assisted-by: Codex:model-version-unavailable
1 parent e82a315 commit 44ebf49

1 file changed

Lines changed: 4 additions & 13 deletions

File tree

‎crates/vm/src/stdlib/builtins.rs‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,11 @@ mod builtins {
7373
match next(&iter, vm)? {
7474
PyIterReturn::Return(item) => {
7575
let truth = item.try_to_bool(vm);
76-
drop(item);
7776
if truth? == short_circuit {
7877
return Ok(short_circuit);
7978
}
8079
}
81-
PyIterReturn::StopIteration(value) => {
82-
drop(value);
80+
PyIterReturn::StopIteration(_value) => {
8381
return Ok(!short_circuit);
8482
}
8583
}
@@ -1078,15 +1076,11 @@ mod builtins {
10781076
} else {
10791077
// Rejected candidates have the opposite release order.
10801078
drop(item);
1081-
drop(key);
10821079
}
10831080
}
10841081

10851082
match best {
1086-
Some(MinMaxBest { key, item }) => {
1087-
drop(key);
1088-
Ok(item)
1089-
}
1083+
Some(MinMaxBest { key: _key, item }) => Ok(item),
10901084
None => default.cloned().ok_or_else(|| {
10911085
vm.new_value_error(format!("{func_name}() iterable argument is empty"))
10921086
}),
@@ -1320,10 +1314,10 @@ mod builtins {
13201314
#[pyfunction]
13211315
fn sum(SumArgs { iterable, start }: SumArgs, vm: &VirtualMachine) -> PyResult {
13221316
// Acquire and validate the iterator before rejecting a start type.
1323-
let mut items = iterable.get_iter(vm)?.into_iter::<PyObjectRef>(vm);
1317+
let items = iterable.get_iter(vm)?.into_iter::<PyObjectRef>(vm);
13241318
// Keep the original argument alive independently of the accumulator.
13251319
// Declaring the accumulator last also releases it before the iterator.
1326-
let mut sum = start.clone();
1320+
let (_start, mut items, mut sum) = (start.clone(), items, start);
13271321

13281322
match_class!(match sum {
13291323
PyStr =>
@@ -1419,11 +1413,8 @@ mod builtins {
14191413
// On both success and failure, release the old total before the
14201414
// item, and only then propagate an addition error to the iterator.
14211415
drop(sum);
1422-
drop(item);
14231416
sum = result?;
14241417
}
1425-
drop(items);
1426-
drop(start);
14271418
Ok(sum)
14281419
}
14291420

0 commit comments

Comments
 (0)