From 63eea06a9a5c4dc74dacebfeabeed4067918fcd3 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Fri, 1 Mar 2024 10:28:17 -0700 Subject: [PATCH] chore: bump rust-toolchain (#1408) --- .github/workflows/ci.yml | 7 +-- rust-toolchain.toml | 2 +- src/function.rs | 1 - src/isolate.rs | 6 +-- src/lib.rs | 4 -- src/scope.rs | 25 ++++----- src/snapshot.rs | 4 +- src/support.rs | 2 +- src/unbound_module_script.rs | 1 - src/unbound_script.rs | 1 - src/value_serializer.rs | 6 +-- src/wasm.rs | 2 +- .../handle_scope_escape_to_nowhere.stderr | 54 +++++++++---------- .../object_without_context_scope.stderr | 26 ++++----- tests/test_api.rs | 35 ++++++------ 15 files changed, 80 insertions(+), 96 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ad9a38b..a4a979ff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,16 +67,13 @@ jobs: run: git config --global core.symlinks true - name: Clone repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 10 submodules: recursive - name: Install rust - uses: hecrj/setup-rust-action@v1 - with: - components: clippy, rustfmt - rust-version: 1.66.1 + uses: dsherret/rust-toolchain-file@v1 - name: Install python uses: actions/setup-python@v4 diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 9058c7d8..a436857e 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.71.0" +channel = "1.76.0" components = ["rustfmt", "clippy"] diff --git a/src/function.rs b/src/function.rs index 93786639..a5ca2dfc 100644 --- a/src/function.rs +++ b/src/function.rs @@ -957,7 +957,6 @@ impl Function { pub fn create_code_cache(&self) -> Option>> { let code_cache = unsafe { UniqueRef::try_from_raw(v8__Function__CreateCodeCache(self)) }; - #[cfg(debug_assertions)] if let Some(code_cache) = &code_cache { debug_assert_eq!( code_cache.buffer_policy(), diff --git a/src/isolate.rs b/src/isolate.rs index 558f024e..1645adc8 100644 --- a/src/isolate.rs +++ b/src/isolate.rs @@ -1361,6 +1361,9 @@ pub(crate) struct IsolateAnnex { isolate_mutex: Mutex<()>, } +unsafe impl Send for IsolateAnnex {} +unsafe impl Sync for IsolateAnnex {} + impl IsolateAnnex { fn new( isolate: &mut Isolate, @@ -1395,9 +1398,6 @@ impl Debug for IsolateAnnex { #[derive(Clone, Debug)] pub struct IsolateHandle(Arc); -unsafe impl Send for IsolateHandle {} -unsafe impl Sync for IsolateHandle {} - impl IsolateHandle { // This function is marked unsafe because it must be called only with either // IsolateAnnex::mutex locked, or from the main thread associated with the V8 diff --git a/src/lib.rs b/src/lib.rs index e17b398b..9bc1fb59 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -86,7 +86,6 @@ pub mod script_compiler; pub mod V8; pub use array_buffer::*; -pub use bigint::*; pub use data::*; pub use exception::*; pub use external_references::ExternalReference; @@ -124,13 +123,11 @@ pub use platform::new_single_threaded_default_platform; pub use platform::new_unprotected_default_platform; pub use platform::Platform; pub use primitives::*; -pub use private::*; pub use promise::{PromiseRejectEvent, PromiseRejectMessage, PromiseState}; pub use property_attribute::*; pub use property_descriptor::*; pub use property_filter::*; pub use property_handler_flags::*; -pub use proxy::*; pub use scope::AllowJavascriptExecutionScope; pub use scope::CallbackScope; pub use scope::ContextScope; @@ -150,7 +147,6 @@ pub use support::SharedPtr; pub use support::SharedRef; pub use support::UniquePtr; pub use support::UniqueRef; -pub use symbol::*; pub use template::*; pub use value_deserializer::ValueDeserializer; pub use value_deserializer::ValueDeserializerHelper; diff --git a/src/scope.rs b/src/scope.rs index 9be23b3c..80a18db1 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -287,12 +287,11 @@ impl<'s> HandleScope<'s> { for<'l> Local<'l, Data>: TryInto>, { unsafe { - let Some(res) = self - .cast_local(|sd| { - raw::v8__Isolate__GetDataFromSnapshotOnce(sd.get_isolate_ptr(), index) - }) else { - return Err(DataError::no_data::()); - }; + let Some(res) = self.cast_local(|sd| { + raw::v8__Isolate__GetDataFromSnapshotOnce(sd.get_isolate_ptr(), index) + }) else { + return Err(DataError::no_data::()); + }; use get_data_sealed::ToDataError; match res.try_into() { Ok(x) => Ok(x), @@ -319,12 +318,14 @@ impl<'s> HandleScope<'s> { for<'l> Local<'l, Data>: TryInto>, { unsafe { - let Some(res) = self - .cast_local(|sd| { - raw::v8__Context__GetDataFromSnapshotOnce(sd.get_current_context(), index) - }) else { - return Err(DataError::no_data::()); - }; + let Some(res) = self.cast_local(|sd| { + raw::v8__Context__GetDataFromSnapshotOnce( + sd.get_current_context(), + index, + ) + }) else { + return Err(DataError::no_data::()); + }; use get_data_sealed::ToDataError; match res.try_into() { Ok(x) => Ok(x), diff --git a/src/snapshot.rs b/src/snapshot.rs index e9c7e7a8..f2ca6270 100644 --- a/src/snapshot.rs +++ b/src/snapshot.rs @@ -66,9 +66,9 @@ impl Drop for StartupData { impl Deref for StartupData { type Target = [u8]; fn deref(&self) -> &Self::Target { - let data = self.data as *const u8; + let data = self.data; let len = usize::try_from(self.raw_size).unwrap(); - unsafe { std::slice::from_raw_parts(data, len) } + unsafe { std::slice::from_raw_parts(data as _, len) } } } diff --git a/src/support.rs b/src/support.rs index 9eef944c..fedbe444 100644 --- a/src/support.rs +++ b/src/support.rs @@ -514,7 +514,7 @@ impl Copy for FieldOffset {} impl Clone for FieldOffset { fn clone(&self) -> Self { - Self(self.0, self.1) + *self } } diff --git a/src/unbound_module_script.rs b/src/unbound_module_script.rs index d5ef9e65..f1055cec 100644 --- a/src/unbound_module_script.rs +++ b/src/unbound_module_script.rs @@ -17,7 +17,6 @@ impl UnboundModuleScript { let code_cache = unsafe { UniqueRef::try_from_raw(v8__UnboundModuleScript__CreateCodeCache(self)) }; - #[cfg(debug_assertions)] if let Some(code_cache) = &code_cache { debug_assert_eq!( code_cache.buffer_policy(), diff --git a/src/unbound_script.rs b/src/unbound_script.rs index 0c995d74..3211abe4 100644 --- a/src/unbound_script.rs +++ b/src/unbound_script.rs @@ -34,7 +34,6 @@ impl UnboundScript { let code_cache = unsafe { UniqueRef::try_from_raw(v8__UnboundScript__CreateCodeCache(self)) }; - #[cfg(debug_assertions)] if let Some(code_cache) = &code_cache { debug_assert_eq!( code_cache.buffer_policy(), diff --git a/src/value_serializer.rs b/src/value_serializer.rs index 81ce5f70..ca724fe0 100644 --- a/src/value_serializer.rs +++ b/src/value_serializer.rs @@ -488,11 +488,7 @@ impl<'a, 's> ValueSerializer<'a, 's> { &mut ptr, &mut size, ); - Vec::from_raw_parts( - ptr as *mut u8, - size, - self.value_serializer_heap.buffer_size, - ) + Vec::from_raw_parts(ptr, size, self.value_serializer_heap.buffer_size) } } diff --git a/src/wasm.rs b/src/wasm.rs index 6414d6c4..624429bf 100644 --- a/src/wasm.rs +++ b/src/wasm.rs @@ -159,7 +159,7 @@ impl CompiledWasmModule { let mut len = 0; unsafe { let ptr = v8__CompiledWasmModule__SourceUrl(self.0, &mut len); - let bytes = std::slice::from_raw_parts(ptr as *const u8, len); + let bytes = std::slice::from_raw_parts(ptr as _, len); std::str::from_utf8_unchecked(bytes) } } diff --git a/tests/compile_fail/handle_scope_escape_to_nowhere.stderr b/tests/compile_fail/handle_scope_escape_to_nowhere.stderr index d0021e1b..721e1cb2 100644 --- a/tests/compile_fail/handle_scope_escape_to_nowhere.stderr +++ b/tests/compile_fail/handle_scope_escape_to_nowhere.stderr @@ -1,24 +1,24 @@ error[E0277]: the trait bound `OwnedIsolate: v8::scope::param::NewEscapableHandleScope<'_, '_>` is not satisfied - --> tests/compile_fail/handle_scope_escape_to_nowhere.rs:5:50 - | -5 | let mut _scope = v8::EscapableHandleScope::new(&mut isolate); - | ----------------------------- ^^^^^^^^^^^^ the trait `v8::scope::param::NewEscapableHandleScope<'_, '_>` is not implemented for `OwnedIsolate` - | | - | required by a bound introduced by this call - | - = help: the following other types implement trait `v8::scope::param::NewEscapableHandleScope<'s, 'e>`: - as v8::scope::param::NewEscapableHandleScope<'s, 'e>> - as v8::scope::param::NewEscapableHandleScope<'s, 'p>> - as v8::scope::param::NewEscapableHandleScope<'s, 'e>> - as v8::scope::param::NewEscapableHandleScope<'s, 'e>> - as v8::scope::param::NewEscapableHandleScope<'s, 'p>> - as v8::scope::param::NewEscapableHandleScope<'s, 'p>> - as v8::scope::param::NewEscapableHandleScope<'s, 'e>> + --> tests/compile_fail/handle_scope_escape_to_nowhere.rs:5:50 + | +5 | let mut _scope = v8::EscapableHandleScope::new(&mut isolate); + | ----------------------------- ^^^^^^^^^^^^ the trait `v8::scope::param::NewEscapableHandleScope<'_, '_>` is not implemented for `OwnedIsolate` + | | + | required by a bound introduced by this call + | + = help: the following other types implement trait `v8::scope::param::NewEscapableHandleScope<'s, 'e>`: + as v8::scope::param::NewEscapableHandleScope<'s, 'e>> + as v8::scope::param::NewEscapableHandleScope<'s, 'p>> + as v8::scope::param::NewEscapableHandleScope<'s, 'p>> + as v8::scope::param::NewEscapableHandleScope<'s, 'e>> + as v8::scope::param::NewEscapableHandleScope<'s, 'p>> + as v8::scope::param::NewEscapableHandleScope<'s, 'e>> + as v8::scope::param::NewEscapableHandleScope<'s, 'e>> note: required by a bound in `EscapableHandleScope::<'s, 'e>::new` - --> src/scope.rs - | - | pub fn new>( - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `EscapableHandleScope::<'s, 'e>::new` + --> src/scope.rs + | + | pub fn new>( + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `EscapableHandleScope::<'s, 'e>::new` error[E0277]: the trait bound `OwnedIsolate: v8::scope::param::NewEscapableHandleScope<'_, '_>` is not satisfied --> tests/compile_fail/handle_scope_escape_to_nowhere.rs:5:20 @@ -27,13 +27,13 @@ error[E0277]: the trait bound `OwnedIsolate: v8::scope::param::NewEscapableHandl | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `v8::scope::param::NewEscapableHandleScope<'_, '_>` is not implemented for `OwnedIsolate` | = help: the following other types implement trait `v8::scope::param::NewEscapableHandleScope<'s, 'e>`: - as v8::scope::param::NewEscapableHandleScope<'s, 'e>> - as v8::scope::param::NewEscapableHandleScope<'s, 'p>> as v8::scope::param::NewEscapableHandleScope<'s, 'e>> - as v8::scope::param::NewEscapableHandleScope<'s, 'e>> - as v8::scope::param::NewEscapableHandleScope<'s, 'p>> as v8::scope::param::NewEscapableHandleScope<'s, 'p>> + as v8::scope::param::NewEscapableHandleScope<'s, 'p>> as v8::scope::param::NewEscapableHandleScope<'s, 'e>> + as v8::scope::param::NewEscapableHandleScope<'s, 'p>> + as v8::scope::param::NewEscapableHandleScope<'s, 'e>> + as v8::scope::param::NewEscapableHandleScope<'s, 'e>> error[E0277]: the trait bound `OwnedIsolate: v8::scope::param::NewEscapableHandleScope<'_, '_>` is not satisfied --> tests/compile_fail/handle_scope_escape_to_nowhere.rs:5:20 @@ -42,10 +42,10 @@ error[E0277]: the trait bound `OwnedIsolate: v8::scope::param::NewEscapableHandl | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `v8::scope::param::NewEscapableHandleScope<'_, '_>` is not implemented for `OwnedIsolate` | = help: the following other types implement trait `v8::scope::param::NewEscapableHandleScope<'s, 'e>`: - as v8::scope::param::NewEscapableHandleScope<'s, 'e>> - as v8::scope::param::NewEscapableHandleScope<'s, 'p>> as v8::scope::param::NewEscapableHandleScope<'s, 'e>> - as v8::scope::param::NewEscapableHandleScope<'s, 'e>> - as v8::scope::param::NewEscapableHandleScope<'s, 'p>> as v8::scope::param::NewEscapableHandleScope<'s, 'p>> + as v8::scope::param::NewEscapableHandleScope<'s, 'p>> as v8::scope::param::NewEscapableHandleScope<'s, 'e>> + as v8::scope::param::NewEscapableHandleScope<'s, 'p>> + as v8::scope::param::NewEscapableHandleScope<'s, 'e>> + as v8::scope::param::NewEscapableHandleScope<'s, 'e>> diff --git a/tests/compile_fail/object_without_context_scope.stderr b/tests/compile_fail/object_without_context_scope.stderr index beab06d5..f4a4f0ff 100644 --- a/tests/compile_fail/object_without_context_scope.stderr +++ b/tests/compile_fail/object_without_context_scope.stderr @@ -1,15 +1,15 @@ error[E0308]: mismatched types - --> tests/compile_fail/object_without_context_scope.rs:6:33 - | -6 | let _object = v8::Object::new(&mut scope); - | --------------- ^^^^^^^^^^ expected `&mut HandleScope<'_>`, found `&mut HandleScope<'_, ()>` - | | - | arguments to this function are incorrect - | - = note: expected mutable reference `&mut HandleScope<'_>` - found mutable reference `&mut HandleScope<'_, ()>` + --> tests/compile_fail/object_without_context_scope.rs:6:33 + | +6 | let _object = v8::Object::new(&mut scope); + | --------------- ^^^^^^^^^^ expected `&mut HandleScope<'_>`, found `&mut HandleScope<'_, ()>` + | | + | arguments to this function are incorrect + | + = note: expected mutable reference `&mut HandleScope<'_, v8::Context>` + found mutable reference `&mut HandleScope<'_, ()>` note: associated function defined here - --> src/object.rs - | - | pub fn new<'s>(scope: &mut HandleScope<'s>) -> Local<'s, Object> { - | ^^^ + --> src/object.rs + | + | pub fn new<'s>(scope: &mut HandleScope<'s>) -> Local<'s, Object> { + | ^^^ diff --git a/tests/test_api.rs b/tests/test_api.rs index 4d18880b..13746701 100644 --- a/tests/test_api.rs +++ b/tests/test_api.rs @@ -263,8 +263,7 @@ fn test_string() { assert_eq!(15, local.length()); assert_eq!(17, local.utf8_length(scope)); assert_eq!(reference, local.to_rust_string_lossy(scope)); - let mut vec = Vec::new(); - vec.resize(17, 0); + let mut vec = vec![0; 17]; let options = v8::WriteOptions::NO_NULL_TERMINATION; let mut nchars = 0; assert_eq!( @@ -705,8 +704,8 @@ fn get_isolate_from_handle() { let context = v8::Context::new(scope); let scope = &mut v8::ContextScope::new(scope, context); - check_handle(scope, None, |s| v8::null(s)); - check_handle(scope, None, |s| v8::undefined(s)); + check_handle(scope, None, v8::null); + check_handle(scope, None, v8::undefined); check_handle(scope, None, |s| v8::Boolean::new(s, true)); check_handle(scope, None, |s| v8::Boolean::new(s, false)); check_handle(scope, None, |s| v8::String::new(s, "").unwrap()); @@ -878,13 +877,13 @@ fn array_buffer() { data[0] = 1; let unique_bs = v8::ArrayBuffer::new_backing_store_from_bytes(Box::new(data)); - assert_eq!(unique_bs.get(0).unwrap().get(), 1); + assert_eq!(unique_bs.first().unwrap().get(), 1); assert_eq!(unique_bs.get(15).unwrap().get(), 100); let ab = v8::ArrayBuffer::with_backing_store(scope, &unique_bs.make_shared()); assert_eq!(ab.byte_length(), 16); - assert_eq!(ab.get_backing_store().get(0).unwrap().get(), 1); + assert_eq!(ab.get_backing_store().first().unwrap().get(), 1); } } @@ -1001,7 +1000,7 @@ fn deref_empty_backing_store() { let backing_store = v8::ArrayBuffer::new_backing_store(isolate, 0); let slice: &[std::cell::Cell] = &backing_store; - assert!(!slice.as_ptr().is_null()); + assert!(!std::hint::black_box(slice.as_ptr()).is_null()); } fn eval<'s>( @@ -4203,6 +4202,7 @@ fn promise_reject_callback_no_value() { } #[test] +#[allow(clippy::clone_on_copy)] fn promise_hook() { extern "C" fn hook( type_: v8::PromiseHookType, @@ -4210,8 +4210,8 @@ fn promise_hook() { _parent: v8::Local, ) { // Check that PromiseHookType implements Clone and PartialEq. - #[allow(clippy::clone_on_copy)] - if type_.clone() == v8::PromiseHookType::Init {} + _ = type_.clone() == v8::PromiseHookType::Init; + let scope = &mut unsafe { v8::CallbackScope::new(promise) }; let context = promise.get_creation_context(scope).unwrap(); let scope = &mut v8::ContextScope::new(scope, context); @@ -5468,8 +5468,8 @@ fn snapshot_creator_multiple_contexts() { fn external_references() { let _setup_guard = setup::sequential_test(); // Allocate externals for the test. - let external_ptr = Box::into_raw(vec![0_u8, 1, 2, 3, 4].into_boxed_slice()) - as *mut [u8] as *mut c_void; + let external_ptr = + Box::into_raw(vec![0_u8, 1, 2, 3, 4].into_boxed_slice()) as *mut c_void; // Push them to the external reference table. let refs = [ v8::ExternalReference { @@ -7683,16 +7683,13 @@ fn bigint() { let raw_b = v8::Local::::try_from(raw_b).unwrap(); - let mut vec = Vec::new(); - vec.resize(raw_b.word_count(), 0); + let mut vec = vec![0; raw_b.word_count()]; assert_eq!(raw_b.to_words_array(&mut vec), (true, &mut [10, 10][..])); - let mut vec = Vec::new(); - vec.resize(1, 0); + let mut vec = vec![0; 1]; assert_eq!(raw_b.to_words_array(&mut vec), (true, &mut [10][..])); - let mut vec = Vec::new(); - vec.resize(20, 1337); + let mut vec = vec![1337, 20]; assert_eq!(raw_b.to_words_array(&mut vec), (true, &mut [10, 10][..])); } @@ -8415,7 +8412,7 @@ fn run_with_rust_allocator() { unsafe extern "C" fn allocate(count: &AtomicUsize, n: usize) -> *mut c_void { count.fetch_add(n, Ordering::SeqCst); - Box::into_raw(vec![0u8; n].into_boxed_slice()) as *mut [u8] as *mut c_void + Box::into_raw(vec![0u8; n].into_boxed_slice()) as *mut c_void } unsafe extern "C" fn allocate_uninitialized( count: &AtomicUsize, @@ -8443,7 +8440,7 @@ fn run_with_rust_allocator() { let copy_len = oldlen.min(newlen); new_store.extend_from_slice(&old_store[..copy_len]); new_store.resize(newlen, 0u8); - Box::into_raw(new_store.into_boxed_slice()) as *mut [u8] as *mut c_void + Box::into_raw(new_store.into_boxed_slice()) as *mut c_void } unsafe extern "C" fn drop(count: *const AtomicUsize) { Arc::from_raw(count);