diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs index 4fe0fdae5..5cb9589e8 100644 --- a/crates/common/src/lib.rs +++ b/crates/common/src/lib.rs @@ -1232,7 +1232,7 @@ pub fn new(value: T) -> Self { pub fn scoped_mod<'a, Modifier: FnOnce(&mut T)>( &'a self, modifier: Modifier, - ) -> impl ScopeGuarding + 'a { + ) -> impl DerefMut + 'a { let mut val = self.get(); modifier(&mut val); let saved = self.replace(val); @@ -1290,7 +1290,7 @@ pub fn scoped_set<'a, Accessor, Value: 'a>( &'a self, value: Value, accessor: Accessor, - ) -> impl ScopeGuarding + 'a + ) -> impl DerefMut + 'a where Accessor: Fn(&mut T) -> &mut Value + 'a, { @@ -1320,7 +1320,7 @@ pub fn scoped_set<'a, Accessor, Value: 'a>( /// /// assert_eq!(*cell.borrow(), 10); /// ``` - pub fn scoped_replace<'a>(&'a self, value: T) -> impl ScopeGuarding + 'a { + pub fn scoped_replace<'a>(&'a self, value: T) -> impl DerefMut + 'a { self.scoped_set(value, |s| s) } } @@ -1383,13 +1383,6 @@ 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 {} - -impl ScopeGuarding for ScopeGuard {} - pub const fn assert_send() {} pub const fn assert_sync() {} diff --git a/src/parser.rs b/src/parser.rs index 02b5d958b..0f0fe8dce 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -30,8 +30,7 @@ }; use assert_matches::assert_matches; use fish_common::{ - EscapeFlags, EscapeStringStyle, FilenameRef, ScopeGuarding, ScopedCell, ScopedRefCell, - escape_string, + EscapeFlags, EscapeStringStyle, FilenameRef, ScopedCell, ScopedRefCell, escape_string, }; use fish_util::get_time; use fish_widestring::{WExt as _, wcs2bytes}; @@ -41,6 +40,7 @@ use std::fs::File; use std::io::Write as _; use std::num::NonZeroU32; +use std::ops::DerefMut; use std::rc::Rc; use std::sync::Arc; use std::time::Duration; @@ -906,10 +906,7 @@ pub fn scope(&self) -> ScopedData { /// Modify the scoped values for the duration of the caller's scope (or whenever the ParserScope is dropped). /// This accepts a closure which modifies the ScopedData, and returns a ParserScope which restores the /// data when dropped. - pub fn push_scope<'a, F: FnOnce(&mut ScopedData)>( - &'a self, - modifier: F, - ) -> impl ScopeGuarding + 'a { + pub fn push_scope<'a, F: FnOnce(&mut ScopedData)>(&'a self, modifier: F) -> impl DerefMut + 'a { self.scoped_data.scoped_mod(modifier) } diff --git a/src/reader/reader.rs b/src/reader/reader.rs index 97847483a..92e8ecaf9 100644 --- a/src/reader/reader.rs +++ b/src/reader/reader.rs @@ -111,8 +111,8 @@ use assert_matches::assert_matches; use errno::{Errno, errno}; use fish_common::{ - EscapeFlags, EscapeStringStyle, ScopeGuard, ScopeGuarding, escape, escape_string, - escape_string_with_quote, exit_without_destructors, get_obfuscation_read_char, help_section, + EscapeFlags, EscapeStringStyle, ScopeGuard, escape, escape_string, escape_string_with_quote, + exit_without_destructors, get_obfuscation_read_char, help_section, restore_term_foreground_process_group_for_exit, write_loop, }; use fish_fallback::{fish_wcwidth, lowercase}; @@ -143,7 +143,7 @@ cmp, io::BufReader, num::NonZeroUsize, - ops::{ControlFlow, Range}, + ops::{ControlFlow, DerefMut, Range}, os::fd::{AsRawFd as _, BorrowedFd, FromRawFd as _, OwnedFd, RawFd}, pin::Pin, sync::{ @@ -424,7 +424,7 @@ pub fn reader_pop() { } } -pub fn fake_scoped_reader<'a>(parser: &'a Parser) -> impl ScopeGuarding> + 'a { +pub fn fake_scoped_reader<'a>(parser: &'a Parser) -> impl DerefMut> + 'a { let inputfd = -1; let conf = ReaderConfig { inputfd,