mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-12 03:41:14 -03:00
Remove ScopeGuard::commit in favor of drop
As of commit a296ee085c (Stop returning a value from ScopeGuarding::commit,
2025-03-15) "ScopeGuard::commit()" is equivalent to "drop()".
Let's use that instead.
This commit is contained in:
@@ -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<T, F: FnOnce(T)> ScopeGuarding for ScopeGuard<T, F> {}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -694,7 +694,7 @@ pub fn eval_node<T: 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
|
||||
|
||||
Reference in New Issue
Block a user