From 1aab5240cf91e26ee5093e3df2f4f6e3884c869f Mon Sep 17 00:00:00 2001 From: Noa Date: Wed, 20 Mar 2024 23:06:39 -0500 Subject: [PATCH 1/5] Update for rust 1.77 --- vm/src/object/core.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vm/src/object/core.rs b/vm/src/object/core.rs index 624a3a41a..6a8166b20 100644 --- a/vm/src/object/core.rs +++ b/vm/src/object/core.rs @@ -364,8 +364,11 @@ impl PyWeak { fn drop_inner(&self) { let dealloc = { let mut guard = unsafe { self.parent.as_ref().lock() }; - let offset = memoffset::offset_of!(PyInner, payload); - let pyinner = (self as *const Self as usize - offset) as *const PyInner; + let offset = std::mem::offset_of!(PyInner, payload); + let pyinner = (self as *const Self) + .cast::() + .wrapping_sub(offset) + .cast::>(); let node_ptr = unsafe { NonNull::new_unchecked(pyinner as *mut Py) }; // the list doesn't have ownership over its PyRef! we're being dropped // right now so that should be obvious!! From eae60113afd213cfd9a3dfb653cc015b19b4ad40 Mon Sep 17 00:00:00 2001 From: Noa Date: Sun, 16 Jun 2024 20:01:14 -0400 Subject: [PATCH 2/5] Update some stuff for inline const & associated type bounds --- common/src/str.rs | 13 ++++++++----- compiler/core/src/frozen.rs | 3 +-- vm/src/builtins/dict.rs | 7 ++----- vm/src/function/builtin.rs | 19 +++++++------------ vm/src/intern.rs | 8 ++------ vm/src/object/traverse_object.rs | 31 ++++++++++++------------------- vm/src/vm/mod.rs | 11 ++++------- 7 files changed, 36 insertions(+), 56 deletions(-) diff --git a/common/src/str.rs b/common/src/str.rs index 48fdb0f95..1606ebc07 100644 --- a/common/src/str.rs +++ b/common/src/str.rs @@ -331,12 +331,15 @@ pub mod levenshtein { /// ``` #[macro_export] macro_rules! ascii { - ($x:literal) => {{ - const STR: &str = $x; - const _: () = if !STR.is_ascii() { - panic!("ascii!() argument is not an ascii string"); + ($x:expr $(,)?) => {{ + let s = const { + let s: &str = $x; + if !s.is_ascii() { + panic!("ascii!() argument is not an ascii string"); + } + s }; - unsafe { $crate::vendored::ascii::AsciiStr::from_ascii_unchecked(STR.as_bytes()) } + unsafe { $crate::vendored::ascii::AsciiStr::from_ascii_unchecked(s.as_bytes()) } }}; } pub use ascii; diff --git a/compiler/core/src/frozen.rs b/compiler/core/src/frozen.rs index 4565eac8a..991898c1e 100644 --- a/compiler/core/src/frozen.rs +++ b/compiler/core/src/frozen.rs @@ -102,8 +102,7 @@ impl FrozenLib> { /// Encode the given iterator of frozen modules into a compressed vector of bytes pub fn encode<'a, I, B: AsRef<[u8]>>(lib: I) -> FrozenLib> where - I: IntoIterator)>, - I::IntoIter: ExactSizeIterator + Clone, + I: IntoIterator), IntoIter: ExactSizeIterator + Clone>, { let iter = lib.into_iter(); let mut bytes = Vec::new(); diff --git a/vm/src/builtins/dict.rs b/vm/src/builtins/dict.rs index 0fa2e18c3..68567e493 100644 --- a/vm/src/builtins/dict.rs +++ b/vm/src/builtins/dict.rs @@ -728,11 +728,8 @@ impl ExactSizeIterator for DictIter<'_> { } #[pyclass] -trait DictView: PyPayload + PyClassDef + Iterable + Representable -where - Self::ReverseIter: PyPayload, -{ - type ReverseIter; +trait DictView: PyPayload + PyClassDef + Iterable + Representable { + type ReverseIter: PyPayload; fn dict(&self) -> &PyDictRef; fn item(vm: &VirtualMachine, key: PyObjectRef, value: PyObjectRef) -> PyObjectRef; diff --git a/vm/src/function/builtin.rs b/vm/src/function/builtin.rs index 41e04d252..bf9a5ed34 100644 --- a/vm/src/function/builtin.rs +++ b/vm/src/function/builtin.rs @@ -55,19 +55,14 @@ const fn zst_ref_out_of_thin_air(x: T) -> &'static T { // would never get called anyway if we consider this semantically a Box::leak(Box::new(x))-type // operation. if T isn't zero-sized, we don't have to worry about it because we'll fail to compile. std::mem::forget(x); - trait Zst: Sized + 'static { - const THIN_AIR: &'static Self = { - if std::mem::size_of::() == 0 { - // SAFETY: we just confirmed that Self is zero-sized, so we can - // pull a value of it out of thin air. - unsafe { std::ptr::NonNull::::dangling().as_ref() } - } else { - panic!("can't use a non-zero-sized type here") - } - }; + const { + if std::mem::size_of::() != 0 { + panic!("can't use a non-zero-sized type here") + } + // SAFETY: we just confirmed that T is zero-sized, so we can + // pull a value of it out of thin air. + unsafe { std::ptr::NonNull::::dangling().as_ref() } } - impl Zst for T {} - ::THIN_AIR } /// Get the [`STATIC_FUNC`](IntoPyNativeFn::STATIC_FUNC) of the passed function. The same diff --git a/vm/src/intern.rs b/vm/src/intern.rs index 1f6fb09f2..45bd45d96 100644 --- a/vm/src/intern.rs +++ b/vm/src/intern.rs @@ -228,12 +228,8 @@ mod sealed { } /// A sealed marker trait for `DictKey` types that always become an exact instance of `str` -pub trait InternableString -where - Self: sealed::SealedInternable + ToPyObject + AsRef, - Self::Interned: MaybeInternedString, -{ - type Interned: ?Sized; +pub trait InternableString: sealed::SealedInternable + ToPyObject + AsRef { + type Interned: MaybeInternedString + ?Sized; fn into_pyref_exact(self, str_type: PyTypeRef) -> PyRefExact; } diff --git a/vm/src/object/traverse_object.rs b/vm/src/object/traverse_object.rs index b7476c849..b690b80f7 100644 --- a/vm/src/object/traverse_object.rs +++ b/vm/src/object/traverse_object.rs @@ -1,4 +1,4 @@ -use std::{fmt, marker::PhantomData}; +use std::fmt; use crate::{ object::{ @@ -16,25 +16,18 @@ pub(in crate::object) struct PyObjVTable { } impl PyObjVTable { - pub fn of() -> &'static Self { - struct Helper(PhantomData); - trait VtableHelper { - const VTABLE: PyObjVTable; + pub const fn of() -> &'static Self { + &PyObjVTable { + drop_dealloc: drop_dealloc_obj::, + debug: debug_obj::, + trace: const { + if T::IS_TRACE { + Some(try_trace_obj::) + } else { + None + } + }, } - impl VtableHelper for Helper { - const VTABLE: PyObjVTable = PyObjVTable { - drop_dealloc: drop_dealloc_obj::, - debug: debug_obj::, - trace: { - if T::IS_TRACE { - Some(try_trace_obj::) - } else { - None - } - }, - }; - } - &Helper::::VTABLE } } diff --git a/vm/src/vm/mod.rs b/vm/src/vm/mod.rs index 1a5f40e76..295e599b7 100644 --- a/vm/src/vm/mod.rs +++ b/vm/src/vm/mod.rs @@ -133,13 +133,10 @@ impl VirtualMachine { let import_func = ctx.none(); let profile_func = RefCell::new(ctx.none()); let trace_func = RefCell::new(ctx.none()); - // hack to get around const array repeat expressions, rust issue #79270 - const NONE: Option = None; - // putting it in a const optimizes better, prevents linear initialization of the array - #[allow(clippy::declare_interior_mutable_const)] - const SIGNAL_HANDLERS: RefCell<[Option; signal::NSIG]> = - RefCell::new([NONE; signal::NSIG]); - let signal_handlers = Some(Box::new(SIGNAL_HANDLERS)); + let signal_handlers = Some(Box::new( + // putting it in a const optimizes better, prevents linear initialization of the array + const { RefCell::new([const { None }; signal::NSIG]) }, + )); let module_inits = stdlib::get_module_inits(); From c883f0ad8af76a981eaca511fa2c3e334117dbad Mon Sep 17 00:00:00 2001 From: Noa Date: Thu, 17 Oct 2024 16:31:41 -0500 Subject: [PATCH 3/5] Updates for Rust 1.82 --- Cargo.toml | 2 +- common/src/boxvec.rs | 25 +++---------------------- common/src/lock/cell_lock.rs | 6 +++--- stdlib/src/grp.rs | 2 +- stdlib/src/select.rs | 2 +- stdlib/src/socket.rs | 2 +- stdlib/src/sqlite.rs | 12 ++++-------- vm/src/object/core.rs | 4 ++-- vm/src/stdlib/pwd.rs | 2 +- 9 files changed, 17 insertions(+), 40 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6e90643ef..35ff85758 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -105,7 +105,7 @@ members = [ version = "0.4.0" authors = ["RustPython Team"] edition = "2021" -rust-version = "1.80.0" +rust-version = "1.82.0" repository = "https://github.com/RustPython/RustPython" license = "MIT" diff --git a/common/src/boxvec.rs b/common/src/boxvec.rs index ca81b7510..50f9ab271 100644 --- a/common/src/boxvec.rs +++ b/common/src/boxvec.rs @@ -1,7 +1,6 @@ //! An unresizable vector backed by a `Box<[T]>` use std::{ - alloc, borrow::{Borrow, BorrowMut}, cmp, fmt, mem::{self, MaybeUninit}, @@ -35,29 +34,11 @@ macro_rules! panic_oob { }; } -fn capacity_overflow() -> ! { - panic!("capacity overflow") -} - impl BoxVec { pub fn new(n: usize) -> BoxVec { - unsafe { - let layout = match alloc::Layout::array::(n) { - Ok(l) => l, - Err(_) => capacity_overflow(), - }; - let ptr = if mem::size_of::() == 0 { - ptr::NonNull::>::dangling().as_ptr() - } else { - let ptr = alloc::alloc(layout); - if ptr.is_null() { - alloc::handle_alloc_error(layout) - } - ptr as *mut MaybeUninit - }; - let ptr = ptr::slice_from_raw_parts_mut(ptr, n); - let xs = Box::from_raw(ptr); - BoxVec { xs, len: 0 } + BoxVec { + xs: Box::new_uninit_slice(n), + len: 0, } } diff --git a/common/src/lock/cell_lock.rs b/common/src/lock/cell_lock.rs index 5c31fcdbb..b10101f26 100644 --- a/common/src/lock/cell_lock.rs +++ b/common/src/lock/cell_lock.rs @@ -2,7 +2,7 @@ use lock_api::{ GetThreadId, RawMutex, RawRwLock, RawRwLockDowngrade, RawRwLockRecursive, RawRwLockUpgrade, RawRwLockUpgradeDowngrade, }; -use std::{cell::Cell, num::NonZeroUsize}; +use std::{cell::Cell, num::NonZero}; pub struct RawCellMutex { locked: Cell, @@ -203,7 +203,7 @@ fn deadlock(lock_kind: &str, ty: &str) -> ! { pub struct SingleThreadId(()); unsafe impl GetThreadId for SingleThreadId { const INIT: Self = SingleThreadId(()); - fn nonzero_thread_id(&self) -> NonZeroUsize { - NonZeroUsize::new(1).unwrap() + fn nonzero_thread_id(&self) -> NonZero { + NonZero::new(1).unwrap() } } diff --git a/stdlib/src/grp.rs b/stdlib/src/grp.rs index 959c984be..d3eb0848b 100644 --- a/stdlib/src/grp.rs +++ b/stdlib/src/grp.rs @@ -83,7 +83,7 @@ mod grp { #[pyfunction] fn getgrall(vm: &VirtualMachine) -> PyResult> { // setgrent, getgrent, etc are not thread safe. Could use fgetgrent_r, but this is easier - static GETGRALL: parking_lot::Mutex<()> = parking_lot::const_mutex(()); + static GETGRALL: parking_lot::Mutex<()> = parking_lot::Mutex::new(()); let _guard = GETGRALL.lock(); let mut list = Vec::new(); diff --git a/stdlib/src/select.rs b/stdlib/src/select.rs index 0e367bc35..af76d86c8 100644 --- a/stdlib/src/select.rs +++ b/stdlib/src/select.rs @@ -36,7 +36,7 @@ mod platform { // based off winsock2.h: https://gist.github.com/piscisaureus/906386#file-winsock2-h-L128-L141 pub unsafe fn FD_SET(fd: RawFd, set: *mut fd_set) { - let mut slot = std::ptr::addr_of_mut!((*set).fd_array).cast::(); + let mut slot = (&raw mut (*set).fd_array).cast::(); let fd_count = (*set).fd_count; for _ in 0..fd_count { if *slot == fd { diff --git a/stdlib/src/socket.rs b/stdlib/src/socket.rs index 864586685..bf2f5ecd3 100644 --- a/stdlib/src/socket.rs +++ b/stdlib/src/socket.rs @@ -2217,7 +2217,7 @@ mod _socket { fn as_slice(&self) -> &[netioapi::MIB_IF_ROW2] { unsafe { let p = self.ptr.as_ptr(); - let ptr = ptr::addr_of!((*p).Table) as *const netioapi::MIB_IF_ROW2; + let ptr = &raw const (*p).Table as *const netioapi::MIB_IF_ROW2; std::slice::from_raw_parts(ptr, (*p).NumEntries as usize) } } diff --git a/stdlib/src/sqlite.rs b/stdlib/src/sqlite.rs index e24b7e475..c47bc6420 100644 --- a/stdlib/src/sqlite.rs +++ b/stdlib/src/sqlite.rs @@ -76,7 +76,7 @@ mod _sqlite { ffi::{c_int, c_longlong, c_uint, c_void, CStr}, fmt::Debug, ops::Deref, - ptr::{addr_of_mut, null, null_mut}, + ptr::{null, null_mut}, thread::ThreadId, }; @@ -1178,14 +1178,10 @@ mod _sqlite { ) }; - // TODO: replace with Result.inspect_err when stable - if let Err(exc) = db.check(ret, vm) { + db.check(ret, vm).inspect_err(|_| { // create_collation do not call destructor if error occur let _ = unsafe { Box::from_raw(data) }; - Err(exc) - } else { - Ok(()) - } + }) } #[pymethod] @@ -2396,7 +2392,7 @@ mod _sqlite { let ret = unsafe { sqlite3_open_v2( path, - addr_of_mut!(db), + &raw mut db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | if uri { SQLITE_OPEN_URI } else { 0 }, diff --git a/vm/src/object/core.rs b/vm/src/object/core.rs index 6a8166b20..b32693546 100644 --- a/vm/src/object/core.rs +++ b/vm/src/object/core.rs @@ -322,7 +322,7 @@ unsafe impl Link for WeakLink { #[inline(always)] unsafe fn pointers(target: NonNull) -> NonNull> { - NonNull::new_unchecked(ptr::addr_of_mut!((*target.as_ptr()).0.payload.pointers)) + NonNull::new_unchecked(&raw mut (*target.as_ptr()).0.payload.pointers) } } @@ -1047,7 +1047,7 @@ impl PyRef { pub fn leak(pyref: Self) -> &'static Py { let ptr = pyref.ptr; std::mem::forget(pyref); - unsafe { &*ptr.as_ptr() } + unsafe { ptr.as_ref() } } } diff --git a/vm/src/stdlib/pwd.rs b/vm/src/stdlib/pwd.rs index f5d1e50a2..0edca9c0a 100644 --- a/vm/src/stdlib/pwd.rs +++ b/vm/src/stdlib/pwd.rs @@ -92,7 +92,7 @@ mod pwd { #[pyfunction] fn getpwall(vm: &VirtualMachine) -> PyResult> { // setpwent, getpwent, etc are not thread safe. Could use fgetpwent_r, but this is easier - static GETPWALL: parking_lot::Mutex<()> = parking_lot::const_mutex(()); + static GETPWALL: parking_lot::Mutex<()> = parking_lot::Mutex::new(()); let _guard = GETPWALL.lock(); let mut list = Vec::new(); From 8ac7e34be268da5add6ff670150419cdf5acd3f1 Mon Sep 17 00:00:00 2001 From: Noa Date: Tue, 3 Dec 2024 17:05:24 -0600 Subject: [PATCH 4/5] Updates for Rust 1.83 --- .github/workflows/ci.yaml | 8 ++++---- Cargo.toml | 2 +- README.md | 8 ++++---- common/src/boxvec.rs | 2 ++ common/src/linked_list.rs | 2 +- common/src/lock/immutable_mutex.rs | 2 ++ common/src/lock/thread_mutex.rs | 2 ++ common/src/str.rs | 4 +--- jit/src/lib.rs | 2 +- stdlib/src/posixsubprocess.rs | 2 +- vm/src/object/ext.rs | 8 ++++---- vm/src/ospath.rs | 2 +- vm/src/protocol/iter.rs | 4 ++-- vm/src/protocol/number.rs | 2 +- vm/src/recursion.rs | 2 +- vm/src/stdlib/codecs.rs | 2 +- vm/sre_engine/src/engine.rs | 2 +- vm/sre_engine/src/string.rs | 2 +- wapm.toml | 2 +- 19 files changed, 32 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e05f3efd6..f60bddabe 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -407,7 +407,7 @@ jobs: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable with: - target: wasm32-wasi + target: wasm32-wasip1 - uses: Swatinem/rust-cache@v2 - name: Setup Wasmer @@ -415,8 +415,8 @@ jobs: - name: Install clang run: sudo apt-get update && sudo apt-get install clang -y - name: build rustpython - run: cargo build --release --target wasm32-wasi --features freeze-stdlib,stdlib --verbose + run: cargo build --release --target wasm32-wasip1 --features freeze-stdlib,stdlib --verbose - name: run snippets - run: wasmer run --dir `pwd` target/wasm32-wasi/release/rustpython.wasm -- `pwd`/extra_tests/snippets/stdlib_random.py + run: wasmer run --dir `pwd` target/wasm32-wasip1/release/rustpython.wasm -- `pwd`/extra_tests/snippets/stdlib_random.py - name: run cpython unittest - run: wasmer run --dir `pwd` target/wasm32-wasi/release/rustpython.wasm -- `pwd`/Lib/test/test_int.py + run: wasmer run --dir `pwd` target/wasm32-wasip1/release/rustpython.wasm -- `pwd`/Lib/test/test_int.py diff --git a/Cargo.toml b/Cargo.toml index 35ff85758..e2dc581ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -105,7 +105,7 @@ members = [ version = "0.4.0" authors = ["RustPython Team"] edition = "2021" -rust-version = "1.82.0" +rust-version = "1.83.0" repository = "https://github.com/RustPython/RustPython" license = "MIT" diff --git a/README.md b/README.md index 96e201ac1..903e829b9 100644 --- a/README.md +++ b/README.md @@ -91,13 +91,13 @@ You can compile RustPython to a standalone WebAssembly WASI module so it can run Build ```bash -cargo build --target wasm32-wasi --no-default-features --features freeze-stdlib,stdlib --release +cargo build --target wasm32-wasip1 --no-default-features --features freeze-stdlib,stdlib --release ``` Run by wasmer ```bash -wasmer run --dir `pwd` -- target/wasm32-wasi/release/rustpython.wasm `pwd`/extra_tests/snippets/stdlib_random.py +wasmer run --dir `pwd` -- target/wasm32-wasip1/release/rustpython.wasm `pwd`/extra_tests/snippets/stdlib_random.py ``` Run by wapm @@ -114,10 +114,10 @@ $ wapm run rustpython You can build the WebAssembly WASI file with: ```bash -cargo build --release --target wasm32-wasi --features="freeze-stdlib" +cargo build --release --target wasm32-wasip1 --features="freeze-stdlib" ``` -> Note: we use the `freeze-stdlib` to include the standard library inside the binary. You also have to run once `rustup target add wasm32-wasi`. +> Note: we use the `freeze-stdlib` to include the standard library inside the binary. You also have to run once `rustup target add wasm32-wasip1`. ### JIT (Just in time) compiler diff --git a/common/src/boxvec.rs b/common/src/boxvec.rs index 50f9ab271..40856c672 100644 --- a/common/src/boxvec.rs +++ b/common/src/boxvec.rs @@ -1,5 +1,7 @@ //! An unresizable vector backed by a `Box<[T]>` +#![allow(clippy::needless_lifetimes)] + use std::{ borrow::{Borrow, BorrowMut}, cmp, fmt, diff --git a/common/src/linked_list.rs b/common/src/linked_list.rs index 3941d2c83..3040bab0b 100644 --- a/common/src/linked_list.rs +++ b/common/src/linked_list.rs @@ -293,7 +293,7 @@ impl LinkedList { } } -impl<'a, T, F> Iterator for DrainFilter<'a, T, F> +impl Iterator for DrainFilter<'_, T, F> where T: Link, F: FnMut(&mut T::Target) -> bool, diff --git a/common/src/lock/immutable_mutex.rs b/common/src/lock/immutable_mutex.rs index 3f5eba787..3001cc757 100644 --- a/common/src/lock/immutable_mutex.rs +++ b/common/src/lock/immutable_mutex.rs @@ -1,3 +1,5 @@ +#![allow(clippy::needless_lifetimes)] + use lock_api::{MutexGuard, RawMutex}; use std::{fmt, marker::PhantomData, ops::Deref}; diff --git a/common/src/lock/thread_mutex.rs b/common/src/lock/thread_mutex.rs index 1a5054264..a1e1ee8be 100644 --- a/common/src/lock/thread_mutex.rs +++ b/common/src/lock/thread_mutex.rs @@ -1,3 +1,5 @@ +#![allow(clippy::needless_lifetimes)] + use lock_api::{GetThreadId, GuardNoSend, RawMutex}; use std::{ cell::UnsafeCell, diff --git a/common/src/str.rs b/common/src/str.rs index 1606ebc07..3f9bf583b 100644 --- a/common/src/str.rs +++ b/common/src/str.rs @@ -334,9 +334,7 @@ macro_rules! ascii { ($x:expr $(,)?) => {{ let s = const { let s: &str = $x; - if !s.is_ascii() { - panic!("ascii!() argument is not an ascii string"); - } + assert!(s.is_ascii(), "ascii!() argument is not an ascii string"); s }; unsafe { $crate::vendored::ascii::AsciiStr::from_ascii_unchecked(s.as_bytes()) } diff --git a/jit/src/lib.rs b/jit/src/lib.rs index d982ce439..1d099635e 100644 --- a/jit/src/lib.rs +++ b/jit/src/lib.rs @@ -341,7 +341,7 @@ pub struct Args<'a> { code: &'a CompiledCode, } -impl<'a> Args<'a> { +impl Args<'_> { pub fn invoke(&self) -> Option { unsafe { self.code.invoke_raw(&self.cif_args) } } diff --git a/stdlib/src/posixsubprocess.rs b/stdlib/src/posixsubprocess.rs index 47e19d317..64e897b60 100644 --- a/stdlib/src/posixsubprocess.rs +++ b/stdlib/src/posixsubprocess.rs @@ -113,7 +113,7 @@ struct CharPtrSlice<'a> { slice: [*const libc::c_char], } -impl<'a> CharPtrSlice<'a> { +impl CharPtrSlice<'_> { fn as_ptr(&self) -> *const *const libc::c_char { self.slice.as_ptr() } diff --git a/vm/src/object/ext.rs b/vm/src/object/ext.rs index ec8b59bda..f7247bc5e 100644 --- a/vm/src/object/ext.rs +++ b/vm/src/object/ext.rs @@ -500,21 +500,21 @@ pub struct PyLease<'a, T: PyObjectPayload> { inner: PyRwLockReadGuard<'a, PyRef>, } -impl<'a, T: PyObjectPayload + PyPayload> PyLease<'a, T> { +impl PyLease<'_, T> { #[inline(always)] pub fn into_owned(self) -> PyRef { self.inner.clone() } } -impl<'a, T: PyObjectPayload + PyPayload> Borrow for PyLease<'a, T> { +impl Borrow for PyLease<'_, T> { #[inline(always)] fn borrow(&self) -> &PyObject { self.inner.as_ref() } } -impl<'a, T: PyObjectPayload + PyPayload> Deref for PyLease<'a, T> { +impl Deref for PyLease<'_, T> { type Target = PyRef; #[inline(always)] fn deref(&self) -> &Self::Target { @@ -522,7 +522,7 @@ impl<'a, T: PyObjectPayload + PyPayload> Deref for PyLease<'a, T> { } } -impl<'a, T> fmt::Display for PyLease<'a, T> +impl fmt::Display for PyLease<'_, T> where T: PyPayload + fmt::Display, { diff --git a/vm/src/ospath.rs b/vm/src/ospath.rs index ac574339f..fe26f227d 100644 --- a/vm/src/ospath.rs +++ b/vm/src/ospath.rs @@ -179,7 +179,7 @@ impl<'a> IOErrorBuilder<'a> { } } -impl<'a> ToPyException for IOErrorBuilder<'a> { +impl ToPyException for IOErrorBuilder<'_> { fn to_pyexception(&self, vm: &VirtualMachine) -> PyBaseExceptionRef { let excp = self.error.to_pyexception(vm); diff --git a/vm/src/protocol/iter.rs b/vm/src/protocol/iter.rs index 36952916c..d9c49ed15 100644 --- a/vm/src/protocol/iter.rs +++ b/vm/src/protocol/iter.rs @@ -229,7 +229,7 @@ where _phantom: std::marker::PhantomData, } -unsafe impl<'a, T, O> Traverse for PyIterIter<'a, T, O> +unsafe impl Traverse for PyIterIter<'_, T, O> where O: Traverse + Borrow, { @@ -252,7 +252,7 @@ where } } -impl<'a, T, O> Iterator for PyIterIter<'a, T, O> +impl Iterator for PyIterIter<'_, T, O> where T: TryFromObject, O: Borrow, diff --git a/vm/src/protocol/number.rs b/vm/src/protocol/number.rs index 92636dc11..01829bb55 100644 --- a/vm/src/protocol/number.rs +++ b/vm/src/protocol/number.rs @@ -432,7 +432,7 @@ unsafe impl Traverse for PyNumber<'_> { } } -impl<'a> Deref for PyNumber<'a> { +impl Deref for PyNumber<'_> { type Target = PyObject; fn deref(&self) -> &Self::Target { diff --git a/vm/src/recursion.rs b/vm/src/recursion.rs index c7b75e588..7392cca4d 100644 --- a/vm/src/recursion.rs +++ b/vm/src/recursion.rs @@ -23,7 +23,7 @@ impl<'vm> ReprGuard<'vm> { } } -impl<'vm> Drop for ReprGuard<'vm> { +impl Drop for ReprGuard<'_> { fn drop(&mut self) { self.vm.repr_guards.borrow_mut().remove(&self.id); } diff --git a/vm/src/stdlib/codecs.rs b/vm/src/stdlib/codecs.rs index b4051d5c4..71317bf48 100644 --- a/vm/src/stdlib/codecs.rs +++ b/vm/src/stdlib/codecs.rs @@ -107,7 +107,7 @@ mod _codecs { PyStr::is_ascii(self) } } - impl<'vm> encodings::ErrorHandler for ErrorsHandler<'vm> { + impl encodings::ErrorHandler for ErrorsHandler<'_> { type Error = PyBaseExceptionRef; type StrBuf = PyStrRef; type BytesBuf = PyBytesRef; diff --git a/vm/sre_engine/src/engine.rs b/vm/sre_engine/src/engine.rs index ca269c73d..77f4ccdf3 100644 --- a/vm/sre_engine/src/engine.rs +++ b/vm/sre_engine/src/engine.rs @@ -236,7 +236,7 @@ pub struct SearchIter<'a, S: StrDrive> { pub state: State, } -impl<'a, S: StrDrive> Iterator for SearchIter<'a, S> { +impl Iterator for SearchIter<'_, S> { type Item = (); fn next(&mut self) -> Option { diff --git a/vm/sre_engine/src/string.rs b/vm/sre_engine/src/string.rs index e3f14ef01..ca8b3179d 100644 --- a/vm/sre_engine/src/string.rs +++ b/vm/sre_engine/src/string.rs @@ -25,7 +25,7 @@ pub trait StrDrive: Copy { fn back_skip(cursor: &mut StringCursor, n: usize); } -impl<'a> StrDrive for &'a [u8] { +impl StrDrive for &[u8] { #[inline] fn count(&self) -> usize { self.len() diff --git a/wapm.toml b/wapm.toml index 07f07a3b0..22d8f1816 100644 --- a/wapm.toml +++ b/wapm.toml @@ -8,7 +8,7 @@ repository = "https://github.com/RustPython/RustPython" [[module]] name = "rustpython" -source = "target/wasm32-wasi/release/rustpython.wasm" +source = "target/wasm32-wasip1/release/rustpython.wasm" abi = "wasi" [[command]] From 8c7bfb3e1a6bd65d683efae1f8e8357e2f55d41b Mon Sep 17 00:00:00 2001 From: Noa Date: Mon, 6 Jan 2025 12:54:04 -0600 Subject: [PATCH 5/5] Fix redox --- .github/workflows/ci.yaml | 1 + common/src/lib.rs | 2 +- stdlib/src/lib.rs | 1 + vm/src/lib.rs | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f60bddabe..f45c1c0dc 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -229,6 +229,7 @@ jobs: uses: coolreader18/redoxer-action@v1 with: command: check + args: --ignore-rust-version snippets_cpython: if: ${{ !contains(github.event.pull_request.labels.*.name, 'skip:ci') }} diff --git a/common/src/lib.rs b/common/src/lib.rs index 25501e4f5..cf2286c1c 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -1,6 +1,6 @@ //! A crate to hold types and functions common to all rustpython components. -#![cfg_attr(target_os = "redox", feature(byte_slice_trim_ascii))] +#![cfg_attr(target_os = "redox", feature(byte_slice_trim_ascii, new_uninit))] #[macro_use] mod macros; diff --git a/stdlib/src/lib.rs b/stdlib/src/lib.rs index a910c5854..33eb114f0 100644 --- a/stdlib/src/lib.rs +++ b/stdlib/src/lib.rs @@ -1,6 +1,7 @@ // to allow `mod foo {}` in foo.rs; clippy thinks this is a mistake/misunderstanding of // how `mod` works, but we want this sometimes for pymodule declarations #![allow(clippy::module_inception)] +#![cfg_attr(target_os = "redox", feature(raw_ref_op))] #[macro_use] extern crate rustpython_derive; diff --git a/vm/src/lib.rs b/vm/src/lib.rs index cb2e77327..93adaa13f 100644 --- a/vm/src/lib.rs +++ b/vm/src/lib.rs @@ -13,6 +13,7 @@ #![allow(clippy::upper_case_acronyms)] #![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/main/logo.png")] #![doc(html_root_url = "https://docs.rs/rustpython-vm/")] +#![cfg_attr(target_os = "redox", feature(raw_ref_op))] #[cfg(feature = "flame-it")] #[macro_use]