Unnamed repository; edit this file 'description' to name the repository.
Auto merge of #17690 - lnicola:unsafe_op_in_unsafe_fn, r=lnicola
internal: Fix and enable unsafe_op_in_unsafe_fn Closes #17689
bors 2024-07-25
parent eeb192b · parent b392eb4 · commit 62a7468
-rw-r--r--.github/workflows/ci.yaml2
-rw-r--r--Cargo.toml6
-rw-r--r--crates/salsa/src/intern_id.rs3
-rw-r--r--crates/stdx/src/anymap.rs4
-rw-r--r--crates/stdx/src/process.rs18
-rw-r--r--lib/line-index/src/lib.rs26
6 files changed, 29 insertions, 30 deletions
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 87a1729d2b..6d3e488bb0 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -15,7 +15,7 @@ env:
CARGO_NET_RETRY: 10
CI: 1
RUST_BACKTRACE: short
- RUSTFLAGS: "-D warnings -W unreachable-pub -W bare-trait-objects"
+ RUSTFLAGS: "-D warnings -D elided_lifetimes_in_paths -D explicit_outlives_requirements -D unsafe_op_in_unsafe_fn -D unused_extern_crates -D unused_lifetimes -D unreachable_pub"
RUSTUP_MAX_RETRIES: 10
jobs:
diff --git a/Cargo.toml b/Cargo.toml
index 428d11ad60..c2f601a91b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -163,14 +163,14 @@ xshell = "0.2.5"
dashmap = { version = "=5.5.3", features = ["raw-api"] }
[workspace.lints.rust]
-bare_trait_objects = "warn"
+# remember to update RUSTFLAGS in ci.yml if you add something here
+
elided_lifetimes_in_paths = "warn"
-ellipsis_inclusive_range_patterns = "warn"
explicit_outlives_requirements = "warn"
+unsafe_op_in_unsafe_fn = "warn"
unused_extern_crates = "warn"
unused_lifetimes = "warn"
unreachable_pub = "warn"
-semicolon_in_expressions_from_macros = "warn"
[workspace.lints.clippy]
# FIXME Remove the tidy test once the lint table is stable
diff --git a/crates/salsa/src/intern_id.rs b/crates/salsa/src/intern_id.rs
index b060d8aab6..8e74c100ac 100644
--- a/crates/salsa/src/intern_id.rs
+++ b/crates/salsa/src/intern_id.rs
@@ -63,7 +63,8 @@ impl InternId {
/// `value` must be less than `MAX`
pub const unsafe fn new_unchecked(value: u32) -> Self {
debug_assert!(value < InternId::MAX);
- InternId { value: NonZeroU32::new_unchecked(value + 1) }
+ let value = unsafe { NonZeroU32::new_unchecked(value + 1) };
+ InternId { value }
}
/// Convert this raw-id into a u32 value.
diff --git a/crates/stdx/src/anymap.rs b/crates/stdx/src/anymap.rs
index 4eafcfb060..91fab8e923 100644
--- a/crates/stdx/src/anymap.rs
+++ b/crates/stdx/src/anymap.rs
@@ -271,12 +271,12 @@ macro_rules! implement {
#[inline]
unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T {
- &*(self as *const Self as *const T)
+ unsafe { &*(self as *const Self as *const T) }
}
#[inline]
unsafe fn downcast_mut_unchecked<T: 'static>(&mut self) -> &mut T {
- &mut *(self as *mut Self as *mut T)
+ unsafe { &mut *(self as *mut Self as *mut T) }
}
}
diff --git a/crates/stdx/src/process.rs b/crates/stdx/src/process.rs
index c54d850d7b..75ae064db9 100644
--- a/crates/stdx/src/process.rs
+++ b/crates/stdx/src/process.rs
@@ -212,17 +212,13 @@ mod imp {
impl<'a> Pipe<'a> {
unsafe fn new<P: IntoRawHandle>(p: P, dst: &'a mut Vec<u8>) -> Pipe<'a> {
- Pipe {
- dst,
- pipe: NamedPipe::from_raw_handle(p.into_raw_handle()),
- overlapped: Overlapped::zero(),
- done: false,
- }
+ let pipe = unsafe { NamedPipe::from_raw_handle(p.into_raw_handle()) };
+ Pipe { dst, pipe, overlapped: Overlapped::zero(), done: false }
}
unsafe fn read(&mut self) -> io::Result<()> {
- let dst = slice_to_end(self.dst);
- match self.pipe.read_overlapped(dst, self.overlapped.raw()) {
+ let dst = unsafe { slice_to_end(self.dst) };
+ match unsafe { self.pipe.read_overlapped(dst, self.overlapped.raw()) } {
Ok(_) => Ok(()),
Err(e) => {
if e.raw_os_error() == Some(ERROR_BROKEN_PIPE as i32) {
@@ -237,7 +233,7 @@ mod imp {
unsafe fn complete(&mut self, status: &CompletionStatus) {
let prev = self.dst.len();
- self.dst.set_len(prev + status.bytes_transferred() as usize);
+ unsafe { self.dst.set_len(prev + status.bytes_transferred() as usize) };
if status.bytes_transferred() == 0 {
self.done = true;
}
@@ -251,7 +247,9 @@ mod imp {
if v.capacity() == v.len() {
v.reserve(1);
}
- slice::from_raw_parts_mut(v.as_mut_ptr().add(v.len()), v.capacity() - v.len())
+ let data = unsafe { v.as_mut_ptr().add(v.len()) };
+ let len = v.capacity() - v.len();
+ unsafe { slice::from_raw_parts_mut(data, len) }
}
}
diff --git a/lib/line-index/src/lib.rs b/lib/line-index/src/lib.rs
index 1ab62e9923..66875e2524 100644
--- a/lib/line-index/src/lib.rs
+++ b/lib/line-index/src/lib.rs
@@ -275,21 +275,21 @@ unsafe fn analyze_source_file_sse2(
let ptr = src_bytes.as_ptr() as *const __m128i;
// We don't know if the pointer is aligned to 16 bytes, so we
// use `loadu`, which supports unaligned loading.
- let chunk = _mm_loadu_si128(ptr.add(chunk_index));
+ let chunk = unsafe { _mm_loadu_si128(ptr.add(chunk_index)) };
// For character in the chunk, see if its byte value is < 0, which
// indicates that it's part of a UTF-8 char.
- let multibyte_test = _mm_cmplt_epi8(chunk, _mm_set1_epi8(0));
+ let multibyte_test = unsafe { _mm_cmplt_epi8(chunk, _mm_set1_epi8(0)) };
// Create a bit mask from the comparison results.
- let multibyte_mask = _mm_movemask_epi8(multibyte_test);
+ let multibyte_mask = unsafe { _mm_movemask_epi8(multibyte_test) };
// If the bit mask is all zero, we only have ASCII chars here:
if multibyte_mask == 0 {
assert!(intra_chunk_offset == 0);
// Check for newlines in the chunk
- let newlines_test = _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8));
- let newlines_mask = _mm_movemask_epi8(newlines_test);
+ let newlines_test = unsafe { _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8)) };
+ let newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) };
if newlines_mask != 0 {
// All control characters are newlines, record them
@@ -349,8 +349,8 @@ unsafe fn analyze_source_file_sse2(
unsafe fn move_mask(v: std::arch::aarch64::uint8x16_t) -> u64 {
use std::arch::aarch64::*;
- let nibble_mask = vshrn_n_u16(vreinterpretq_u16_u8(v), 4);
- vget_lane_u64(vreinterpret_u64_u8(nibble_mask), 0)
+ let nibble_mask = unsafe { vshrn_n_u16(vreinterpretq_u16_u8(v), 4) };
+ unsafe { vget_lane_u64(vreinterpret_u64_u8(nibble_mask), 0) }
}
#[target_feature(enable = "neon")]
@@ -368,7 +368,7 @@ unsafe fn analyze_source_file_neon(
let chunk_count = src.len() / CHUNK_SIZE;
- let newline = vdupq_n_s8(b'\n' as i8);
+ let newline = unsafe { vdupq_n_s8(b'\n' as i8) };
// This variable keeps track of where we should start decoding a
// chunk. If a multi-byte character spans across chunk boundaries,
@@ -378,21 +378,21 @@ unsafe fn analyze_source_file_neon(
for chunk_index in 0..chunk_count {
let ptr = src_bytes.as_ptr() as *const i8;
- let chunk = vld1q_s8(ptr.add(chunk_index * CHUNK_SIZE));
+ let chunk = unsafe { vld1q_s8(ptr.add(chunk_index * CHUNK_SIZE)) };
// For character in the chunk, see if its byte value is < 0, which
// indicates that it's part of a UTF-8 char.
- let multibyte_test = vcltzq_s8(chunk);
+ let multibyte_test = unsafe { vcltzq_s8(chunk) };
// Create a bit mask from the comparison results.
- let multibyte_mask = move_mask(multibyte_test);
+ let multibyte_mask = unsafe { move_mask(multibyte_test) };
// If the bit mask is all zero, we only have ASCII chars here:
if multibyte_mask == 0 {
assert!(intra_chunk_offset == 0);
// Check for newlines in the chunk
- let newlines_test = vceqq_s8(chunk, newline);
- let mut newlines_mask = move_mask(newlines_test);
+ let newlines_test = unsafe { vceqq_s8(chunk, newline) };
+ let mut newlines_mask = unsafe { move_mask(newlines_test) };
// If the bit mask is not all zero, there are newlines in this chunk.
if newlines_mask != 0 {