Skip to content

Commit

Permalink
shell: Refactor to avoid lint complaining about dropping reference
Browse files Browse the repository at this point in the history
The lint is right in that dropping the reference does little, but it
ensures that the reference is not held longer than the lock. Using an
explicit scope achieves the same without any discussions about the drop.
  • Loading branch information
chrysn committed Oct 15, 2023
1 parent b9fbcec commit c61b609
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ pub unsafe trait CommandListInternals: Sized {
let sleeve = lock
.as_ref()
.expect("Callback called while no shell set up as running");
// unsafe: A suitable callback is always configured. We can make a &mut out of it for as
// long as we hold the lock.
let root = unsafe { &mut *(sleeve.0 as *mut Self) };
let result = root.find_self_and_run(argc, argv, command_index);
drop(root);
let result;
{
// unsafe: A suitable callback is always configured. We can make a &mut out of it for as
// long as we hold the lock.
let root = unsafe { &mut *(sleeve.0 as *mut Self) };
result = root.find_self_and_run(argc, argv, command_index);
}
drop(lock);
result
}
Expand Down

0 comments on commit c61b609

Please sign in to comment.