From c61b60906b0069e08b97cb42990d00022ae06eff Mon Sep 17 00:00:00 2001 From: chrysn Date: Sun, 15 Oct 2023 19:08:02 +0200 Subject: [PATCH] shell: Refactor to avoid lint complaining about dropping reference 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. --- src/shell.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/shell.rs b/src/shell.rs index b1a768d7..06a25d34 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -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 }