diff --git a/src/apperr.rs b/src/apperr.rs index b1dd6d20199..faa1aa41bb8 100644 --- a/src/apperr.rs +++ b/src/apperr.rs @@ -23,15 +23,15 @@ pub enum Error { impl Error { pub const fn new_app(code: u32) -> Self { - Error::App(code) + Self::App(code) } pub const fn new_icu(code: u32) -> Self { - Error::Icu(code) + Self::Icu(code) } pub const fn new_sys(code: u32) -> Self { - Error::Sys(code) + Self::Sys(code) } } diff --git a/src/arena/debug.rs b/src/arena/debug.rs index 4b1ae6c3cc4..48083baa059 100644 --- a/src/arena/debug.rs +++ b/src/arena/debug.rs @@ -44,7 +44,7 @@ pub enum Arena { impl Drop for Arena { fn drop(&mut self) { - if let Arena::Delegated { delegate, borrow } = self { + if let Self::Delegated { delegate, borrow } = self { let borrows = delegate.borrows.get(); assert_eq!(*borrow, borrows); delegate.borrows.set(borrows - 1); @@ -63,11 +63,11 @@ impl Arena { Self::Owned { arena: release::Arena::empty() } } - pub fn new(capacity: usize) -> apperr::Result { + pub fn new(capacity: usize) -> apperr::Result { Ok(Self::Owned { arena: release::Arena::new(capacity)? }) } - pub(super) fn delegated(delegate: &release::Arena) -> Arena { + pub(super) fn delegated(delegate: &release::Arena) -> Self { let borrow = delegate.borrows.get() + 1; delegate.borrows.set(borrow); Self::Delegated { delegate: unsafe { mem::transmute(delegate) }, borrow } @@ -76,22 +76,22 @@ impl Arena { #[inline] pub(super) fn delegate_target(&self) -> &release::Arena { match *self { - Arena::Delegated { delegate, borrow } => { + Self::Delegated { delegate, borrow } => { assert!( borrow == delegate.borrows.get(), "Arena already borrowed by a newer ScratchArena" ); delegate } - Arena::Owned { ref arena } => arena, + Self::Owned { ref arena } => arena, } } #[inline] pub(super) fn delegate_target_unchecked(&self) -> &release::Arena { match self { - Arena::Delegated { delegate, .. } => delegate, - Arena::Owned { arena } => arena, + Self::Delegated { delegate, .. } => delegate, + Self::Owned { arena } => arena, } } diff --git a/src/arena/release.rs b/src/arena/release.rs index dec572c1dc9..5f436e11af1 100644 --- a/src/arena/release.rs +++ b/src/arena/release.rs @@ -62,11 +62,11 @@ impl Arena { } } - pub fn new(capacity: usize) -> apperr::Result { + pub fn new(capacity: usize) -> apperr::Result { let capacity = (capacity.max(1) + ALLOC_CHUNK_SIZE - 1) & !(ALLOC_CHUNK_SIZE - 1); let base = unsafe { sys::virtual_reserve(capacity)? }; - Ok(Arena { + Ok(Self { base, capacity, commit: Cell::new(0), @@ -177,7 +177,7 @@ impl Drop for Arena { impl Default for Arena { fn default() -> Self { - Arena::empty() + Self::empty() } } diff --git a/src/arena/string.rs b/src/arena/string.rs index ff70ec15d49..f77fec8711a 100644 --- a/src/arena/string.rs +++ b/src/arena/string.rs @@ -50,10 +50,7 @@ impl<'a> ArenaString<'a> { /// Checks whether `text` contains only valid UTF-8. /// If the entire string is valid, it returns `Ok(text)`. /// Otherwise, it returns `Err(ArenaString)` with all invalid sequences replaced with U+FFFD. - pub fn from_utf8_lossy<'s>( - arena: &'a Arena, - text: &'s [u8], - ) -> Result<&'s str, ArenaString<'a>> { + pub fn from_utf8_lossy<'s>(arena: &'a Arena, text: &'s [u8]) -> Result<&'s str, Self> { let mut iter = text.utf8_chunks(); let Some(mut chunk) = iter.next() else { return Ok(""); diff --git a/src/bin/edit/main.rs b/src/bin/edit/main.rs index 6372c9548a0..65a4d1d5542 100644 --- a/src/bin/edit/main.rs +++ b/src/bin/edit/main.rs @@ -491,7 +491,9 @@ impl Drop for RestoreModes { fn drop(&mut self) { // Same as in the beginning but in the reverse order. // It also includes DECSCUSR 0 to reset the cursor style and DECTCEM to show the cursor. - sys::write_stdout("\x1b[0 q\x1b[?25h\x1b]0;\x07\x1b[?1036l\x1b[?1002;1006;2004l\x1b[?1049l"); + sys::write_stdout( + "\x1b[0 q\x1b[?25h\x1b]0;\x07\x1b[?1036l\x1b[?1002;1006;2004l\x1b[?1049l", + ); } } diff --git a/src/bin/edit/state.rs b/src/bin/edit/state.rs index d23be3091b1..358c94d22d7 100644 --- a/src/bin/edit/state.rs +++ b/src/bin/edit/state.rs @@ -20,7 +20,7 @@ pub struct FormatApperr(apperr::Error); impl From for FormatApperr { fn from(err: apperr::Error) -> Self { - FormatApperr(err) + Self(err) } } @@ -68,19 +68,19 @@ impl Default for DisplayablePathBuf { impl Clone for DisplayablePathBuf { fn clone(&self) -> Self { - DisplayablePathBuf::new(self.value.clone()) + Self::new(self.value.clone()) } } impl From for DisplayablePathBuf { - fn from(s: OsString) -> DisplayablePathBuf { - DisplayablePathBuf::new(PathBuf::from(s)) + fn from(s: OsString) -> Self { + Self::new(PathBuf::from(s)) } } impl> From<&T> for DisplayablePathBuf { - fn from(s: &T) -> DisplayablePathBuf { - DisplayablePathBuf::new(PathBuf::from(s)) + fn from(s: &T) -> Self { + Self::new(PathBuf::from(s)) } } diff --git a/src/buffer/gap_buffer.rs b/src/buffer/gap_buffer.rs index 58425cdafa2..5ed12f79442 100644 --- a/src/buffer/gap_buffer.rs +++ b/src/buffer/gap_buffer.rs @@ -30,7 +30,7 @@ enum BackingBuffer { impl Drop for BackingBuffer { fn drop(&mut self) { unsafe { - if let BackingBuffer::VirtualMemory(ptr, reserve) = *self { + if let Self::VirtualMemory(ptr, reserve) = *self { sys::virtual_release(ptr, reserve); } } diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index 94b471aa411..4c279b62e5a 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -213,7 +213,7 @@ impl TextBuffer { /// Creates a new text buffer inside an [`Rc`]. /// See [`TextBuffer::new()`]. pub fn new_rc(small: bool) -> apperr::Result { - let buffer = TextBuffer::new(small)?; + let buffer = Self::new(small)?; Ok(Rc::new(SemiRefCell::new(buffer))) } diff --git a/src/cell.rs b/src/cell.rs index 0e29039fada..cb60ac06548 100644 --- a/src/cell.rs +++ b/src/cell.rs @@ -49,7 +49,7 @@ mod release { impl<'b, T> Ref<'b, T> { #[inline(always)] - pub fn clone(orig: &Ref<'b, T>) -> Ref<'b, T> { + pub fn clone(orig: &Self) -> Self { Ref(orig.0) } } diff --git a/src/document.rs b/src/document.rs index 0ae9eb889ba..697bcea0346 100644 --- a/src/document.rs +++ b/src/document.rs @@ -104,6 +104,6 @@ impl WriteableDocument for PathBuf { fn replace(&mut self, range: Range, replacement: &[u8]) { let mut vec = mem::take(self).into_os_string().into_encoded_bytes(); vec.replace_range(range, replacement); - *self = unsafe { PathBuf::from(OsString::from_encoded_bytes_unchecked(vec)) }; + *self = unsafe { Self::from(OsString::from_encoded_bytes_unchecked(vec)) }; } } diff --git a/src/framebuffer.rs b/src/framebuffer.rs index 71031b312a1..586f1e76a01 100644 --- a/src/framebuffer.rs +++ b/src/framebuffer.rs @@ -793,12 +793,12 @@ pub struct Attributes(u8); #[allow(non_upper_case_globals)] impl Attributes { - pub const None: Attributes = Attributes(0); - pub const Italic: Attributes = Attributes(0b1); - pub const Underlined: Attributes = Attributes(0b10); - pub const All: Attributes = Attributes(0b11); + pub const None: Self = Self(0); + pub const Italic: Self = Self(0b1); + pub const Underlined: Self = Self(0b10); + pub const All: Self = Self(0b11); - pub const fn is(self, attr: Attributes) -> bool { + pub const fn is(self, attr: Self) -> bool { (self.0 & attr.0) == attr.0 } } @@ -806,18 +806,18 @@ impl Attributes { unsafe impl MemsetSafe for Attributes {} impl BitOr for Attributes { - type Output = Attributes; + type Output = Self; fn bitor(self, rhs: Self) -> Self::Output { - Attributes(self.0 | rhs.0) + Self(self.0 | rhs.0) } } impl BitXor for Attributes { - type Output = Attributes; + type Output = Self; fn bitxor(self, rhs: Self) -> Self::Output { - Attributes(self.0 ^ rhs.0) + Self(self.0 ^ rhs.0) } } diff --git a/src/helpers.rs b/src/helpers.rs index 1071f299a1c..43c6287c1ee 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -58,11 +58,11 @@ pub struct Point { } impl Point { - pub const MIN: Point = Point { x: CoordType::MIN, y: CoordType::MIN }; - pub const MAX: Point = Point { x: CoordType::MAX, y: CoordType::MAX }; + pub const MIN: Self = Self { x: CoordType::MIN, y: CoordType::MIN }; + pub const MAX: Self = Self { x: CoordType::MAX, y: CoordType::MAX }; } -impl PartialOrd for Point { +impl PartialOrd for Point { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } @@ -70,10 +70,7 @@ impl PartialOrd for Point { impl Ord for Point { fn cmp(&self, other: &Self) -> Ordering { - match self.y.cmp(&other.y) { - Ordering::Equal => self.x.cmp(&other.x), - ord => ord, - } + self.y.cmp(&other.y).then(self.x.cmp(&other.x)) } } @@ -149,7 +146,7 @@ impl Rect { let r = l.max(r); let b = t.max(b); - Rect { left: l, top: t, right: r, bottom: b } + Self { left: l, top: t, right: r, bottom: b } } } diff --git a/src/input.rs b/src/input.rs index 56e16761607..f744095f805 100644 --- a/src/input.rs +++ b/src/input.rs @@ -40,8 +40,8 @@ impl InputKey { self.0 } - pub(crate) const fn key(&self) -> InputKey { - InputKey(self.0 & 0x00FFFFFF) + pub(crate) const fn key(&self) -> Self { + Self(self.0 & 0x00FFFFFF) } pub(crate) const fn modifiers(&self) -> InputKeyMod { @@ -52,8 +52,8 @@ impl InputKey { (self.0 & modifier.0) != 0 } - pub(crate) const fn with_modifiers(&self, modifiers: InputKeyMod) -> InputKey { - InputKey(self.0 | modifiers.0) + pub(crate) const fn with_modifiers(&self, modifiers: InputKeyMod) -> Self { + Self(self.0 | modifiers.0) } } @@ -67,16 +67,16 @@ impl InputKeyMod { Self(v) } - pub(crate) const fn contains(&self, modifier: InputKeyMod) -> bool { + pub(crate) const fn contains(&self, modifier: Self) -> bool { (self.0 & modifier.0) != 0 } } impl std::ops::BitOr for InputKey { - type Output = InputKey; + type Output = Self; - fn bitor(self, rhs: InputKeyMod) -> InputKey { - InputKey(self.0 | rhs.0) + fn bitor(self, rhs: InputKeyMod) -> Self { + Self(self.0 | rhs.0) } } diff --git a/src/simd/memchr2.rs b/src/simd/memchr2.rs index 696f31943f5..c04cc8ea0d9 100644 --- a/src/simd/memchr2.rs +++ b/src/simd/memchr2.rs @@ -179,7 +179,7 @@ mod tests { #[test] fn test_page_boundary() { let page = unsafe { - const PAGE_SIZE: usize = 64 * 1024; // 64 KiB to cover many architectures. + const PAGE_SIZE: usize = 64 * 1024; // 64 KiB to cover many architectures. // 3 pages: uncommitted, committed, uncommitted let ptr = sys::virtual_reserve(PAGE_SIZE * 3).unwrap(); diff --git a/src/simd/memrchr2.rs b/src/simd/memrchr2.rs index 80fc11e007b..97c3c11cb11 100644 --- a/src/simd/memrchr2.rs +++ b/src/simd/memrchr2.rs @@ -177,7 +177,7 @@ mod tests { #[test] fn test_page_boundary() { let page = unsafe { - const PAGE_SIZE: usize = 64 * 1024; // 64 KiB to cover many architectures. + const PAGE_SIZE: usize = 64 * 1024; // 64 KiB to cover many architectures. // 3 pages: uncommitted, committed, uncommitted let ptr = sys::virtual_reserve(PAGE_SIZE * 3).unwrap(); diff --git a/src/sys/windows.rs b/src/sys/windows.rs index 18aa89a8121..baf10988096 100644 --- a/src/sys/windows.rs +++ b/src/sys/windows.rs @@ -406,14 +406,14 @@ pub enum FileId { impl PartialEq for FileId { fn eq(&self, other: &Self) -> bool { match (self, other) { - (FileId::Id(left), FileId::Id(right)) => { + (Self::Id(left), Self::Id(right)) => { // Lowers to an efficient word-wise comparison. const SIZE: usize = std::mem::size_of::(); let a: &[u8; SIZE] = unsafe { mem::transmute(left) }; let b: &[u8; SIZE] = unsafe { mem::transmute(right) }; a == b } - (FileId::Path(left), FileId::Path(right)) => left == right, + (Self::Path(left), Self::Path(right)) => left == right, _ => false, } } diff --git a/src/tui.rs b/src/tui.rs index 277a59b5abc..8893a29b649 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -1319,7 +1319,7 @@ impl Tui { if ptr::eq(focused_next, focused_start) { false } else { - Tui::build_node_path(Some(focused_next), &mut self.focused_node_path); + Self::build_node_path(Some(focused_next), &mut self.focused_node_path); true } }