From ce70c24d17b6dd675e881c95ddf0325afdc21153 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Fri, 31 Jul 2026 18:00:38 +0100 Subject: [PATCH] clippy: fix ptr_as_ptr lint https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr --- Cargo.toml | 3 + crates/edit/Cargo.toml | 3 + crates/edit/src/helpers.rs | 4 +- crates/edit/src/icu.rs | 6 +- crates/edit/src/simd/lines_bwd.rs | 30 +++++----- crates/edit/src/simd/lines_fwd.rs | 30 +++++----- crates/edit/src/simd/memchr2.rs | 6 +- crates/edit/src/sys/unix.rs | 2 +- crates/edit/src/sys/windows.rs | 6 +- crates/lsh-bin/Cargo.toml | 3 + crates/lsh/Cargo.toml | 3 + crates/lsh/src/runtime.rs | 12 ++-- crates/stdext/Cargo.toml | 3 + crates/stdext/src/collections/vec.rs | 4 +- crates/stdext/src/simd/memset.rs | 88 ++++++++++++++-------------- crates/stdext/src/sys/windows.rs | 4 +- crates/unicode-gen/Cargo.toml | 3 + 17 files changed, 114 insertions(+), 96 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7bd88a805d2..c88d46406e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,3 +31,6 @@ edit = { path = "./crates/edit" } lsh = { path = "./crates/lsh" } stdext = { path = "./crates/stdext" } unicode-gen = { path = "./crates/unicode-gen" } + +[workspace.lints.clippy] +ptr_as_ptr = "warn" diff --git a/crates/edit/Cargo.toml b/crates/edit/Cargo.toml index 02becfdb908..e75500c14d1 100644 --- a/crates/edit/Cargo.toml +++ b/crates/edit/Cargo.toml @@ -50,3 +50,6 @@ features = [ [dev-dependencies] criterion = { version = "0.8", features = ["html_reports"] } zstd = { version = "0.13", default-features = false } + +[lints] +workspace = true diff --git a/crates/edit/src/helpers.rs b/crates/edit/src/helpers.rs index e85b62f7dc6..d6b030a0171 100644 --- a/crates/edit/src/helpers.rs +++ b/crates/edit/src/helpers.rs @@ -6,7 +6,7 @@ use std::cmp::Ordering; use std::io::{self, Read}; use std::mem::MaybeUninit; -use std::{fmt, slice}; +use std::{fmt, ptr, slice}; pub const KILO: usize = 1000; pub const MEGA: usize = 1000 * 1000; @@ -59,7 +59,7 @@ impl Point { pub const MAX: Self = Self { x: CoordType::MAX, y: CoordType::MAX }; pub fn as_array(&mut self) -> &mut [CoordType; 2] { - unsafe { &mut *(self as *mut Self as *mut [CoordType; 2]) } + unsafe { &mut *ptr::from_mut(self).cast() } } } diff --git a/crates/edit/src/icu.rs b/crates/edit/src/icu.rs index bb50ef44fbf..c27c4f01377 100644 --- a/crates/edit/src/icu.rs +++ b/crates/edit/src/icu.rs @@ -7,7 +7,7 @@ use std::cmp::Ordering; use std::ffi::{CStr, c_char}; use std::mem::MaybeUninit; use std::ops::Range; -use std::ptr::{null, null_mut}; +use std::ptr::{self, null, null_mut}; use std::sync::OnceLock; use std::{fmt, mem}; @@ -348,7 +348,7 @@ impl Text { let ut = unsafe { &mut *ptr }; ut.p_funcs = &FUNCS; - ut.context = tb as *const TextBuffer as *mut _; + ut.context = ptr::from_ref(tb).cast_mut().cast(); ut.a = -1; Ok(Self(ut)) @@ -356,7 +356,7 @@ impl Text { } fn text_buffer_from_utext<'a>(ut: &icu_ffi::UText) -> &'a TextBuffer { - unsafe { &*(ut.context as *const TextBuffer) } + unsafe { &*(ut.context.cast()) } } fn double_cache_from_utext<'a>(ut: &icu_ffi::UText) -> &'a mut DoubleCache { diff --git a/crates/edit/src/simd/lines_bwd.rs b/crates/edit/src/simd/lines_bwd.rs index 37a016906f9..0c00dfce19d 100644 --- a/crates/edit/src/simd/lines_bwd.rs +++ b/crates/edit/src/simd/lines_bwd.rs @@ -117,10 +117,10 @@ unsafe fn lines_bwd_avx2( while end.offset_from_unsigned(beg) >= 128 { let chunk_start = end.sub(128); - let v1 = _mm256_loadu_si256(chunk_start.add(0) as *const _); - let v2 = _mm256_loadu_si256(chunk_start.add(32) as *const _); - let v3 = _mm256_loadu_si256(chunk_start.add(64) as *const _); - let v4 = _mm256_loadu_si256(chunk_start.add(96) as *const _); + let v1 = _mm256_loadu_si256(chunk_start.add(0).cast()); + let v2 = _mm256_loadu_si256(chunk_start.add(32).cast()); + let v3 = _mm256_loadu_si256(chunk_start.add(64).cast()); + let v4 = _mm256_loadu_si256(chunk_start.add(96).cast()); let mut sum = _mm256_setzero_si256(); sum = _mm256_sub_epi8(sum, _mm256_cmpeq_epi8(v1, lf)); @@ -142,7 +142,7 @@ unsafe fn lines_bwd_avx2( while end.offset_from_unsigned(beg) >= 32 { let chunk_start = end.sub(32); - let v = _mm256_loadu_si256(chunk_start as *const _); + let v = _mm256_loadu_si256(chunk_start.cast()); let c = _mm256_cmpeq_epi8(v, lf); let ones = _mm256_and_si256(c, _mm256_set1_epi8(0x01)); @@ -216,10 +216,10 @@ unsafe fn lines_bwd_lasx( while end.offset_from_unsigned(beg) >= 128 { let chunk_start = end.sub(128); - let v1 = lasx_xvld::<0>(chunk_start as *const _); - let v2 = lasx_xvld::<32>(chunk_start as *const _); - let v3 = lasx_xvld::<64>(chunk_start as *const _); - let v4 = lasx_xvld::<96>(chunk_start as *const _); + let v1 = lasx_xvld::<0>(chunk_start.cast()); + let v2 = lasx_xvld::<32>(chunk_start.cast()); + let v3 = lasx_xvld::<64>(chunk_start.cast()); + let v4 = lasx_xvld::<96>(chunk_start.cast()); let mut sum = lasx_xvneg_b(lasx_xvseqi_b::(v1)); sum = lasx_xvsub_b(sum, lasx_xvseqi_b::(v2)); @@ -238,7 +238,7 @@ unsafe fn lines_bwd_lasx( while end.offset_from_unsigned(beg) >= 32 { let chunk_start = end.sub(32); - let v = lasx_xvld::<0>(chunk_start as *const _); + let v = lasx_xvld::<0>(chunk_start.cast()); let c = lasx_xvseqi_b::(v); let ones = lasx_xvandi_b::<1>(c); @@ -289,10 +289,10 @@ unsafe fn lines_bwd_lsx( while end.offset_from_unsigned(beg) >= 64 { let chunk_start = end.sub(64); - let v1 = lsx_vld::<0>(chunk_start as *const _); - let v2 = lsx_vld::<16>(chunk_start as *const _); - let v3 = lsx_vld::<32>(chunk_start as *const _); - let v4 = lsx_vld::<48>(chunk_start as *const _); + let v1 = lsx_vld::<0>(chunk_start.cast()); + let v2 = lsx_vld::<16>(chunk_start.cast()); + let v3 = lsx_vld::<32>(chunk_start.cast()); + let v4 = lsx_vld::<48>(chunk_start.cast()); let mut sum = lsx_vneg_b(lsx_vseqi_b::(v1)); sum = lsx_vsub_b(sum, lsx_vseqi_b::(v2)); @@ -311,7 +311,7 @@ unsafe fn lines_bwd_lsx( while end.offset_from_unsigned(beg) >= 16 { let chunk_start = end.sub(16); - let v = lsx_vld::<0>(chunk_start as *const _); + let v = lsx_vld::<0>(chunk_start.cast()); let c = lsx_vseqi_b::(v); let ones = lsx_vandi_b::<1>(c); diff --git a/crates/edit/src/simd/lines_fwd.rs b/crates/edit/src/simd/lines_fwd.rs index c05d827d8d3..1346f421ee4 100644 --- a/crates/edit/src/simd/lines_fwd.rs +++ b/crates/edit/src/simd/lines_fwd.rs @@ -118,10 +118,10 @@ unsafe fn lines_fwd_avx2( // Unrolling the loop by 4x speeds things up by >3x. // It allows us to accumulate matches before doing a single `vpsadbw`. while end.offset_from_unsigned(beg) >= 128 { - let v1 = _mm256_loadu_si256(beg.add(0) as *const _); - let v2 = _mm256_loadu_si256(beg.add(32) as *const _); - let v3 = _mm256_loadu_si256(beg.add(64) as *const _); - let v4 = _mm256_loadu_si256(beg.add(96) as *const _); + let v1 = _mm256_loadu_si256(beg.add(0).cast()); + let v2 = _mm256_loadu_si256(beg.add(32).cast()); + let v3 = _mm256_loadu_si256(beg.add(64).cast()); + let v4 = _mm256_loadu_si256(beg.add(96).cast()); // `vpcmpeqb` leaves each comparison result byte as 0 or -1 (0xff). // This allows us to accumulate the comparisons by subtracting them. @@ -145,7 +145,7 @@ unsafe fn lines_fwd_avx2( } while end.offset_from_unsigned(beg) >= 32 { - let v = _mm256_loadu_si256(beg as *const _); + let v = _mm256_loadu_si256(beg.cast()); let c = _mm256_cmpeq_epi8(v, lf); // If you ask an LLM, the best way to do this is @@ -221,10 +221,10 @@ unsafe fn lines_fwd_lasx( if line < line_stop { while end.offset_from_unsigned(beg) >= 128 { - let v1 = lasx_xvld::<0>(beg as *const _); - let v2 = lasx_xvld::<32>(beg as *const _); - let v3 = lasx_xvld::<64>(beg as *const _); - let v4 = lasx_xvld::<96>(beg as *const _); + let v1 = lasx_xvld::<0>(beg.cast()); + let v2 = lasx_xvld::<32>(beg.cast()); + let v3 = lasx_xvld::<64>(beg.cast()); + let v4 = lasx_xvld::<96>(beg.cast()); let mut sum = lasx_xvneg_b(lasx_xvseqi_b::(v1)); sum = lasx_xvsub_b(sum, lasx_xvseqi_b::(v2)); @@ -242,7 +242,7 @@ unsafe fn lines_fwd_lasx( } while end.offset_from_unsigned(beg) >= 32 { - let v = lasx_xvld::<0>(beg as *const _); + let v = lasx_xvld::<0>(beg.cast()); let c = lasx_xvseqi_b::(v); let ones = lasx_xvandi_b::<1>(c); @@ -292,10 +292,10 @@ unsafe fn lines_fwd_lsx( if line < line_stop { while end.offset_from_unsigned(beg) >= 64 { - let v1 = lsx_vld::<0>(beg as *const _); - let v2 = lsx_vld::<16>(beg as *const _); - let v3 = lsx_vld::<32>(beg as *const _); - let v4 = lsx_vld::<48>(beg as *const _); + let v1 = lsx_vld::<0>(beg.cast()); + let v2 = lsx_vld::<16>(beg.cast()); + let v3 = lsx_vld::<32>(beg.cast()); + let v4 = lsx_vld::<48>(beg.cast()); let mut sum = lsx_vneg_b(lsx_vseqi_b::(v1)); sum = lsx_vsub_b(sum, lsx_vseqi_b::(v2)); @@ -313,7 +313,7 @@ unsafe fn lines_fwd_lsx( } while end.offset_from_unsigned(beg) >= 16 { - let v = lsx_vld::<0>(beg as *const _); + let v = lsx_vld::<0>(beg.cast()); let c = lsx_vseqi_b::(v); let ones = lsx_vandi_b::<1>(c); diff --git a/crates/edit/src/simd/memchr2.rs b/crates/edit/src/simd/memchr2.rs index f6e83d1ad05..bb79fffc754 100644 --- a/crates/edit/src/simd/memchr2.rs +++ b/crates/edit/src/simd/memchr2.rs @@ -86,7 +86,7 @@ unsafe fn memchr2_avx2(needle1: u8, needle2: u8, mut beg: *const u8, end: *const let mut remaining = end.offset_from_unsigned(beg); while remaining >= 32 { - let v = _mm256_loadu_si256(beg as *const _); + let v = _mm256_loadu_si256(beg.cast()); let a = _mm256_cmpeq_epi8(v, n1); let b = _mm256_cmpeq_epi8(v, n2); let c = _mm256_or_si256(a, b); @@ -134,7 +134,7 @@ unsafe fn memchr2_lasx(needle1: u8, needle2: u8, mut beg: *const u8, end: *const } while end.offset_from_unsigned(beg) >= 32 { - let v = lasx_xvld::<0>(beg as *const _); + let v = lasx_xvld::<0>(beg.cast()); let a = lasx_xvseq_b(v, n1); let b = lasx_xvseq_b(v, n2); let c = lasx_xvor_v(a, b); @@ -169,7 +169,7 @@ unsafe fn memchr2_lsx(needle1: u8, needle2: u8, mut beg: *const u8, end: *const } while end.offset_from_unsigned(beg) >= 16 { - let v = lsx_vld::<0>(beg as *const _); + let v = lsx_vld::<0>(beg.cast()); let a = lsx_vseq_b(v, n1); let b = lsx_vseq_b(v, n2); let c = lsx_vor_v(a, b); diff --git a/crates/edit/src/sys/unix.rs b/crates/edit/src/sys/unix.rs index 1d51fa6f3d0..570ec51a001 100644 --- a/crates/edit/src/sys/unix.rs +++ b/crates/edit/src/sys/unix.rs @@ -507,7 +507,7 @@ where res.push_str(arena, name); res.push_str(arena, suffix); res.push(arena, '\0'); - res.as_ptr() as *const c_char + res.as_ptr().cast() } } diff --git a/crates/edit/src/sys/windows.rs b/crates/edit/src/sys/windows.rs index 98a100835d6..575efcb3c35 100644 --- a/crates/edit/src/sys/windows.rs +++ b/crates/edit/src/sys/windows.rs @@ -397,7 +397,7 @@ pub fn read_stdin(arena: &Arena, mut timeout: time::Duration) -> Option io::Result { check_bool_return(FileSystem::GetFileInformationByHandleEx( file.as_raw_handle(), FileSystem::FileIdInfo, - info.as_mut_ptr() as *mut _, + info.as_mut_ptr().cast(), mem::size_of::() as u32, ))?; Ok(FileId::Id(info.assume_init())) @@ -538,7 +538,7 @@ unsafe fn load_library(name: *const u16) -> io::Result> { // It'd be nice to constrain T to std::marker::FnPtr, but that's unstable. pub unsafe fn get_proc_address(handle: NonNull, name: *const c_char) -> io::Result { unsafe { - let ptr = LibraryLoader::GetProcAddress(handle.as_ptr(), name as *const u8); + let ptr = LibraryLoader::GetProcAddress(handle.as_ptr(), name.cast()); if let Some(ptr) = ptr { Ok(mem::transmute_copy(&ptr)) } else { Err(last_os_error()) } } } diff --git a/crates/lsh-bin/Cargo.toml b/crates/lsh-bin/Cargo.toml index 8601fe1960e..8f44ac36735 100644 --- a/crates/lsh-bin/Cargo.toml +++ b/crates/lsh-bin/Cargo.toml @@ -12,3 +12,6 @@ anyhow = "*" argh = "*" lsh.workspace = true stdext.workspace = true + +[lints] +workspace = true diff --git a/crates/lsh/Cargo.toml b/crates/lsh/Cargo.toml index c079ef797f4..68693605b02 100644 --- a/crates/lsh/Cargo.toml +++ b/crates/lsh/Cargo.toml @@ -9,3 +9,6 @@ rust-version.workspace = true [dependencies] stdext.workspace = true + +[lints] +workspace = true diff --git a/crates/lsh/src/runtime.rs b/crates/lsh/src/runtime.rs index e9e767786a2..66db3a7e75b 100644 --- a/crates/lsh/src/runtime.rs +++ b/crates/lsh/src/runtime.rs @@ -23,7 +23,7 @@ //! as used by the backend's relocation system. use std::fmt::{self, Debug}; -use std::mem; +use std::{mem, ptr}; use stdext::arena::Arena; use stdext::arena_write_fmt; @@ -474,13 +474,13 @@ impl Registers { } #[inline(always)] - unsafe fn as_ptr(&self) -> *const u32 { - self as *const _ as *const u32 + fn as_ptr(&self) -> *const u32 { + ptr::from_ref(self).cast() } #[inline(always)] - unsafe fn as_mut_ptr(&mut self) -> *mut u32 { - self as *mut _ as *mut u32 + fn as_mut_ptr(&mut self) -> *mut u32 { + ptr::from_mut(self).cast() } } @@ -570,7 +570,7 @@ macro_rules! instruction_decode { #[inline(always)] fn dec_u32(bytes: &[u8], off: usize) -> u32 { debug_assert!(off + 4 <= bytes.len()); - unsafe { (bytes.as_ptr().add(off) as *const u32).read_unaligned() } + unsafe { (bytes.as_ptr().add(off).cast::()).read_unaligned() } } let __asm: &[u8] = $assembly; diff --git a/crates/stdext/Cargo.toml b/crates/stdext/Cargo.toml index 8feec1485fd..2b8e3f5d5a2 100644 --- a/crates/stdext/Cargo.toml +++ b/crates/stdext/Cargo.toml @@ -12,3 +12,6 @@ single-threaded = [] [target.'cfg(unix)'.dependencies] libc = "0.2" + +[lints] +workspace = true diff --git a/crates/stdext/src/collections/vec.rs b/crates/stdext/src/collections/vec.rs index 1c8c8abc629..b3a2dbd7e39 100644 --- a/crates/stdext/src/collections/vec.rs +++ b/crates/stdext/src/collections/vec.rs @@ -376,7 +376,7 @@ impl<'a, T: Copy> BVec<'a, T> { let dst = self.spare_mut_ptr(); let src = self.ptr.as_ptr().add(beg); self.len += add; - ptr::copy_nonoverlapping(src as *const _, dst, add); + ptr::copy_nonoverlapping(src.cast(), dst, add); } } @@ -455,7 +455,7 @@ impl<'a> BVec<'a, u16> { // MultiByteToWideChar is ~2x faster than the UTF8 loop below and saves space. #[cfg(windows)] unsafe { - let dst = self.spare_mut_ptr() as *mut u16; + let dst = self.spare_mut_ptr().cast(); let len = MultiByteToWideChar( 65001, 0, diff --git a/crates/stdext/src/simd/memset.rs b/crates/stdext/src/simd/memset.rs index 15d921220f3..a8c2bb4b762 100644 --- a/crates/stdext/src/simd/memset.rs +++ b/crates/stdext/src/simd/memset.rs @@ -113,8 +113,8 @@ unsafe fn memset_sse2(mut beg: *mut u8, end: *mut u8, val: u64) { let fill = _mm_set1_epi64x(val as i64); while remaining >= 32 { - _mm_storeu_si128(beg as *mut _, fill); - _mm_storeu_si128(beg.add(16) as *mut _, fill); + _mm_storeu_si128(beg.cast(), fill); + _mm_storeu_si128(beg.add(16).cast(), fill); beg = beg.add(32); remaining -= 32; @@ -122,24 +122,24 @@ unsafe fn memset_sse2(mut beg: *mut u8, end: *mut u8, val: u64) { if remaining >= 16 { // 16-31 bytes remaining - _mm_storeu_si128(beg as *mut _, fill); - _mm_storeu_si128(end.sub(16) as *mut _, fill); + _mm_storeu_si128(beg.cast(), fill); + _mm_storeu_si128(end.sub(16).cast(), fill); return; } } if remaining >= 8 { // 8-15 bytes remaining - (beg as *mut u64).write_unaligned(val); - (end.sub(8) as *mut u64).write_unaligned(val); + beg.cast::().write_unaligned(val); + end.sub(8).cast::().write_unaligned(val); } else if remaining >= 4 { // 4-7 bytes remaining - (beg as *mut u32).write_unaligned(val as u32); - (end.sub(4) as *mut u32).write_unaligned(val as u32); + beg.cast::().write_unaligned(val as u32); + end.sub(4).cast::().write_unaligned(val as u32); } else if remaining >= 2 { // 2-3 bytes remaining - (beg as *mut u16).write_unaligned(val as u16); - (end.sub(2) as *mut u16).write_unaligned(val as u16); + beg.cast::().write_unaligned(val as u16); + end.sub(2).cast::().write_unaligned(val as u16); } else if remaining >= 1 { // 1 byte remaining beg.write(val as u8); @@ -163,10 +163,10 @@ fn memset_avx2(mut beg: *mut u8, end: *mut u8, val: u64) { let fill = _mm256_set1_epi64x(val as i64); loop { - _mm256_storeu_si256(beg as *mut _, fill); - _mm256_storeu_si256(beg.add(32) as *mut _, fill); - _mm256_storeu_si256(beg.add(64) as *mut _, fill); - _mm256_storeu_si256(beg.add(96) as *mut _, fill); + _mm256_storeu_si256(beg.cast(), fill); + _mm256_storeu_si256(beg.add(32).cast(), fill); + _mm256_storeu_si256(beg.add(64).cast(), fill); + _mm256_storeu_si256(beg.add(96).cast(), fill); beg = beg.add(128); remaining -= 128; @@ -183,7 +183,7 @@ fn memset_avx2(mut beg: *mut u8, end: *mut u8, val: u64) { // LLVM is _very_ eager to unroll loops. In the absence of an unroll attribute, black_box does the job. // Note that this must not be applied to the intrinsic parameters, as they're otherwise misoptimized. #[allow(clippy::unit_arg)] - black_box(_mm_storeu_si128(beg as *mut _, fill)); + black_box(_mm_storeu_si128(beg.cast(), fill)); beg = beg.add(16); remaining -= 16; @@ -198,16 +198,16 @@ fn memset_avx2(mut beg: *mut u8, end: *mut u8, val: u64) { // can be seen in various libraries, such as wyhash which uses it for loading data in `wyr3`. if remaining >= 8 { // 8-15 bytes - (beg as *mut u64).write_unaligned(val); - (end.sub(8) as *mut u64).write_unaligned(val); + beg.cast::().write_unaligned(val); + end.sub(8).cast::().write_unaligned(val); } else if remaining >= 4 { // 4-7 bytes - (beg as *mut u32).write_unaligned(val as u32); - (end.sub(4) as *mut u32).write_unaligned(val as u32); + beg.cast::().write_unaligned(val as u32); + end.sub(4).cast::().write_unaligned(val as u32); } else if remaining >= 2 { // 2-3 bytes - (beg as *mut u16).write_unaligned(val as u16); - (end.sub(2) as *mut u16).write_unaligned(val as u16); + beg.cast::().write_unaligned(val as u16); + end.sub(2).cast::().write_unaligned(val as u16); } else if remaining >= 1 { // 1 byte beg.write(val as u8); @@ -239,17 +239,17 @@ fn memset_lasx(mut beg: *mut u8, end: *mut u8, val: u64) { let fill = lasx_xvreplgr2vr_d(val as i64); if end.offset_from_unsigned(beg) >= 32 { - lasx_xvst::<0>(fill, beg as *mut _); + lasx_xvst::<0>(fill, beg.cast()); let off = beg.align_offset(32); beg = beg.add(off); } if end.offset_from_unsigned(beg) >= 128 { loop { - lasx_xvst::<0>(fill, beg as *mut _); - lasx_xvst::<32>(fill, beg as *mut _); - lasx_xvst::<64>(fill, beg as *mut _); - lasx_xvst::<96>(fill, beg as *mut _); + lasx_xvst::<0>(fill, beg.cast()); + lasx_xvst::<32>(fill, beg.cast()); + lasx_xvst::<64>(fill, beg.cast()); + lasx_xvst::<96>(fill, beg.cast()); beg = beg.add(128); if end.offset_from_unsigned(beg) < 128 { @@ -262,7 +262,7 @@ fn memset_lasx(mut beg: *mut u8, end: *mut u8, val: u64) { let fill = lsx_vreplgr2vr_d(val as i64); loop { - lsx_vst::<0>(fill, beg as *mut _); + lsx_vst::<0>(fill, beg.cast()); beg = beg.add(16); if end.offset_from_unsigned(beg) < 16 { @@ -273,16 +273,16 @@ fn memset_lasx(mut beg: *mut u8, end: *mut u8, val: u64) { if end.offset_from_unsigned(beg) >= 8 { // 8-15 bytes - (beg as *mut u64).write_unaligned(val); - (end.sub(8) as *mut u64).write_unaligned(val); + beg.cast::().write_unaligned(val); + end.sub(8).cast::().write_unaligned(val); } else if end.offset_from_unsigned(beg) >= 4 { // 4-7 bytes - (beg as *mut u32).write_unaligned(val as u32); - (end.sub(4) as *mut u32).write_unaligned(val as u32); + beg.cast::().write_unaligned(val as u32); + end.sub(4).cast::().write_unaligned(val as u32); } else if end.offset_from_unsigned(beg) >= 2 { // 2-3 bytes - (beg as *mut u16).write_unaligned(val as u16); - (end.sub(2) as *mut u16).write_unaligned(val as u16); + beg.cast::().write_unaligned(val as u16); + end.sub(2).cast::().write_unaligned(val as u16); } else if end.offset_from_unsigned(beg) >= 1 { // 1 byte beg.write(val as u8); @@ -299,37 +299,37 @@ unsafe fn memset_lsx(mut beg: *mut u8, end: *mut u8, val: u64) { if end.offset_from_unsigned(beg) >= 16 { let fill = lsx_vreplgr2vr_d(val as i64); - lsx_vst::<0>(fill, beg as *mut _); + lsx_vst::<0>(fill, beg.cast()); let off = beg.align_offset(16); beg = beg.add(off); while end.offset_from_unsigned(beg) >= 32 { - lsx_vst::<0>(fill, beg as *mut _); - lsx_vst::<16>(fill, beg as *mut _); + lsx_vst::<0>(fill, beg.cast()); + lsx_vst::<16>(fill, beg.cast()); beg = beg.add(32); } if end.offset_from_unsigned(beg) >= 16 { // 16-31 bytes remaining - lsx_vst::<0>(fill, beg as *mut _); - lsx_vst::<-16>(fill, end as *mut _); + lsx_vst::<0>(fill, beg.cast()); + lsx_vst::<-16>(fill, end.cast()); return; } } if end.offset_from_unsigned(beg) >= 8 { // 8-15 bytes remaining - (beg as *mut u64).write_unaligned(val); - (end.sub(8) as *mut u64).write_unaligned(val); + beg.cast::().write_unaligned(val); + end.sub(8).cast::().write_unaligned(val); } else if end.offset_from_unsigned(beg) >= 4 { // 4-7 bytes remaining - (beg as *mut u32).write_unaligned(val as u32); - (end.sub(4) as *mut u32).write_unaligned(val as u32); + beg.cast::().write_unaligned(val as u32); + end.sub(4).cast::().write_unaligned(val as u32); } else if end.offset_from_unsigned(beg) >= 2 { // 2-3 bytes remaining - (beg as *mut u16).write_unaligned(val as u16); - (end.sub(2) as *mut u16).write_unaligned(val as u16); + beg.cast::().write_unaligned(val as u16); + end.sub(2).cast::().write_unaligned(val as u16); } else if end.offset_from_unsigned(beg) >= 1 { // 1 byte remaining beg.write(val as u8); diff --git a/crates/stdext/src/sys/windows.rs b/crates/stdext/src/sys/windows.rs index 59282bec9ff..041c5c783fa 100644 --- a/crates/stdext/src/sys/windows.rs +++ b/crates/stdext/src/sys/windows.rs @@ -48,7 +48,7 @@ pub unsafe fn virtual_release(base: NonNull, _size: usize) { unsafe { // NOTE: `VirtualFree` fails if the pointer isn't // a valid base address or if the size isn't zero. - VirtualFree(base.as_ptr() as *mut _, 0, MEM_RELEASE); + VirtualFree(base.as_ptr(), 0, MEM_RELEASE); } } @@ -61,7 +61,7 @@ pub unsafe fn virtual_release(base: NonNull, _size: usize) { /// and to pass a size less than or equal to the size passed to [`virtual_reserve`]. pub unsafe fn virtual_commit(base: NonNull, size: usize) -> io::Result<()> { unsafe { - let res = VirtualAlloc(base.as_ptr() as *mut _, size, MEM_COMMIT, PAGE_READWRITE); + let res = VirtualAlloc(base.as_ptr(), size, MEM_COMMIT, PAGE_READWRITE); if res.is_null() { Err(io::Error::last_os_error()) } else { Ok(()) } } } diff --git a/crates/unicode-gen/Cargo.toml b/crates/unicode-gen/Cargo.toml index c8dde6b0c95..d18b6d59850 100644 --- a/crates/unicode-gen/Cargo.toml +++ b/crates/unicode-gen/Cargo.toml @@ -14,3 +14,6 @@ indoc = "2.0" pico-args = { version = "0.5", features = ["eq-separator"] } rayon = "1.10" roxmltree = { version = "0.21", default-features = false, features = ["std"] } + +[lints] +workspace = true