diff --git a/stdlib/src/array.rs b/stdlib/src/array.rs index 5da3da34e..b76f165b0 100644 --- a/stdlib/src/array.rs +++ b/stdlib/src/array.rs @@ -1324,10 +1324,10 @@ mod array { } } - impl<'a> BufferResizeGuard<'a> for PyArray { - type Resizable = PyRwLockWriteGuard<'a, ArrayContentType>; + impl BufferResizeGuard for PyArray { + type Resizable<'a> = PyRwLockWriteGuard<'a, ArrayContentType>; - fn try_resizable_opt(&'a self) -> Option { + fn try_resizable_opt(&self) -> Option> { let w = self.write(); (self.exports.load(atomic::Ordering::SeqCst) == 0).then_some(w) } diff --git a/vm/src/anystr.rs b/vm/src/anystr.rs index 196671925..1f1077f5c 100644 --- a/vm/src/anystr.rs +++ b/vm/src/anystr.rs @@ -7,15 +7,14 @@ use crate::{ use num_traits::{cast::ToPrimitive, sign::Signed}; #[derive(FromArgs)] -pub struct SplitArgs<'s, T: TryFromObject + AnyStrWrapper<'s>> { +pub struct SplitArgs { #[pyarg(any, default)] sep: Option, #[pyarg(any, default = "-1")] maxsplit: isize, - _phantom: std::marker::PhantomData<&'s ()>, } -impl<'s, T: TryFromObject + AnyStrWrapper<'s>> SplitArgs<'s, T> { +impl SplitArgs { pub fn get_value(self, vm: &VirtualMachine) -> PyResult<(Option, isize)> { let sep = if let Some(s) = self.sep { let sep = s.as_ref(); @@ -69,10 +68,10 @@ impl StartsEndsWithArgs { } #[inline] - pub fn prepare<'s, S, F>(self, s: &'s S, len: usize, substr: F) -> Option<(PyObjectRef, &'s S)> + pub fn prepare(self, s: &S, len: usize, substr: F) -> Option<(PyObjectRef, &S)> where - S: ?Sized + AnyStr<'s>, - F: Fn(&'s S, std::ops::Range) -> &'s S, + S: ?Sized + AnyStr, + F: Fn(&S, std::ops::Range) -> &S, { let (affix, range) = self.get_value(len); let substr = if let Some(range) = range { @@ -133,8 +132,8 @@ impl StringRange for std::ops::Range { } } -pub trait AnyStrWrapper<'s> { - type Str: ?Sized + AnyStr<'s>; +pub trait AnyStrWrapper { + type Str: ?Sized + AnyStr; fn as_ref(&self) -> &Self::Str; } @@ -147,20 +146,23 @@ where fn push_str(&mut self, s: &S); } -// TODO: GATs for `'s` once stabilized -pub trait AnyStr<'s>: 's { +pub trait AnyStr { type Char: Copy; type Container: AnyStrContainer + Extend; - type CharIter: Iterator + 's; - type ElementIter: Iterator + 's; + type CharIter<'a>: Iterator + 'a + where + Self: 'a; + type ElementIter<'a>: Iterator + 'a + where + Self: 'a; fn element_bytes_len(c: Self::Char) -> usize; fn to_container(&self) -> Self::Container; fn as_bytes(&self) -> &[u8]; fn as_utf8_str(&self) -> Result<&str, std::str::Utf8Error>; - fn chars(&'s self) -> Self::CharIter; - fn elements(&'s self) -> Self::ElementIter; + fn chars(&self) -> Self::CharIter<'_>; + fn elements(&self) -> Self::ElementIter<'_>; fn get_bytes(&self, range: std::ops::Range) -> &Self; // FIXME: get_chars is expensive for str fn get_chars(&self, range: std::ops::Range) -> &Self; @@ -179,14 +181,14 @@ pub trait AnyStr<'s>: 's { fn py_split( &self, - args: SplitArgs<'s, T>, + args: SplitArgs, vm: &VirtualMachine, split: SP, splitn: SN, splitw: SW, ) -> PyResult> where - T: TryFromObject + AnyStrWrapper<'s, Str = Self>, + T: TryFromObject + AnyStrWrapper, SP: Fn(&Self, &Self, &VirtualMachine) -> Vec, SN: Fn(&Self, &Self, usize, &VirtualMachine) -> Vec, SW: Fn(&Self, isize, &VirtualMachine) -> Vec, @@ -247,7 +249,7 @@ pub trait AnyStr<'s>: 's { func_default: FD, ) -> &'a Self where - S: AnyStrWrapper<'s, Str = Self>, + S: AnyStrWrapper, FC: Fn(&'a Self, &Self) -> &'a Self, FD: Fn(&'a Self) -> &'a Self, { @@ -308,10 +310,10 @@ pub trait AnyStr<'s>: 's { self.py_pad(width - len, 0, fillchar) } - fn py_join<'a>( + fn py_join( &self, mut iter: impl std::iter::Iterator< - Item = PyResult + TryFromObject>, + Item = PyResult + TryFromObject>, >, ) -> PyResult { let mut joined = if let Some(elem) = iter.next() { @@ -413,7 +415,7 @@ pub trait AnyStr<'s>: 's { rustpython_common::str::zfill(self.as_bytes(), width) } - fn py_iscase(&'s self, is_case: F, is_opposite: G) -> bool + fn py_iscase(&self, is_case: F, is_opposite: G) -> bool where F: Fn(char) -> bool, G: Fn(char) -> bool, diff --git a/vm/src/builtins/bytearray.rs b/vm/src/builtins/bytearray.rs index 66341fe63..486fec9c1 100644 --- a/vm/src/builtins/bytearray.rs +++ b/vm/src/builtins/bytearray.rs @@ -782,10 +782,10 @@ impl AsBuffer for PyByteArray { } } -impl<'a> BufferResizeGuard<'a> for PyByteArray { - type Resizable = PyRwLockWriteGuard<'a, PyBytesInner>; +impl BufferResizeGuard for PyByteArray { + type Resizable<'a> = PyRwLockWriteGuard<'a, PyBytesInner>; - fn try_resizable_opt(&'a self) -> Option { + fn try_resizable_opt(&self) -> Option> { let w = self.inner.write(); (self.exports.load(Ordering::SeqCst) == 0).then_some(w) } diff --git a/vm/src/builtins/list.rs b/vm/src/builtins/list.rs index f2944942e..2374e7746 100644 --- a/vm/src/builtins/list.rs +++ b/vm/src/builtins/list.rs @@ -365,14 +365,14 @@ where } } -impl<'a> MutObjectSequenceOp<'a> for PyList { - type Guard = PyMappedRwLockReadGuard<'a, [PyObjectRef]>; +impl MutObjectSequenceOp for PyList { + type Guard<'a> = PyMappedRwLockReadGuard<'a, [PyObjectRef]>; - fn do_get(index: usize, guard: &Self::Guard) -> Option<&PyObjectRef> { + fn do_get<'a>(index: usize, guard: &'a Self::Guard<'_>) -> Option<&'a PyObjectRef> { guard.get(index) } - fn do_lock(&'a self) -> Self::Guard { + fn do_lock(&self) -> Self::Guard<'_> { self.borrow_vec() } } diff --git a/vm/src/builtins/str.rs b/vm/src/builtins/str.rs index 87cc7fa1d..b9f125894 100644 --- a/vm/src/builtins/str.rs +++ b/vm/src/builtins/str.rs @@ -1369,7 +1369,7 @@ impl ToPyObject for AsciiString { } } -type SplitArgs<'a> = anystr::SplitArgs<'a, PyStrRef>; +type SplitArgs = anystr::SplitArgs; #[derive(FromArgs)] pub struct FindArgs { @@ -1582,7 +1582,7 @@ mod tests { } } -impl<'s> AnyStrWrapper<'s> for PyStrRef { +impl AnyStrWrapper for PyStrRef { type Str = str; fn as_ref(&self) -> &str { self.as_str() @@ -1603,11 +1603,11 @@ impl AnyStrContainer for String { } } -impl<'s> AnyStr<'s> for str { +impl AnyStr for str { type Char = char; type Container = String; - type CharIter = std::str::Chars<'s>; - type ElementIter = std::str::Chars<'s>; + type CharIter<'a> = std::str::Chars<'a>; + type ElementIter<'a> = std::str::Chars<'a>; fn element_bytes_len(c: char) -> usize { c.len_utf8() @@ -1625,11 +1625,11 @@ impl<'s> AnyStr<'s> for str { Ok(self) } - fn chars(&'s self) -> Self::CharIter { + fn chars(&self) -> Self::CharIter<'_> { str::chars(self) } - fn elements(&'s self) -> Self::ElementIter { + fn elements(&self) -> Self::ElementIter<'_> { str::chars(self) } diff --git a/vm/src/bytesinner.rs b/vm/src/bytesinner.rs index 6ce5c1a2f..07ff56a47 100644 --- a/vm/src/bytesinner.rs +++ b/vm/src/bytesinner.rs @@ -239,7 +239,7 @@ impl ByteInnerTranslateOptions { } } -pub type ByteInnerSplitOptions<'a> = anystr::SplitArgs<'a, PyBytesInner>; +pub type ByteInnerSplitOptions = anystr::SplitArgs; impl PyBytesInner { #[inline] @@ -971,7 +971,7 @@ pub trait ByteOr: ToPrimitive { impl ByteOr for BigInt {} -impl<'s> AnyStrWrapper<'s> for PyBytesInner { +impl AnyStrWrapper for PyBytesInner { type Str = [u8]; fn as_ref(&self) -> &[u8] { &self.elements @@ -994,11 +994,11 @@ impl AnyStrContainer<[u8]> for Vec { const ASCII_WHITESPACES: [u8; 6] = [0x20, 0x09, 0x0a, 0x0c, 0x0d, 0x0b]; -impl<'s> AnyStr<'s> for [u8] { +impl AnyStr for [u8] { type Char = u8; type Container = Vec; - type CharIter = bstr::Chars<'s>; - type ElementIter = std::iter::Copied>; + type CharIter<'a> = bstr::Chars<'a>; + type ElementIter<'a> = std::iter::Copied>; fn element_bytes_len(_: u8) -> usize { 1 @@ -1016,11 +1016,11 @@ impl<'s> AnyStr<'s> for [u8] { std::str::from_utf8(self) } - fn chars(&'s self) -> Self::CharIter { + fn chars(&self) -> Self::CharIter<'_> { bstr::ByteSlice::chars(self) } - fn elements(&'s self) -> Self::ElementIter { + fn elements(&self) -> Self::ElementIter<'_> { self.iter().copied() } diff --git a/vm/src/protocol/buffer.rs b/vm/src/protocol/buffer.rs index 14273b713..9ba0c0160 100644 --- a/vm/src/protocol/buffer.rs +++ b/vm/src/protocol/buffer.rs @@ -384,10 +384,12 @@ impl BufferDescriptor { // TODO: support fortain order } -pub trait BufferResizeGuard<'a> { - type Resizable: 'a; - fn try_resizable_opt(&'a self) -> Option; - fn try_resizable(&'a self, vm: &VirtualMachine) -> PyResult { +pub trait BufferResizeGuard { + type Resizable<'a>: 'a + where + Self: 'a; + fn try_resizable_opt(&self) -> Option>; + fn try_resizable(&self, vm: &VirtualMachine) -> PyResult> { self.try_resizable_opt().ok_or_else(|| { vm.new_buffer_error("Existing exports of data: object cannot be re-sized".to_owned()) }) diff --git a/vm/src/sequence.rs b/vm/src/sequence.rs index 2ed07b62c..614e72d52 100644 --- a/vm/src/sequence.rs +++ b/vm/src/sequence.rs @@ -5,13 +5,13 @@ use crate::{ use optional::Optioned; use std::ops::Range; -pub trait MutObjectSequenceOp<'a> { - type Guard; +pub trait MutObjectSequenceOp { + type Guard<'a>: 'a; - fn do_get(index: usize, guard: &Self::Guard) -> Option<&PyObjectRef>; - fn do_lock(&'a self) -> Self::Guard; + fn do_get<'a>(index: usize, guard: &'a Self::Guard<'_>) -> Option<&'a PyObjectRef>; + fn do_lock(&self) -> Self::Guard<'_>; - fn mut_count(&'a self, vm: &VirtualMachine, needle: &PyObject) -> PyResult { + fn mut_count(&self, vm: &VirtualMachine, needle: &PyObject) -> PyResult { let mut count = 0; self._mut_iter_equal_skeleton::<_, false>(vm, needle, 0..isize::MAX as usize, || { count += 1 @@ -20,7 +20,7 @@ pub trait MutObjectSequenceOp<'a> { } fn mut_index_range( - &'a self, + &self, vm: &VirtualMachine, needle: &PyObject, range: Range, @@ -28,16 +28,16 @@ pub trait MutObjectSequenceOp<'a> { self._mut_iter_equal_skeleton::<_, true>(vm, needle, range, || {}) } - fn mut_index(&'a self, vm: &VirtualMachine, needle: &PyObject) -> PyResult> { + fn mut_index(&self, vm: &VirtualMachine, needle: &PyObject) -> PyResult> { self.mut_index_range(vm, needle, 0..isize::MAX as usize) } - fn mut_contains(&'a self, vm: &VirtualMachine, needle: &PyObject) -> PyResult { + fn mut_contains(&self, vm: &VirtualMachine, needle: &PyObject) -> PyResult { self.mut_index(vm, needle).map(|x| x.is_some()) } fn _mut_iter_equal_skeleton( - &'a self, + &self, vm: &VirtualMachine, needle: &PyObject, range: Range, diff --git a/vm/src/stdlib/collections.rs b/vm/src/stdlib/collections.rs index a3cbdab99..403b2ee7a 100644 --- a/vm/src/stdlib/collections.rs +++ b/vm/src/stdlib/collections.rs @@ -429,14 +429,14 @@ mod _collections { } } - impl<'a> MutObjectSequenceOp<'a> for PyDeque { - type Guard = PyRwLockReadGuard<'a, VecDeque>; + impl MutObjectSequenceOp for PyDeque { + type Guard<'a> = PyRwLockReadGuard<'a, VecDeque>; - fn do_get(index: usize, guard: &Self::Guard) -> Option<&PyObjectRef> { + fn do_get<'a>(index: usize, guard: &'a Self::Guard<'_>) -> Option<&'a PyObjectRef> { guard.get(index) } - fn do_lock(&'a self) -> Self::Guard { + fn do_lock(&self) -> Self::Guard<'_> { self.borrow_deque() } } diff --git a/vm/src/stdlib/io.rs b/vm/src/stdlib/io.rs index c7e5b4f3e..5d9645778 100644 --- a/vm/src/stdlib/io.rs +++ b/vm/src/stdlib/io.rs @@ -3389,10 +3389,10 @@ mod _io { }, }; - impl<'a> BufferResizeGuard<'a> for BytesIO { - type Resizable = PyRwLockWriteGuard<'a, BufferedIO>; + impl BufferResizeGuard for BytesIO { + type Resizable<'a> = PyRwLockWriteGuard<'a, BufferedIO>; - fn try_resizable_opt(&'a self) -> Option { + fn try_resizable_opt(&self) -> Option> { let w = self.buffer.write(); (self.exports.load() == 0).then_some(w) }