diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs index 740bf7253..2b407403e 100644 --- a/crates/common/src/lib.rs +++ b/crates/common/src/lib.rs @@ -1360,11 +1360,6 @@ pub fn new(value: T, on_drop: F) -> Self { Self(Some((value, on_drop))) } - /// Invokes the callback, consuming the ScopeGuard. - pub fn commit(guard: Self) { - std::mem::drop(guard); - } - /// Cancels the invocation of the callback, returning the original wrapped value. pub fn cancel(mut guard: Self) -> T { let (value, _) = guard.0.take().expect("Should always have Some value"); @@ -1397,12 +1392,7 @@ fn drop(&mut self) { /// A trait expressing what ScopeGuard can do. This is necessary because our scoped cells return an /// `impl Trait` object and therefore methods on ScopeGuard which take a self parameter cannot be /// used. -pub trait ScopeGuarding: DerefMut + Sized { - /// Invokes the callback, consuming the guard. - fn commit(guard: Self) { - std::mem::drop(guard); - } -} +pub trait ScopeGuarding: DerefMut + Sized {} impl ScopeGuarding for ScopeGuard {} @@ -1561,17 +1551,17 @@ fn test_scope_guard() { counter.fetch_add(1, relaxed); }); assert_eq!(counter.load(relaxed), 0); - std::mem::drop(guard); + drop(guard); assert_eq!(counter.load(relaxed), 1); } - // commit also invokes the callback. + // The callback is invoked on drop { let guard = ScopeGuard::new(123, |arg| { assert_eq!(arg, 123); counter.fetch_add(1, relaxed); }); assert_eq!(counter.load(relaxed), 1); - ScopeGuard::commit(guard); + drop(guard); assert_eq!(counter.load(relaxed), 2); } } diff --git a/src/parse_execution.rs b/src/parse_execution.rs index dd6908858..9e6e96239 100644 --- a/src/parse_execution.rs +++ b/src/parse_execution.rs @@ -56,7 +56,7 @@ trace::{trace_if_enabled, trace_if_enabled_with_args}, wildcard::wildcard_match, }; -use fish_common::{ScopeGuard, ScopeGuarding, escape, help_section, truncate_at_nul}; +use fish_common::{ScopeGuard, escape, help_section, truncate_at_nul}; use fish_widestring::WExt as _; use libc::{ENOTDIR, EXIT_SUCCESS, STDERR_FILENO, STDOUT_FILENO, c_int}; use std::{io::ErrorKind, rc::Rc, sync::Arc}; @@ -1645,7 +1645,7 @@ fn run_1_job( // Populate the job. This may fail for reasons like command_not_found. If this fails, an error // will have been printed. let pop_result = self.populate_job_from_job_node(ctx, &mut job, job_node, associated_block); - ScopeGuarding::commit(_caller_id); + drop(_caller_id); // Clean up the job on failure or cancellation. if pop_result == EndExecutionReason::Ok { diff --git a/src/parser.rs b/src/parser.rs index a5709d977..1d97119d6 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -694,7 +694,7 @@ pub fn eval_node( let new_exec_count = self.libdata().exec_count; let new_status_count = self.libdata().status_count; - ScopeGuarding::commit(restore_current_node); + drop(restore_current_node); self.pop_block(scope_block); job_reap(self, false, Some(block_io)); // reap again