diff --git a/Cargo.toml b/Cargo.toml index 33fb96e84..807e821ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -189,6 +189,7 @@ wasm-bindgen = "0.2.100" [workspace.lints.rust] unsafe_code = "allow" unsafe_op_in_unsafe_fn = "deny" +elided_lifetimes_in_paths = "warn" [workspace.lints.clippy] perf = "warn" diff --git a/common/src/borrow.rs b/common/src/borrow.rs index 0e4b9d6be..ce86d71e2 100644 --- a/common/src/borrow.rs +++ b/common/src/borrow.rs @@ -68,7 +68,7 @@ impl Deref for BorrowedValue<'_, T> { } impl fmt::Display for BorrowedValue<'_, str> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self.deref(), f) } } diff --git a/common/src/boxvec.rs b/common/src/boxvec.rs index 3b1f7e90a..25afbcebb 100644 --- a/common/src/boxvec.rs +++ b/common/src/boxvec.rs @@ -262,7 +262,7 @@ impl BoxVec { /// /// **Panics** if the starting point is greater than the end point or if /// the end point is greater than the length of the vector. - pub fn drain(&mut self, range: R) -> Drain + pub fn drain(&mut self, range: R) -> Drain<'_, T> where R: RangeBounds, { @@ -290,7 +290,7 @@ impl BoxVec { self.drain_range(start, end) } - fn drain_range(&mut self, start: usize, end: usize) -> Drain { + fn drain_range(&mut self, start: usize, end: usize) -> Drain<'_, T> { let len = self.len(); // bounds check happens here (before length is changed!) @@ -438,7 +438,7 @@ impl fmt::Debug for IntoIter where T: fmt::Debug, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_list().entries(&self.v[self.index..]).finish() } } @@ -658,7 +658,7 @@ impl fmt::Debug for BoxVec where T: fmt::Debug, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { (**self).fmt(f) } } @@ -691,13 +691,13 @@ const CAPERROR: &str = "insufficient capacity"; impl std::error::Error for CapacityError {} impl fmt::Display for CapacityError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{CAPERROR}") } } impl fmt::Debug for CapacityError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "capacity error: {CAPERROR}") } } diff --git a/common/src/lock/thread_mutex.rs b/common/src/lock/thread_mutex.rs index 35b0b9ac6..d730818d8 100644 --- a/common/src/lock/thread_mutex.rs +++ b/common/src/lock/thread_mutex.rs @@ -100,7 +100,7 @@ impl From for ThreadMutex { } } impl ThreadMutex { - pub fn lock(&self) -> Option> { + pub fn lock(&self) -> Option> { if self.raw.lock() { Some(ThreadMutexGuard { mu: self, @@ -110,7 +110,7 @@ impl ThreadMutex { None } } - pub fn try_lock(&self) -> Result, TryLockThreadError> { + pub fn try_lock(&self) -> Result, TryLockThreadError> { match self.raw.try_lock() { Some(true) => Ok(ThreadMutexGuard { mu: self, @@ -218,14 +218,14 @@ impl Drop for ThreadMutexGuard<'_, R, G, impl fmt::Display for ThreadMutexGuard<'_, R, G, T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&**self, f) } } impl fmt::Debug for ThreadMutexGuard<'_, R, G, T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&**self, f) } } @@ -285,14 +285,14 @@ impl Drop for MappedThreadMutexGuard<'_, impl fmt::Display for MappedThreadMutexGuard<'_, R, G, T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&**self, f) } } impl fmt::Debug for MappedThreadMutexGuard<'_, R, G, T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&**self, f) } } diff --git a/compiler/codegen/src/compile.rs b/compiler/codegen/src/compile.rs index 6b1d15c72..ce2e5627f 100644 --- a/compiler/codegen/src/compile.rs +++ b/compiler/codegen/src/compile.rs @@ -3484,7 +3484,7 @@ mod tests { use rustpython_parser_core::source_code::LinearLocator; fn compile_exec(source: &str) -> CodeObject { - let mut locator: LinearLocator = LinearLocator::new(source); + let mut locator: LinearLocator<'_> = LinearLocator::new(source); use rustpython_parser::ast::fold::Fold; let mut compiler: Compiler = Compiler::new( CompileOpts::default(), diff --git a/compiler/codegen/src/error.rs b/compiler/codegen/src/error.rs index 27333992d..581f22971 100644 --- a/compiler/codegen/src/error.rs +++ b/compiler/codegen/src/error.rs @@ -38,7 +38,7 @@ pub enum CodegenErrorType { impl std::error::Error for CodegenErrorType {} impl fmt::Display for CodegenErrorType { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { use CodegenErrorType::*; match self { Assign(target) => write!(f, "cannot assign to {target}"), diff --git a/compiler/codegen/src/symboltable.rs b/compiler/codegen/src/symboltable.rs index 7db5c4edb..53d4ff8eb 100644 --- a/compiler/codegen/src/symboltable.rs +++ b/compiler/codegen/src/symboltable.rs @@ -74,7 +74,7 @@ pub enum SymbolTableType { } impl fmt::Display for SymbolTableType { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { SymbolTableType::Module => write!(f, "module"), SymbolTableType::Class => write!(f, "class"), @@ -195,7 +195,7 @@ impl SymbolTable { } impl std::fmt::Debug for SymbolTable { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, "SymbolTable({:?} symbols, {:?} sub scopes)", diff --git a/compiler/core/src/bytecode.rs b/compiler/core/src/bytecode.rs index 11e49a47d..66284efdc 100644 --- a/compiler/core/src/bytecode.rs +++ b/compiler/core/src/bytecode.rs @@ -15,12 +15,12 @@ pub trait Constant: Sized { type Name: AsRef; /// Transforms the given Constant to a BorrowedConstant - fn borrow_constant(&self) -> BorrowedConstant; + fn borrow_constant(&self) -> BorrowedConstant<'_, Self>; } impl Constant for ConstantData { type Name = String; - fn borrow_constant(&self) -> BorrowedConstant { + fn borrow_constant(&self) -> BorrowedConstant<'_, Self> { use BorrowedConstant::*; match self { ConstantData::Integer { value } => Integer { value }, @@ -40,7 +40,7 @@ impl Constant for ConstantData { /// A Constant Bag pub trait ConstantBag: Sized + Copy { type Constant: Constant; - fn make_constant(&self, constant: BorrowedConstant) -> Self::Constant; + fn make_constant(&self, constant: BorrowedConstant<'_, C>) -> Self::Constant; fn make_int(&self, value: BigInt) -> Self::Constant; fn make_tuple(&self, elements: impl Iterator) -> Self::Constant; fn make_code(&self, code: CodeObject) -> Self::Constant; @@ -65,7 +65,7 @@ pub struct BasicBag; impl ConstantBag for BasicBag { type Constant = ConstantData; - fn make_constant(&self, constant: BorrowedConstant) -> Self::Constant { + fn make_constant(&self, constant: BorrowedConstant<'_, C>) -> Self::Constant { constant.to_owned() } fn make_int(&self, value: BigInt) -> Self::Constant { @@ -306,7 +306,7 @@ impl PartialEq for Arg { impl Eq for Arg {} impl fmt::Debug for Arg { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Arg<{}>", std::any::type_name::()) } } @@ -329,7 +329,7 @@ impl OpArgType for Label { } impl fmt::Display for Label { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.fmt(f) } } @@ -752,7 +752,7 @@ impl Clone for BorrowedConstant<'_, C> { } impl BorrowedConstant<'_, C> { - pub fn fmt_display(&self, f: &mut fmt::Formatter) -> fmt::Result { + pub fn fmt_display(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { BorrowedConstant::Integer { value } => write!(f, "{value}"), BorrowedConstant::Float { value } => write!(f, "{value}"), @@ -939,7 +939,7 @@ impl> fmt::Debug for Arguments<'_, N> { impl CodeObject { /// Get all arguments of the code object /// like inspect.getargs - pub fn arg_names(&self) -> Arguments { + pub fn arg_names(&self) -> Arguments<'_, C::Name> { let nargs = self.arg_count as usize; let nkwargs = self.kwonlyarg_count as usize; let mut varargs_pos = nargs + nkwargs; @@ -984,7 +984,7 @@ impl CodeObject { fn display_inner( &self, - f: &mut fmt::Formatter, + f: &mut fmt::Formatter<'_>, expand_code_objects: bool, level: usize, ) -> fmt::Result { @@ -1034,7 +1034,7 @@ impl CodeObject { pub fn display_expand_code_objects(&self) -> impl fmt::Display + '_ { struct Display<'a, C: Constant>(&'a CodeObject); impl fmt::Display for Display<'_, C> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.0.display_inner(f, true, 1) } } @@ -1107,7 +1107,7 @@ impl CodeObject { } impl fmt::Display for CodeObject { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.display_inner(f, false, 1)?; for constant in &*self.constants { if let BorrowedConstant::Code { code } = constant.borrow_constant() { @@ -1302,19 +1302,19 @@ impl Instruction { ctx: &'a impl InstrDisplayContext, ) -> impl fmt::Display + 'a { struct FmtFn(F); - impl fmt::Result> fmt::Display for FmtFn { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + impl) -> fmt::Result> fmt::Display for FmtFn { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { (self.0)(f) } } - FmtFn(move |f: &mut fmt::Formatter| self.fmt_dis(arg, f, ctx, false, 0, 0)) + FmtFn(move |f: &mut fmt::Formatter<'_>| self.fmt_dis(arg, f, ctx, false, 0, 0)) } #[allow(clippy::too_many_arguments)] fn fmt_dis( &self, arg: OpArg, - f: &mut fmt::Formatter, + f: &mut fmt::Formatter<'_>, ctx: &impl InstrDisplayContext, expand_code_objects: bool, pad: usize, @@ -1346,7 +1346,7 @@ impl Instruction { let cell_name = |i: u32| ctx.get_cell_name(i as usize); let fmt_const = - |op: &str, arg: OpArg, f: &mut fmt::Formatter, idx: &Arg| -> fmt::Result { + |op: &str, arg: OpArg, f: &mut fmt::Formatter<'_>, idx: &Arg| -> fmt::Result { let value = ctx.get_constant(idx.get(arg) as usize); match value.borrow_constant() { BorrowedConstant::Code { code } if expand_code_objects => { @@ -1496,13 +1496,13 @@ impl InstrDisplayContext for CodeObject { } impl fmt::Display for ConstantData { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.borrow_constant().fmt_display(f) } } impl fmt::Debug for CodeObject { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, "", diff --git a/compiler/core/src/marshal.rs b/compiler/core/src/marshal.rs index 9f3bb8e22..cdc8b8e4e 100644 --- a/compiler/core/src/marshal.rs +++ b/compiler/core/src/marshal.rs @@ -21,7 +21,7 @@ pub enum MarshalError { } impl std::fmt::Display for MarshalError { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Eof => f.write_str("unexpected end of data"), Self::InvalidBytecode => f.write_str("invalid bytecode"), diff --git a/compiler/src/lib.rs b/compiler/src/lib.rs index 7d226cd1c..659dc9974 100644 --- a/compiler/src/lib.rs +++ b/compiler/src/lib.rs @@ -25,7 +25,7 @@ impl std::error::Error for CompileErrorType { } } impl std::fmt::Display for CompileErrorType { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { CompileErrorType::Codegen(e) => e.fmt(f), CompileErrorType::Parse(e) => e.fmt(f), diff --git a/derive-impl/src/compile_bytecode.rs b/derive-impl/src/compile_bytecode.rs index 2a5713419..2c702b35f 100644 --- a/derive-impl/src/compile_bytecode.rs +++ b/derive-impl/src/compile_bytecode.rs @@ -316,7 +316,7 @@ impl PyCompileArgs { } } -fn parse_str(input: ParseStream) -> ParseResult { +fn parse_str(input: ParseStream<'_>) -> ParseResult { let span = input.span(); if input.peek(LitStr) { input.parse() diff --git a/derive-impl/src/pyclass.rs b/derive-impl/src/pyclass.rs index 077bd36bb..b704e083c 100644 --- a/derive-impl/src/pyclass.rs +++ b/derive-impl/src/pyclass.rs @@ -25,7 +25,7 @@ enum AttrName { } impl std::fmt::Display for AttrName { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let s = match self { Self::Method => "pymethod", Self::ClassMethod => "pyclassmethod", diff --git a/derive-impl/src/pymodule.rs b/derive-impl/src/pymodule.rs index c59e40678..eb1e4bba9 100644 --- a/derive-impl/src/pymodule.rs +++ b/derive-impl/src/pymodule.rs @@ -19,7 +19,7 @@ enum AttrName { } impl std::fmt::Display for AttrName { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let s = match self { Self::Function => "pyfunction", Self::Attr => "pyattr", diff --git a/jit/src/instructions.rs b/jit/src/instructions.rs index 2d5e990dd..b495c6e1f 100644 --- a/jit/src/instructions.rs +++ b/jit/src/instructions.rs @@ -188,7 +188,7 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> { fn prepare_const( &mut self, - constant: BorrowedConstant, + constant: BorrowedConstant<'_, C>, ) -> Result { let value = match constant { BorrowedConstant::Integer { value } => { diff --git a/stdlib/src/contextvars.rs b/stdlib/src/contextvars.rs index 1e27b8b9e..bcc372ed5 100644 --- a/stdlib/src/contextvars.rs +++ b/stdlib/src/contextvars.rs @@ -301,7 +301,7 @@ mod _contextvars { } impl std::fmt::Debug for ContextVar { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("ContextVar").finish() } } diff --git a/stdlib/src/csv.rs b/stdlib/src/csv.rs index 03a5429ba..f07b40b3a 100644 --- a/stdlib/src/csv.rs +++ b/stdlib/src/csv.rs @@ -910,7 +910,7 @@ mod _csv { } impl fmt::Debug for Reader { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "_csv.reader") } } @@ -1064,7 +1064,7 @@ mod _csv { } impl fmt::Debug for Writer { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "_csv.writer") } } diff --git a/stdlib/src/hashlib.rs b/stdlib/src/hashlib.rs index 6124b6d24..f140515c1 100644 --- a/stdlib/src/hashlib.rs +++ b/stdlib/src/hashlib.rs @@ -91,7 +91,7 @@ pub mod _hashlib { } impl std::fmt::Debug for PyHasher { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "HASH {}", self.name) } } @@ -155,7 +155,7 @@ pub mod _hashlib { } impl std::fmt::Debug for PyHasherXof { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "HASHXOF {}", self.name) } } diff --git a/stdlib/src/mmap.rs b/stdlib/src/mmap.rs index e96339c37..cbc86bb2c 100644 --- a/stdlib/src/mmap.rs +++ b/stdlib/src/mmap.rs @@ -483,7 +483,7 @@ mod mmap { flags(BASETYPE) )] impl PyMmap { - fn as_bytes_mut(&self) -> BorrowedValueMut<[u8]> { + fn as_bytes_mut(&self) -> BorrowedValueMut<'_, [u8]> { PyMutexGuard::map(self.mmap.lock(), |m| { match m.as_mut().expect("mmap closed or invalid") { MmapObj::Read(_) => panic!("mmap can't modify a readonly memory map."), @@ -493,7 +493,7 @@ mod mmap { .into() } - fn as_bytes(&self) -> BorrowedValue<[u8]> { + fn as_bytes(&self) -> BorrowedValue<'_, [u8]> { PyMutexGuard::map_immutable(self.mmap.lock(), |m| { match m.as_ref().expect("mmap closed or invalid") { MmapObj::Read(mmap) => &mmap[..], @@ -536,7 +536,7 @@ mod mmap { } } - fn check_valid(&self, vm: &VirtualMachine) -> PyResult>> { + fn check_valid(&self, vm: &VirtualMachine) -> PyResult>> { let m = self.mmap.lock(); if m.is_none() { diff --git a/stdlib/src/overlapped.rs b/stdlib/src/overlapped.rs index 45eac5f51..f40494a43 100644 --- a/stdlib/src/overlapped.rs +++ b/stdlib/src/overlapped.rs @@ -52,7 +52,7 @@ mod _overlapped { unsafe impl Send for OverlappedInner {} impl std::fmt::Debug for Overlapped { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let zelf = self.inner.lock(); f.debug_struct("Overlapped") // .field("overlapped", &(self.overlapped as *const _ as usize)) @@ -93,7 +93,7 @@ mod _overlapped { } impl std::fmt::Debug for OverlappedReadFrom { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("OverlappedReadFrom") .field("result", &self.result) .field("allocated_buffer", &self.allocated_buffer) @@ -114,7 +114,7 @@ mod _overlapped { } impl std::fmt::Debug for OverlappedReadFromInto { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("OverlappedReadFromInto") .field("result", &self.result) .field("user_buffer", &self.user_buffer) diff --git a/stdlib/src/posixsubprocess.rs b/stdlib/src/posixsubprocess.rs index cff00a70a..595caf524 100644 --- a/stdlib/src/posixsubprocess.rs +++ b/stdlib/src/posixsubprocess.rs @@ -152,7 +152,7 @@ struct ProcArgs<'a> { extra_groups: Option<&'a [Gid]>, } -fn exec(args: &ForkExecArgs, procargs: ProcArgs) -> ! { +fn exec(args: &ForkExecArgs, procargs: ProcArgs<'_>) -> ! { let mut ctx = ExecErrorContext::NoExec; match exec_inner(args, procargs, &mut ctx) { Ok(x) => match x {}, @@ -183,7 +183,7 @@ impl ExecErrorContext { fn exec_inner( args: &ForkExecArgs, - procargs: ProcArgs, + procargs: ProcArgs<'_>, ctx: &mut ExecErrorContext, ) -> nix::Result { for &fd in args.fds_to_keep.as_slice() { diff --git a/stdlib/src/scproxy.rs b/stdlib/src/scproxy.rs index 9bf29626a..c63acf534 100644 --- a/stdlib/src/scproxy.rs +++ b/stdlib/src/scproxy.rs @@ -56,10 +56,7 @@ mod _scproxy { .map(|s| { unsafe { CFType::from_void(*s) } .downcast::() - .map(|s| { - let a_string: std::borrow::Cow = (&s).into(); - PyStr::from(a_string.into_owned()) - }) + .map(|s| PyStr::from(s.to_string())) .to_pyobject(vm) }) .collect(); diff --git a/stdlib/src/socket.rs b/stdlib/src/socket.rs index a38b4f123..533a0a0b2 100644 --- a/stdlib/src/socket.rs +++ b/stdlib/src/socket.rs @@ -1920,7 +1920,7 @@ mod _socket { }; let host = opts.host.as_ref().map(|s| s.as_str()); - let port = opts.port.as_ref().map(|p| -> std::borrow::Cow { + let port = opts.port.as_ref().map(|p| -> std::borrow::Cow<'_, str> { match p { Either::A(s) => s.as_str().into(), Either::B(i) => i.to_string().into(), diff --git a/stdlib/src/sqlite.rs b/stdlib/src/sqlite.rs index 5487511e2..85ce8d80f 100644 --- a/stdlib/src/sqlite.rs +++ b/stdlib/src/sqlite.rs @@ -316,7 +316,7 @@ mod _sqlite { } unsafe impl Traverse for ConnectArgs { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.isolation_level.traverse(tracer_fn); self.factory.traverse(tracer_fn); } @@ -337,7 +337,7 @@ mod _sqlite { } unsafe impl Traverse for BackupArgs { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.progress.traverse(tracer_fn); self.name.traverse(tracer_fn); } @@ -867,12 +867,12 @@ mod _sqlite { }) } - fn db_lock(&self, vm: &VirtualMachine) -> PyResult> { + fn db_lock(&self, vm: &VirtualMachine) -> PyResult> { self.check_thread(vm)?; self._db_lock(vm) } - fn _db_lock(&self, vm: &VirtualMachine) -> PyResult> { + fn _db_lock(&self, vm: &VirtualMachine) -> PyResult> { let guard = self.db.lock(); if guard.is_some() { Ok(PyMutexGuard::map(guard, |x| unsafe { @@ -1437,7 +1437,7 @@ mod _sqlite { } } - fn inner(&self, vm: &VirtualMachine) -> PyResult> { + fn inner(&self, vm: &VirtualMachine) -> PyResult> { let guard = self.inner.lock(); if guard.is_some() { Ok(PyMutexGuard::map(guard, |x| unsafe { @@ -2103,7 +2103,7 @@ mod _sqlite { self.close() } - fn inner(&self, vm: &VirtualMachine) -> PyResult> { + fn inner(&self, vm: &VirtualMachine) -> PyResult> { let guard = self.inner.lock(); if guard.is_some() { Ok(PyMutexGuard::map(guard, |x| unsafe { @@ -2314,7 +2314,7 @@ mod _sqlite { })) } - fn lock(&self) -> PyMutexGuard { + fn lock(&self) -> PyMutexGuard<'_, SqliteStatement> { self.st.lock() } } @@ -2675,7 +2675,11 @@ mod _sqlite { Ok(()) } - fn bind_parameters_sequence(self, seq: PySequence, vm: &VirtualMachine) -> PyResult<()> { + fn bind_parameters_sequence( + self, + seq: PySequence<'_>, + vm: &VirtualMachine, + ) -> PyResult<()> { let num_needed = unsafe { sqlite3_bind_parameter_count(self.st) }; if seq.length(vm)? != num_needed as usize { return Err(new_programming_error( diff --git a/vm/src/builtins/code.rs b/vm/src/builtins/code.rs index d9d8895b1..3fa332b2f 100644 --- a/vm/src/builtins/code.rs +++ b/vm/src/builtins/code.rs @@ -58,7 +58,7 @@ impl From for PyObjectRef { } } -fn borrow_obj_constant(obj: &PyObject) -> BorrowedConstant { +fn borrow_obj_constant(obj: &PyObject) -> BorrowedConstant<'_, Literal> { match_class!(match obj { ref i @ super::int::PyInt => { let value = i.as_bigint(); @@ -96,7 +96,7 @@ fn borrow_obj_constant(obj: &PyObject) -> BorrowedConstant { impl Constant for Literal { type Name = &'static PyStrInterned; - fn borrow_constant(&self) -> BorrowedConstant { + fn borrow_constant(&self) -> BorrowedConstant<'_, Self> { borrow_obj_constant(&self.0) } } @@ -120,7 +120,7 @@ pub struct PyObjBag<'a>(pub &'a Context); impl ConstantBag for PyObjBag<'_> { type Constant = Literal; - fn make_constant(&self, constant: BorrowedConstant) -> Self::Constant { + fn make_constant(&self, constant: BorrowedConstant<'_, C>) -> Self::Constant { let ctx = self.0; let obj = match constant { bytecode::BorrowedConstant::Integer { value } => ctx.new_bigint(value).into(), @@ -208,7 +208,7 @@ impl PyCode { } impl fmt::Debug for PyCode { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "code: {:?}", self.code) } } diff --git a/vm/src/builtins/dict.rs b/vm/src/builtins/dict.rs index e54d2a193..c8da40dc0 100644 --- a/vm/src/builtins/dict.rs +++ b/vm/src/builtins/dict.rs @@ -37,7 +37,7 @@ pub struct PyDict { pub type PyDictRef = PyRef; impl fmt::Debug for PyDict { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // TODO: implement more detailed, non-recursive Debug formatter f.write_str("dict") } diff --git a/vm/src/builtins/function.rs b/vm/src/builtins/function.rs index 63cf8ac5c..f7b5d3999 100644 --- a/vm/src/builtins/function.rs +++ b/vm/src/builtins/function.rs @@ -44,7 +44,7 @@ pub struct PyFunction { } unsafe impl Traverse for PyFunction { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.globals.traverse(tracer_fn); self.closure.traverse(tracer_fn); self.defaults_and_kwdefaults.traverse(tracer_fn); diff --git a/vm/src/builtins/genericalias.rs b/vm/src/builtins/genericalias.rs index 57c97ba62..c03e3145b 100644 --- a/vm/src/builtins/genericalias.rs +++ b/vm/src/builtins/genericalias.rs @@ -36,7 +36,7 @@ pub struct PyGenericAlias { } impl fmt::Debug for PyGenericAlias { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("GenericAlias") } } diff --git a/vm/src/builtins/iter.rs b/vm/src/builtins/iter.rs index 5a47abfac..0bd199480 100644 --- a/vm/src/builtins/iter.rs +++ b/vm/src/builtins/iter.rs @@ -26,7 +26,7 @@ pub enum IterStatus { } unsafe impl Traverse for IterStatus { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { match self { IterStatus::Active(r) => r.traverse(tracer_fn), IterStatus::Exhausted => (), @@ -41,7 +41,7 @@ pub struct PositionIterInternal { } unsafe impl Traverse for PositionIterInternal { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.status.traverse(tracer_fn) } } diff --git a/vm/src/builtins/list.rs b/vm/src/builtins/list.rs index 3b9624694..1d8b4a30e 100644 --- a/vm/src/builtins/list.rs +++ b/vm/src/builtins/list.rs @@ -29,7 +29,7 @@ pub struct PyList { } impl fmt::Debug for PyList { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // TODO: implement more detailed, non-recursive Debug formatter f.write_str("list") } diff --git a/vm/src/builtins/mappingproxy.rs b/vm/src/builtins/mappingproxy.rs index 659562cec..385d18df0 100644 --- a/vm/src/builtins/mappingproxy.rs +++ b/vm/src/builtins/mappingproxy.rs @@ -27,7 +27,7 @@ enum MappingProxyInner { } unsafe impl Traverse for MappingProxyInner { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { match self { MappingProxyInner::Class(r) => r.traverse(tracer_fn), MappingProxyInner::Mapping(arg) => arg.traverse(tracer_fn), diff --git a/vm/src/builtins/memory.rs b/vm/src/builtins/memory.rs index 9426730f4..e411d312d 100644 --- a/vm/src/builtins/memory.rs +++ b/vm/src/builtins/memory.rs @@ -386,7 +386,7 @@ impl PyMemoryView { ret } - fn obj_bytes(&self) -> BorrowedValue<[u8]> { + fn obj_bytes(&self) -> BorrowedValue<'_, [u8]> { if self.desc.is_contiguous() { BorrowedValue::map(self.buffer.obj_bytes(), |x| { &x[self.start..self.start + self.desc.len] @@ -396,7 +396,7 @@ impl PyMemoryView { } } - fn obj_bytes_mut(&self) -> BorrowedValueMut<[u8]> { + fn obj_bytes_mut(&self) -> BorrowedValueMut<'_, [u8]> { if self.desc.is_contiguous() { BorrowedValueMut::map(self.buffer.obj_bytes_mut(), |x| { &mut x[self.start..self.start + self.desc.len] @@ -406,7 +406,7 @@ impl PyMemoryView { } } - fn as_contiguous(&self) -> Option> { + fn as_contiguous(&self) -> Option> { self.desc.is_contiguous().then(|| { BorrowedValue::map(self.buffer.obj_bytes(), |x| { &x[self.start..self.start + self.desc.len] @@ -414,7 +414,7 @@ impl PyMemoryView { }) } - fn _as_contiguous_mut(&self) -> Option> { + fn _as_contiguous_mut(&self) -> Option> { self.desc.is_contiguous().then(|| { BorrowedValueMut::map(self.buffer.obj_bytes_mut(), |x| { &mut x[self.start..self.start + self.desc.len] diff --git a/vm/src/builtins/set.rs b/vm/src/builtins/set.rs index 62a66c89b..a135af1bd 100644 --- a/vm/src/builtins/set.rs +++ b/vm/src/builtins/set.rs @@ -138,14 +138,14 @@ impl PyFrozenSet { } impl fmt::Debug for PySet { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // TODO: implement more detailed, non-recursive Debug formatter f.write_str("set") } } impl fmt::Debug for PyFrozenSet { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // TODO: implement more detailed, non-recursive Debug formatter f.write_str("PyFrozenSet ")?; f.debug_set().entries(self.elements().iter()).finish() @@ -170,7 +170,7 @@ pub(super) struct PySetInner { } unsafe impl crate::object::Traverse for PySetInner { - fn traverse(&self, tracer_fn: &mut crate::object::TraverseFn) { + fn traverse(&self, tracer_fn: &mut crate::object::TraverseFn<'_>) { // FIXME(discord9): Rc means shared ref, so should it be traced? self.content.traverse(tracer_fn) } @@ -1266,7 +1266,7 @@ pub(crate) struct PySetIterator { } impl fmt::Debug for PySetIterator { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // TODO: implement more detailed, non-recursive Debug formatter f.write_str("set_iterator") } diff --git a/vm/src/builtins/str.rs b/vm/src/builtins/str.rs index bf9a9f679..3446a3d54 100644 --- a/vm/src/builtins/str.rs +++ b/vm/src/builtins/str.rs @@ -62,7 +62,7 @@ pub struct PyStr { } impl fmt::Debug for PyStr { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("PyStr") .field("value", &self.as_str()) .field("kind", &self.kind) @@ -192,7 +192,7 @@ pub struct PyStrIterator { } unsafe impl Traverse for PyStrIterator { - fn traverse(&self, tracer: &mut TraverseFn) { + fn traverse(&self, tracer: &mut TraverseFn<'_>) { // No need to worry about deadlock, for inner is a PyStr and can't make ref cycle self.internal.lock().0.traverse(tracer); } @@ -351,7 +351,7 @@ impl PyStr { } } - fn borrow(&self) -> &BorrowedStr { + fn borrow(&self) -> &BorrowedStr<'_> { unsafe { std::mem::transmute(self) } } diff --git a/vm/src/builtins/tuple.rs b/vm/src/builtins/tuple.rs index 66cb2799a..c9af04d30 100644 --- a/vm/src/builtins/tuple.rs +++ b/vm/src/builtins/tuple.rs @@ -28,7 +28,7 @@ pub struct PyTuple { } impl fmt::Debug for PyTuple { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // TODO: implement more informational, non-recursive Debug formatter f.write_str("tuple") } @@ -513,7 +513,7 @@ unsafe impl Traverse for PyTupleTyped where T: TransmuteFromObject + Traverse, { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.tuple.traverse(tracer_fn); } } diff --git a/vm/src/builtins/type.rs b/vm/src/builtins/type.rs index 08a15575e..e8ad67a66 100644 --- a/vm/src/builtins/type.rs +++ b/vm/src/builtins/type.rs @@ -45,7 +45,7 @@ pub struct PyType { } unsafe impl crate::object::Traverse for PyType { - fn traverse(&self, tracer_fn: &mut crate::object::TraverseFn) { + fn traverse(&self, tracer_fn: &mut crate::object::TraverseFn<'_>) { self.base.traverse(tracer_fn); self.bases.traverse(tracer_fn); self.mro.traverse(tracer_fn); @@ -119,7 +119,7 @@ cfg_if::cfg_if! { pub type PyAttributes = IndexMap<&'static PyStrInterned, PyObjectRef, ahash::RandomState>; unsafe impl Traverse for PyAttributes { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.values().for_each(|v| v.traverse(tracer_fn)); } } @@ -131,7 +131,7 @@ impl fmt::Display for PyType { } impl fmt::Debug for PyType { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "[PyType {}]", &self.name()) } } @@ -406,14 +406,14 @@ impl PyType { } } - pub fn slot_name(&self) -> BorrowedValue { + pub fn slot_name(&self) -> BorrowedValue<'_, str> { self.name_inner( |name| name.into(), |ext| PyRwLockReadGuard::map(ext.name.read(), |name| name.as_str()).into(), ) } - pub fn name(&self) -> BorrowedValue { + pub fn name(&self) -> BorrowedValue<'_, str> { self.name_inner( |name| name.rsplit_once('.').map_or(name, |(_, name)| name).into(), |ext| PyRwLockReadGuard::map(ext.name.read(), |name| name.as_str()).into(), diff --git a/vm/src/builtins/union.rs b/vm/src/builtins/union.rs index f9dc8f313..2798724ae 100644 --- a/vm/src/builtins/union.rs +++ b/vm/src/builtins/union.rs @@ -22,7 +22,7 @@ pub struct PyUnion { } impl fmt::Debug for PyUnion { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("UnionObject") } } diff --git a/vm/src/dictdatatype.rs b/vm/src/dictdatatype.rs index 7c8fd2383..912aa8e77 100644 --- a/vm/src/dictdatatype.rs +++ b/vm/src/dictdatatype.rs @@ -35,7 +35,7 @@ pub struct Dict { } unsafe impl Traverse for Dict { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.inner.traverse(tracer_fn); } } @@ -79,7 +79,7 @@ struct DictInner { } unsafe impl Traverse for DictInner { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.entries .iter() .map(|v| { @@ -548,7 +548,7 @@ impl Dict { vm: &VirtualMachine, key: &K, hash_value: HashValue, - mut lock: Option>>, + mut lock: Option>>, ) -> PyResult { let mut idxs = None; let mut free_slot = None; diff --git a/vm/src/exceptions.rs b/vm/src/exceptions.rs index 5882fbe2b..d2f410b30 100644 --- a/vm/src/exceptions.rs +++ b/vm/src/exceptions.rs @@ -22,7 +22,7 @@ use std::{ }; unsafe impl Traverse for PyBaseException { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.traceback.traverse(tracer_fn); self.cause.traverse(tracer_fn); self.context.traverse(tracer_fn); @@ -31,7 +31,7 @@ unsafe impl Traverse for PyBaseException { } impl std::fmt::Debug for PyBaseException { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { // TODO: implement more detailed, non-recursive Debug formatter f.write_str("PyBaseException") } diff --git a/vm/src/frame.rs b/vm/src/frame.rs index 7cbe25909..ec5dad10a 100644 --- a/vm/src/frame.rs +++ b/vm/src/frame.rs @@ -221,7 +221,7 @@ impl Frame { impl Py { #[inline(always)] - fn with_exec(&self, f: impl FnOnce(ExecutingFrame) -> R) -> R { + fn with_exec(&self, f: impl FnOnce(ExecutingFrame<'_>) -> R) -> R { let mut state = self.state.lock(); let exec = ExecutingFrame { code: &self.code, @@ -308,7 +308,7 @@ struct ExecutingFrame<'a> { } impl fmt::Debug for ExecutingFrame<'_> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("ExecutingFrame") .field("code", self.code) // .field("scope", self.scope) @@ -371,7 +371,7 @@ impl ExecutingFrame<'_> { Err(exception) => { #[cold] fn handle_exception( - frame: &mut ExecutingFrame, + frame: &mut ExecutingFrame<'_>, exception: PyBaseExceptionRef, idx: usize, vm: &VirtualMachine, @@ -2081,7 +2081,7 @@ impl ExecutingFrame<'_> { } } - fn pop_multiple(&mut self, count: usize) -> crate::common::boxvec::Drain { + fn pop_multiple(&mut self, count: usize) -> crate::common::boxvec::Drain<'_, PyObjectRef> { let stack_len = self.state.stack.len(); self.state.stack.drain(stack_len - count..) } @@ -2119,7 +2119,7 @@ impl ExecutingFrame<'_> { } impl fmt::Debug for Frame { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let state = self.state.lock(); let stack_str = state.stack.iter().fold(String::new(), |mut s, elem| { if elem.payload_is::() { diff --git a/vm/src/function/argument.rs b/vm/src/function/argument.rs index b7fd509ef..197cfe7b9 100644 --- a/vm/src/function/argument.rs +++ b/vm/src/function/argument.rs @@ -67,7 +67,7 @@ pub struct FuncArgs { } unsafe impl Traverse for IndexMap { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.values().for_each(|v| v.traverse(tracer_fn)); } } @@ -336,7 +336,7 @@ unsafe impl Traverse for KwArgs where T: Traverse, { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.0.iter().map(|(_, v)| v.traverse(tracer_fn)).count(); } } @@ -402,7 +402,7 @@ unsafe impl Traverse for PosArgs where T: Traverse, { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.0.traverse(tracer_fn) } } @@ -416,7 +416,7 @@ impl PosArgs { self.0 } - pub fn iter(&self) -> std::slice::Iter { + pub fn iter(&self) -> std::slice::Iter<'_, T> { self.0.iter() } } @@ -495,7 +495,7 @@ unsafe impl Traverse for OptionalArg where T: Traverse, { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { match self { OptionalArg::Present(o) => o.traverse(tracer_fn), OptionalArg::Missing => (), diff --git a/vm/src/function/protocol.rs b/vm/src/function/protocol.rs index 4b7e4c4ce..2f4b4d160 100644 --- a/vm/src/function/protocol.rs +++ b/vm/src/function/protocol.rs @@ -81,7 +81,7 @@ pub struct ArgIterable { } unsafe impl Traverse for ArgIterable { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.iterable.traverse(tracer_fn) } } @@ -143,7 +143,7 @@ impl ArgMapping { } #[inline(always)] - pub fn mapping(&self) -> PyMapping { + pub fn mapping(&self) -> PyMapping<'_> { PyMapping { obj: &self.obj, methods: self.methods, @@ -200,7 +200,7 @@ impl TryFromObject for ArgMapping { pub struct ArgSequence(Vec); unsafe impl Traverse for ArgSequence { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.0.traverse(tracer_fn); } } diff --git a/vm/src/object/core.rs b/vm/src/object/core.rs index 481111532..56ab419c0 100644 --- a/vm/src/object/core.rs +++ b/vm/src/object/core.rs @@ -81,14 +81,17 @@ pub(super) unsafe fn drop_dealloc_obj(x: *mut PyObject) { } pub(super) unsafe fn debug_obj( x: &PyObject, - f: &mut fmt::Formatter, + f: &mut fmt::Formatter<'_>, ) -> fmt::Result { let x = unsafe { &*(x as *const PyObject as *const PyInner) }; fmt::Debug::fmt(x, f) } /// Call `try_trace` on payload -pub(super) unsafe fn try_trace_obj(x: &PyObject, tracer_fn: &mut TraverseFn) { +pub(super) unsafe fn try_trace_obj( + x: &PyObject, + tracer_fn: &mut TraverseFn<'_>, +) { let x = unsafe { &*(x as *const PyObject as *const PyInner) }; let payload = &x.payload; payload.try_traverse(tracer_fn) @@ -113,7 +116,7 @@ pub(super) struct PyInner { } impl fmt::Debug for PyInner { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "[PyObject {:?}]", &self.payload) } } @@ -121,7 +124,7 @@ impl fmt::Debug for PyInner { unsafe impl Traverse for Py { /// DO notice that call `trace` on `Py` means apply `tracer_fn` on `Py`'s children, /// not like call `trace` on `PyRef` which apply `tracer_fn` on `PyRef` itself - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.0.traverse(tracer_fn) } } @@ -129,7 +132,7 @@ unsafe impl Traverse for Py { unsafe impl Traverse for PyObject { /// DO notice that call `trace` on `PyObject` means apply `tracer_fn` on `PyObject`'s children, /// not like call `trace` on `PyObjectRef` which apply `tracer_fn` on `PyObjectRef` itself - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.0.traverse(tracer_fn) } } @@ -139,7 +142,7 @@ pub(super) struct WeakRefList { } impl fmt::Debug for WeakRefList { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("WeakRefList").finish_non_exhaustive() } } @@ -972,7 +975,7 @@ where } impl fmt::Debug for Py { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { (**self).fmt(f) } } @@ -999,7 +1002,7 @@ cfg_if::cfg_if! { } impl fmt::Debug for PyRef { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { (**self).fmt(f) } } diff --git a/vm/src/object/ext.rs b/vm/src/object/ext.rs index 8c6d36758..b2bc6eec4 100644 --- a/vm/src/object/ext.rs +++ b/vm/src/object/ext.rs @@ -43,7 +43,7 @@ impl fmt::Display for PyRef where T: PyObjectPayload + fmt::Display, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&**self, f) } } @@ -51,7 +51,7 @@ impl fmt::Display for Py where T: PyObjectPayload + fmt::Display, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&**self, f) } } @@ -534,7 +534,7 @@ impl fmt::Display for PyLease<'_, T> where T: PyPayload + fmt::Display, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(&**self, f) } } diff --git a/vm/src/object/traverse.rs b/vm/src/object/traverse.rs index 5f93dc5c8..9ff0f8834 100644 --- a/vm/src/object/traverse.rs +++ b/vm/src/object/traverse.rs @@ -14,7 +14,7 @@ pub trait MaybeTraverse { /// if is traceable, will be used by vtable to determine const IS_TRACE: bool = false; // if this type is traceable, then call with tracer_fn, default to do nothing - fn try_traverse(&self, traverse_fn: &mut TraverseFn); + fn try_traverse(&self, traverse_fn: &mut TraverseFn<'_>); } /// Type that need traverse it's children should impl `Traverse`(Not `MaybeTraverse`) @@ -27,28 +27,28 @@ pub unsafe trait Traverse { /// but if some field is called repeatedly, panic and deadlock can happen. /// /// - _**DO NOT**_ clone a `PyObjectRef` or `Pyef` in `traverse()` - fn traverse(&self, traverse_fn: &mut TraverseFn); + fn traverse(&self, traverse_fn: &mut TraverseFn<'_>); } unsafe impl Traverse for PyObjectRef { - fn traverse(&self, traverse_fn: &mut TraverseFn) { + fn traverse(&self, traverse_fn: &mut TraverseFn<'_>) { traverse_fn(self) } } unsafe impl Traverse for PyRef { - fn traverse(&self, traverse_fn: &mut TraverseFn) { + fn traverse(&self, traverse_fn: &mut TraverseFn<'_>) { traverse_fn(self.as_object()) } } unsafe impl Traverse for () { - fn traverse(&self, _traverse_fn: &mut TraverseFn) {} + fn traverse(&self, _traverse_fn: &mut TraverseFn<'_>) {} } unsafe impl Traverse for Option { #[inline] - fn traverse(&self, traverse_fn: &mut TraverseFn) { + fn traverse(&self, traverse_fn: &mut TraverseFn<'_>) { if let Some(v) = self { v.traverse(traverse_fn); } @@ -60,7 +60,7 @@ where T: Traverse, { #[inline] - fn traverse(&self, traverse_fn: &mut TraverseFn) { + fn traverse(&self, traverse_fn: &mut TraverseFn<'_>) { for elem in self { elem.traverse(traverse_fn); } @@ -72,7 +72,7 @@ where T: Traverse, { #[inline] - fn traverse(&self, traverse_fn: &mut TraverseFn) { + fn traverse(&self, traverse_fn: &mut TraverseFn<'_>) { for elem in &**self { elem.traverse(traverse_fn); } @@ -84,7 +84,7 @@ where T: Traverse, { #[inline] - fn traverse(&self, traverse_fn: &mut TraverseFn) { + fn traverse(&self, traverse_fn: &mut TraverseFn<'_>) { for elem in self { elem.traverse(traverse_fn); } @@ -93,7 +93,7 @@ where unsafe impl Traverse for PyRwLock { #[inline] - fn traverse(&self, traverse_fn: &mut TraverseFn) { + fn traverse(&self, traverse_fn: &mut TraverseFn<'_>) { // if can't get a lock, this means something else is holding the lock, // but since gc stopped the world, during gc the lock is always held // so it is safe to ignore those in gc @@ -109,7 +109,7 @@ unsafe impl Traverse for PyRwLock { /// and refcnt is atomic, so it should be fine?) unsafe impl Traverse for PyMutex { #[inline] - fn traverse(&self, traverse_fn: &mut TraverseFn) { + fn traverse(&self, traverse_fn: &mut TraverseFn<'_>) { let mut chs: Vec> = Vec::new(); if let Some(obj) = self.try_lock() { obj.traverse(&mut |ch| { @@ -130,7 +130,7 @@ macro_rules! trace_tuple { ($(($NAME: ident, $NUM: tt)),*) => { unsafe impl<$($NAME: Traverse),*> Traverse for ($($NAME),*) { #[inline] - fn traverse(&self, traverse_fn: &mut TraverseFn) { + fn traverse(&self, traverse_fn: &mut TraverseFn<'_>) { $( self.$NUM.traverse(traverse_fn); )* @@ -142,7 +142,7 @@ macro_rules! trace_tuple { unsafe impl Traverse for Either { #[inline] - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { match self { Either::A(a) => a.traverse(tracer_fn), Either::B(b) => b.traverse(tracer_fn), @@ -154,7 +154,7 @@ unsafe impl Traverse for Either { // because long tuple is extremely rare in almost every case unsafe impl Traverse for (A,) { #[inline] - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.0.traverse(tracer_fn); } } diff --git a/vm/src/object/traverse_object.rs b/vm/src/object/traverse_object.rs index 682ddf487..2cf4fba2d 100644 --- a/vm/src/object/traverse_object.rs +++ b/vm/src/object/traverse_object.rs @@ -11,8 +11,8 @@ use super::{Traverse, TraverseFn}; pub(in crate::object) struct PyObjVTable { pub(in crate::object) drop_dealloc: unsafe fn(*mut PyObject), - pub(in crate::object) debug: unsafe fn(&PyObject, &mut fmt::Formatter) -> fmt::Result, - pub(in crate::object) trace: Option, + pub(in crate::object) debug: unsafe fn(&PyObject, &mut fmt::Formatter<'_>) -> fmt::Result, + pub(in crate::object) trace: Option)>, } impl PyObjVTable { @@ -32,14 +32,14 @@ impl PyObjVTable { } unsafe impl Traverse for InstanceDict { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.d.traverse(tracer_fn) } } unsafe impl Traverse for PyInner { /// Because PyObject hold a `PyInner`, so we need to trace it - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { // 1. trace `dict` and `slots` field(`typ` can't trace for it's a AtomicRef while is leaked by design) // 2. call vtable's trace function to trace payload // self.typ.trace(tracer_fn); @@ -58,7 +58,7 @@ unsafe impl Traverse for PyInner { unsafe impl Traverse for PyInner { /// Type is known, so we can call `try_trace` directly instead of using erased type vtable - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { // 1. trace `dict` and `slots` field(`typ` can't trace for it's a AtomicRef while is leaked by design) // 2. call corresponding `try_trace` function to trace payload // (No need to call vtable's trace function because we already know the type) diff --git a/vm/src/protocol/buffer.rs b/vm/src/protocol/buffer.rs index 8692e4f78..e3b03b4f8 100644 --- a/vm/src/protocol/buffer.rs +++ b/vm/src/protocol/buffer.rs @@ -15,8 +15,8 @@ use itertools::Itertools; use std::{borrow::Cow, fmt::Debug, ops::Range}; pub struct BufferMethods { - pub obj_bytes: fn(&PyBuffer) -> BorrowedValue<[u8]>, - pub obj_bytes_mut: fn(&PyBuffer) -> BorrowedValueMut<[u8]>, + pub obj_bytes: fn(&PyBuffer) -> BorrowedValue<'_, [u8]>, + pub obj_bytes_mut: fn(&PyBuffer) -> BorrowedValueMut<'_, [u8]>, pub release: fn(&PyBuffer), pub retain: fn(&PyBuffer), } @@ -52,13 +52,13 @@ impl PyBuffer { zelf } - pub fn as_contiguous(&self) -> Option> { + pub fn as_contiguous(&self) -> Option> { self.desc .is_contiguous() .then(|| unsafe { self.contiguous_unchecked() }) } - pub fn as_contiguous_mut(&self) -> Option> { + pub fn as_contiguous_mut(&self) -> Option> { (!self.desc.readonly && self.desc.is_contiguous()) .then(|| unsafe { self.contiguous_mut_unchecked() }) } @@ -74,13 +74,13 @@ impl PyBuffer { /// # Safety /// assume the buffer is contiguous - pub unsafe fn contiguous_unchecked(&self) -> BorrowedValue<[u8]> { + pub unsafe fn contiguous_unchecked(&self) -> BorrowedValue<'_, [u8]> { self.obj_bytes() } /// # Safety /// assume the buffer is contiguous and writable - pub unsafe fn contiguous_mut_unchecked(&self) -> BorrowedValueMut<[u8]> { + pub unsafe fn contiguous_mut_unchecked(&self) -> BorrowedValueMut<'_, [u8]> { self.obj_bytes_mut() } @@ -113,11 +113,11 @@ impl PyBuffer { unsafe { self.obj.downcast_unchecked_ref() } } - pub fn obj_bytes(&self) -> BorrowedValue<[u8]> { + pub fn obj_bytes(&self) -> BorrowedValue<'_, [u8]> { (self.methods.obj_bytes)(self) } - pub fn obj_bytes_mut(&self) -> BorrowedValueMut<[u8]> { + pub fn obj_bytes_mut(&self) -> BorrowedValueMut<'_, [u8]> { (self.methods.obj_bytes_mut)(self) } diff --git a/vm/src/protocol/callable.rs b/vm/src/protocol/callable.rs index ca1055572..1444b6bf7 100644 --- a/vm/src/protocol/callable.rs +++ b/vm/src/protocol/callable.rs @@ -62,7 +62,7 @@ enum TraceEvent { } impl std::fmt::Display for TraceEvent { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { use TraceEvent::*; match self { Call => write!(f, "call"), diff --git a/vm/src/protocol/iter.rs b/vm/src/protocol/iter.rs index 345914e41..a7491a389 100644 --- a/vm/src/protocol/iter.rs +++ b/vm/src/protocol/iter.rs @@ -16,7 +16,7 @@ where O: Borrow; unsafe impl> Traverse for PyIter { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.0.borrow().traverse(tracer_fn); } } @@ -70,7 +70,7 @@ where impl PyIter { /// Returns an iterator over this sequence of objects. - pub fn into_iter(self, vm: &VirtualMachine) -> PyResult> { + pub fn into_iter(self, vm: &VirtualMachine) -> PyResult> { let length_hint = vm.length_hint_opt(self.as_object().to_owned())?; Ok(PyIterIter::new(vm, self.0, length_hint)) } @@ -157,7 +157,7 @@ pub enum PyIterReturn { } unsafe impl Traverse for PyIterReturn { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { match self { PyIterReturn::Return(r) => r.traverse(tracer_fn), PyIterReturn::StopIteration(Some(obj)) => obj.traverse(tracer_fn), @@ -233,7 +233,7 @@ unsafe impl Traverse for PyIterIter<'_, T, O> where O: Traverse + Borrow, { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.obj.traverse(tracer_fn) } } diff --git a/vm/src/protocol/mapping.rs b/vm/src/protocol/mapping.rs index cbecc8762..6b60ae6e0 100644 --- a/vm/src/protocol/mapping.rs +++ b/vm/src/protocol/mapping.rs @@ -22,15 +22,15 @@ impl PyObject { #[allow(clippy::type_complexity)] #[derive(Default)] pub struct PyMappingMethods { - pub length: AtomicCell PyResult>>, - pub subscript: AtomicCell PyResult>>, + pub length: AtomicCell, &VirtualMachine) -> PyResult>>, + pub subscript: AtomicCell, &PyObject, &VirtualMachine) -> PyResult>>, pub ass_subscript: AtomicCell< - Option, &VirtualMachine) -> PyResult<()>>, + Option, &PyObject, Option, &VirtualMachine) -> PyResult<()>>, >, } impl std::fmt::Debug for PyMappingMethods { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "mapping methods") } } @@ -64,7 +64,7 @@ pub struct PyMapping<'a> { } unsafe impl Traverse for PyMapping<'_> { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.obj.traverse(tracer_fn) } } diff --git a/vm/src/protocol/number.rs b/vm/src/protocol/number.rs index 65c4eaad7..2b6720e84 100644 --- a/vm/src/protocol/number.rs +++ b/vm/src/protocol/number.rs @@ -12,13 +12,13 @@ use crate::{ stdlib::warnings, }; -pub type PyNumberUnaryFunc = fn(PyNumber, &VirtualMachine) -> PyResult; +pub type PyNumberUnaryFunc = fn(PyNumber<'_>, &VirtualMachine) -> PyResult; pub type PyNumberBinaryFunc = fn(&PyObject, &PyObject, &VirtualMachine) -> PyResult; pub type PyNumberTernaryFunc = fn(&PyObject, &PyObject, &PyObject, &VirtualMachine) -> PyResult; impl PyObject { #[inline] - pub fn to_number(&self) -> PyNumber { + pub fn to_number(&self) -> PyNumber<'_> { PyNumber(self) } @@ -427,7 +427,7 @@ impl PyNumberSlots { pub struct PyNumber<'a>(&'a PyObject); unsafe impl Traverse for PyNumber<'_> { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.0.traverse(tracer_fn) } } diff --git a/vm/src/protocol/sequence.rs b/vm/src/protocol/sequence.rs index 46ac0c8be..5d5622c15 100644 --- a/vm/src/protocol/sequence.rs +++ b/vm/src/protocol/sequence.rs @@ -28,16 +28,18 @@ impl PyObject { #[allow(clippy::type_complexity)] #[derive(Default)] pub struct PySequenceMethods { - pub length: AtomicCell PyResult>>, - pub concat: AtomicCell PyResult>>, - pub repeat: AtomicCell PyResult>>, - pub item: AtomicCell PyResult>>, + pub length: AtomicCell, &VirtualMachine) -> PyResult>>, + pub concat: AtomicCell, &PyObject, &VirtualMachine) -> PyResult>>, + pub repeat: AtomicCell, isize, &VirtualMachine) -> PyResult>>, + pub item: AtomicCell, isize, &VirtualMachine) -> PyResult>>, pub ass_item: AtomicCell< - Option, &VirtualMachine) -> PyResult<()>>, + Option, isize, Option, &VirtualMachine) -> PyResult<()>>, >, - pub contains: AtomicCell PyResult>>, - pub inplace_concat: AtomicCell PyResult>>, - pub inplace_repeat: AtomicCell PyResult>>, + pub contains: + AtomicCell, &PyObject, &VirtualMachine) -> PyResult>>, + pub inplace_concat: + AtomicCell, &PyObject, &VirtualMachine) -> PyResult>>, + pub inplace_repeat: AtomicCell, isize, &VirtualMachine) -> PyResult>>, } impl Debug for PySequenceMethods { @@ -67,7 +69,7 @@ pub struct PySequence<'a> { } unsafe impl Traverse for PySequence<'_> { - fn traverse(&self, tracer_fn: &mut TraverseFn) { + fn traverse(&self, tracer_fn: &mut TraverseFn<'_>) { self.obj.traverse(tracer_fn) } } diff --git a/vm/src/py_io.rs b/vm/src/py_io.rs index 0d7c319bc..c50f09e2b 100644 --- a/vm/src/py_io.rs +++ b/vm/src/py_io.rs @@ -7,7 +7,7 @@ use std::{fmt, io, ops}; pub trait Write { type Error; - fn write_fmt(&mut self, args: fmt::Arguments) -> Result<(), Self::Error>; + fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> Result<(), Self::Error>; } #[repr(transparent)] @@ -37,14 +37,14 @@ where W: io::Write, { type Error = io::Error; - fn write_fmt(&mut self, args: fmt::Arguments) -> io::Result<()> { + fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> io::Result<()> { ::write_fmt(&mut self.0, args) } } impl Write for String { type Error = fmt::Error; - fn write_fmt(&mut self, args: fmt::Arguments) -> fmt::Result { + fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> fmt::Result { ::write_fmt(self, args) } } @@ -53,7 +53,7 @@ pub struct PyWriter<'vm>(pub PyObjectRef, pub &'vm VirtualMachine); impl Write for PyWriter<'_> { type Error = PyBaseExceptionRef; - fn write_fmt(&mut self, args: fmt::Arguments) -> Result<(), Self::Error> { + fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> Result<(), Self::Error> { let PyWriter(obj, vm) = self; vm.call_method(obj, "write", (args.to_string(),)).map(drop) } diff --git a/vm/src/py_serde.rs b/vm/src/py_serde.rs index ea72879e4..6c23f924e 100644 --- a/vm/src/py_serde.rs +++ b/vm/src/py_serde.rs @@ -41,7 +41,7 @@ impl<'s> PyObjectSerializer<'s> { PyObjectSerializer { pyobject, vm } } - fn clone_with_object(&self, pyobject: &'s PyObjectRef) -> PyObjectSerializer { + fn clone_with_object(&self, pyobject: &'s PyObjectRef) -> PyObjectSerializer<'_> { PyObjectSerializer { pyobject, vm: self.vm, @@ -130,7 +130,7 @@ impl<'de> DeserializeSeed<'de> for PyObjectDeserializer<'de> { impl<'de> Visitor<'de> for PyObjectDeserializer<'de> { type Value = PyObjectRef; - fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { + fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { formatter.write_str("a type that can deserialize in Python") } diff --git a/vm/src/scope.rs b/vm/src/scope.rs index 12b878f84..e01209857 100644 --- a/vm/src/scope.rs +++ b/vm/src/scope.rs @@ -8,7 +8,7 @@ pub struct Scope { } impl fmt::Debug for Scope { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // TODO: have a more informative Debug impl that DOESN'T recurse and cause a stack overflow f.write_str("Scope") } diff --git a/vm/src/signal.rs b/vm/src/signal.rs index 346664fa2..846114794 100644 --- a/vm/src/signal.rs +++ b/vm/src/signal.rs @@ -107,14 +107,14 @@ impl UserSignalSender { pub struct UserSignalSendError(pub UserSignal); impl fmt::Debug for UserSignalSendError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("UserSignalSendError") .finish_non_exhaustive() } } impl fmt::Display for UserSignalSendError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("sending a signal to a exited vm") } } diff --git a/vm/src/stdlib/ctypes/library.rs b/vm/src/stdlib/ctypes/library.rs index 94b632744..f777d26bc 100644 --- a/vm/src/stdlib/ctypes/library.rs +++ b/vm/src/stdlib/ctypes/library.rs @@ -12,7 +12,7 @@ pub struct SharedLibrary { } impl fmt::Debug for SharedLibrary { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "SharedLibrary") } } @@ -30,7 +30,7 @@ impl SharedLibrary { unsafe { inner .get(name.as_bytes()) - .map(|f: libloading::Symbol<*mut c_void>| *f) + .map(|f: libloading::Symbol<'_, *mut c_void>| *f) .map_err(|err| err.to_string()) } } else { diff --git a/vm/src/stdlib/io.rs b/vm/src/stdlib/io.rs index 1b5eb6d60..0f472fd94 100644 --- a/vm/src/stdlib/io.rs +++ b/vm/src/stdlib/io.rs @@ -1392,7 +1392,7 @@ mod _io { const WRITABLE: bool; const SEEKABLE: bool = false; fn data(&self) -> &PyThreadMutex; - fn lock(&self, vm: &VirtualMachine) -> PyResult> { + fn lock(&self, vm: &VirtualMachine) -> PyResult> { self.data() .lock() .ok_or_else(|| vm.new_runtime_error("reentrant call inside buffered io".to_owned())) @@ -2273,13 +2273,13 @@ mod _io { fn lock_opt( &self, vm: &VirtualMachine, - ) -> PyResult>> { + ) -> PyResult>> { self.data .lock() .ok_or_else(|| vm.new_runtime_error("reentrant call inside textio".to_owned())) } - fn lock(&self, vm: &VirtualMachine) -> PyResult> { + fn lock(&self, vm: &VirtualMachine) -> PyResult> { let lock = self.lock_opt(vm)?; PyThreadMutexGuard::try_map(lock, |x| x.as_mut()) .map_err(|_| vm.new_value_error("I/O operation on uninitialized object".to_owned())) @@ -3210,7 +3210,7 @@ mod _io { fn lock_opt( &self, vm: &VirtualMachine, - ) -> PyResult>> { + ) -> PyResult>> { self.data .lock() .ok_or_else(|| vm.new_runtime_error("reentrant call inside nldecoder".to_owned())) @@ -3219,7 +3219,7 @@ mod _io { fn lock( &self, vm: &VirtualMachine, - ) -> PyResult> { + ) -> PyResult> { let lock = self.lock_opt(vm)?; PyThreadMutexGuard::try_map(lock, |x| x.as_mut()).map_err(|_| { vm.new_value_error("I/O operation on uninitialized nldecoder".to_owned()) diff --git a/vm/src/stdlib/sre.rs b/vm/src/stdlib/sre.rs index 7d620c13d..193976a62 100644 --- a/vm/src/stdlib/sre.rs +++ b/vm/src/stdlib/sre.rs @@ -53,7 +53,7 @@ mod _sre { trait SreStr: StrDrive { fn slice(&self, start: usize, end: usize, vm: &VirtualMachine) -> PyObjectRef; - fn create_request(self, pattern: &Pattern, start: usize, end: usize) -> Request { + fn create_request(self, pattern: &Pattern, start: usize, end: usize) -> Request<'_, Self> { Request::new(self, start, end, &pattern.code, false) } } diff --git a/vm/src/stdlib/symtable.rs b/vm/src/stdlib/symtable.rs index 13a410511..7a575cb08 100644 --- a/vm/src/stdlib/symtable.rs +++ b/vm/src/stdlib/symtable.rs @@ -41,7 +41,7 @@ mod symtable { } impl fmt::Debug for PySymbolTable { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "SymbolTable()") } } @@ -157,7 +157,7 @@ mod symtable { } impl fmt::Debug for PySymbol { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Symbol()") } } diff --git a/vm/src/stdlib/thread.rs b/vm/src/stdlib/thread.rs index bca793043..a664d6cdc 100644 --- a/vm/src/stdlib/thread.rs +++ b/vm/src/stdlib/thread.rs @@ -115,7 +115,7 @@ pub(crate) mod _thread { } impl fmt::Debug for Lock { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("Lock") } } @@ -192,7 +192,7 @@ pub(crate) mod _thread { } impl fmt::Debug for RLock { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("RLock") } } diff --git a/vm/src/stdlib/time.rs b/vm/src/stdlib/time.rs index 37a518e50..c464dc3ab 100644 --- a/vm/src/stdlib/time.rs +++ b/vm/src/stdlib/time.rs @@ -450,7 +450,7 @@ mod decl { } impl std::fmt::Debug for PyStructTime { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "struct_time()") } } diff --git a/vm/src/types/slot.rs b/vm/src/types/slot.rs index de651580d..2d8c82581 100644 --- a/vm/src/types/slot.rs +++ b/vm/src/types/slot.rs @@ -1232,7 +1232,7 @@ pub trait AsMapping: PyPayload { fn as_mapping() -> &'static PyMappingMethods; #[inline] - fn mapping_downcast(mapping: PyMapping) -> &Py { + fn mapping_downcast(mapping: PyMapping<'_>) -> &Py { unsafe { mapping.obj.downcast_unchecked_ref() } } } @@ -1243,7 +1243,7 @@ pub trait AsSequence: PyPayload { fn as_sequence() -> &'static PySequenceMethods; #[inline] - fn sequence_downcast(seq: PySequence) -> &Py { + fn sequence_downcast(seq: PySequence<'_>) -> &Py { unsafe { seq.obj.downcast_unchecked_ref() } } } @@ -1259,12 +1259,12 @@ pub trait AsNumber: PyPayload { } #[inline] - fn number_downcast(num: PyNumber) -> &Py { + fn number_downcast(num: PyNumber<'_>) -> &Py { unsafe { num.obj().downcast_unchecked_ref() } } #[inline] - fn number_downcast_exact(num: PyNumber, vm: &VirtualMachine) -> PyRef { + fn number_downcast_exact(num: PyNumber<'_>, vm: &VirtualMachine) -> PyRef { if let Some(zelf) = num.downcast_ref_if_exact::(vm) { zelf.to_owned() } else { diff --git a/vm/src/vm/mod.rs b/vm/src/vm/mod.rs index 05ac245a0..dd647e36f 100644 --- a/vm/src/vm/mod.rs +++ b/vm/src/vm/mod.rs @@ -497,7 +497,7 @@ impl VirtualMachine { } } - pub fn current_frame(&self) -> Option> { + pub fn current_frame(&self) -> Option> { let frames = self.frames.borrow(); if frames.is_empty() { None @@ -514,7 +514,7 @@ impl VirtualMachine { .locals(self) } - pub fn current_globals(&self) -> Ref { + pub fn current_globals(&self) -> Ref<'_, PyDictRef> { let frame = self .current_frame() .expect("called current_globals but no frames on the stack"); diff --git a/vm/sre_engine/src/engine.rs b/vm/sre_engine/src/engine.rs index 3425da337..bf0a6046f 100644 --- a/vm/sre_engine/src/engine.rs +++ b/vm/sre_engine/src/engine.rs @@ -122,14 +122,14 @@ pub struct State { } impl State { - pub fn reset(&mut self, req: &Request, start: usize) { + pub fn reset(&mut self, req: &Request<'_, S>, start: usize) { self.marks.clear(); self.repeat_stack.clear(); self.start = start; req.string.adjust_cursor(&mut self.cursor, start); } - pub fn pymatch(&mut self, req: &Request) -> bool { + pub fn pymatch(&mut self, req: &Request<'_, S>) -> bool { self.start = req.start; req.string.adjust_cursor(&mut self.cursor, self.start); @@ -144,7 +144,7 @@ impl State { _match(req, self, ctx) } - pub fn search(&mut self, mut req: Request) -> bool { + pub fn search(&mut self, mut req: Request<'_, S>) -> bool { self.start = req.start; req.string.adjust_cursor(&mut self.cursor, self.start); @@ -279,7 +279,7 @@ enum Jump { PossessiveRepeat4, } -fn _match(req: &Request, state: &mut State, mut ctx: MatchContext) -> bool { +fn _match(req: &Request<'_, S>, state: &mut State, mut ctx: MatchContext) -> bool { let mut context_stack = vec![]; let mut popped_result = false; @@ -882,7 +882,7 @@ fn _match(req: &Request, state: &mut State, mut ctx: MatchContex } fn search_info_literal( - req: &mut Request, + req: &mut Request<'_, S>, state: &mut State, mut ctx: MatchContext, ) -> bool { @@ -998,7 +998,7 @@ fn search_info_literal( } fn search_info_charset( - req: &mut Request, + req: &mut Request<'_, S>, state: &mut State, mut ctx: MatchContext, ) -> bool { @@ -1054,11 +1054,11 @@ impl MatchContext { &req.pattern_codes[self.code_position..] } - fn remaining_codes(&self, req: &Request) -> usize { + fn remaining_codes(&self, req: &Request<'_, S>) -> usize { req.pattern_codes.len() - self.code_position } - fn remaining_chars(&self, req: &Request) -> usize { + fn remaining_chars(&self, req: &Request<'_, S>) -> usize { req.end - self.cursor.position } @@ -1086,11 +1086,11 @@ impl MatchContext { S::back_advance(&mut self.cursor) } - fn peek_code(&self, req: &Request, peek: usize) -> u32 { + fn peek_code(&self, req: &Request<'_, S>, peek: usize) -> u32 { req.pattern_codes[self.code_position + peek] } - fn try_peek_code_as(&self, req: &Request, peek: usize) -> Result + fn try_peek_code_as(&self, req: &Request<'_, S>, peek: usize) -> Result where T: TryFrom, { @@ -1101,7 +1101,7 @@ impl MatchContext { self.code_position += skip; } - fn skip_code_from(&mut self, req: &Request, peek: usize) { + fn skip_code_from(&mut self, req: &Request<'_, S>, peek: usize) { self.skip_code(self.peek_code(req, peek) as usize + 1); } @@ -1110,17 +1110,17 @@ impl MatchContext { self.cursor.position == 0 } - fn at_end(&self, req: &Request) -> bool { + fn at_end(&self, req: &Request<'_, S>) -> bool { self.cursor.position == req.end } - fn at_linebreak(&self, req: &Request) -> bool { + fn at_linebreak(&self, req: &Request<'_, S>) -> bool { !self.at_end(req) && is_linebreak(self.peek_char::()) } fn at_boundary bool>( &self, - req: &Request, + req: &Request<'_, S>, mut word_checker: F, ) -> bool { if self.at_beginning() && self.at_end(req) { @@ -1133,7 +1133,7 @@ impl MatchContext { fn at_non_boundary bool>( &self, - req: &Request, + req: &Request<'_, S>, mut word_checker: F, ) -> bool { if self.at_beginning() && self.at_end(req) { @@ -1144,7 +1144,7 @@ impl MatchContext { this == that } - fn can_success(&self, req: &Request) -> bool { + fn can_success(&self, req: &Request<'_, S>) -> bool { if !self.toplevel { return true; } @@ -1158,7 +1158,7 @@ impl MatchContext { } #[must_use] - fn next_peek_from(&mut self, peek: usize, req: &Request, jump: Jump) -> Self { + fn next_peek_from(&mut self, peek: usize, req: &Request<'_, S>, jump: Jump) -> Self { self.next_offset(self.peek_code(req, peek) as usize + 1, jump) } @@ -1179,7 +1179,7 @@ impl MatchContext { } } -fn at(req: &Request, ctx: &MatchContext, atcode: SreAtCode) -> bool { +fn at(req: &Request<'_, S>, ctx: &MatchContext, atcode: SreAtCode) -> bool { match atcode { SreAtCode::BEGINNING | SreAtCode::BEGINNING_STRING => ctx.at_beginning(), SreAtCode::BEGINNING_LINE => ctx.at_beginning() || is_linebreak(ctx.back_peek_char::()), @@ -1327,7 +1327,7 @@ fn charset(set: &[u32], ch: u32) -> bool { } fn _count( - req: &Request, + req: &Request<'_, S>, state: &mut State, ctx: &mut MatchContext, max_count: usize, @@ -1399,7 +1399,7 @@ fn _count( } fn general_count_literal bool>( - req: &Request, + req: &Request<'_, S>, ctx: &mut MatchContext, end: usize, mut f: F, diff --git a/wasm/lib/src/js_module.rs b/wasm/lib/src/js_module.rs index e25499df4..a5b728148 100644 --- a/wasm/lib/src/js_module.rs +++ b/wasm/lib/src/js_module.rs @@ -297,7 +297,7 @@ mod _js { } impl fmt::Debug for JsClosure { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.pad("JsClosure") } } diff --git a/wasm/lib/src/lib.rs b/wasm/lib/src/lib.rs index a5f1a5895..8d1d19dda 100644 --- a/wasm/lib/src/lib.rs +++ b/wasm/lib/src/lib.rs @@ -14,7 +14,7 @@ pub(crate) use vm_class::weak_vm; use wasm_bindgen::prelude::*; /// Sets error info on the window object, and prints the backtrace to console -pub fn panic_hook(info: &panic::PanicHookInfo) { +pub fn panic_hook(info: &panic::PanicHookInfo<'_>) { // If something errors, just ignore it; we don't want to panic in the panic hook let try_set_info = || { let msg = &info.to_string();