Skip to content

Commit 3480bed

Browse files
committed
Auto merge of rust-lang#17690 - lnicola:unsafe_op_in_unsafe_fn, r=lnicola
internal: Fix and enable unsafe_op_in_unsafe_fn Closes rust-lang#17689
2 parents 5fd18ee + d7968e5 commit 3480bed

File tree

6 files changed

+29
-30
lines changed

6 files changed

+29
-30
lines changed

src/tools/rust-analyzer/.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ env:
1515
CARGO_NET_RETRY: 10
1616
CI: 1
1717
RUST_BACKTRACE: short
18-
RUSTFLAGS: "-D warnings -W unreachable-pub -W bare-trait-objects"
18+
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"
1919
RUSTUP_MAX_RETRIES: 10
2020

2121
jobs:

src/tools/rust-analyzer/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,14 @@ xshell = "0.2.5"
163163
dashmap = { version = "=5.5.3", features = ["raw-api"] }
164164

165165
[workspace.lints.rust]
166-
bare_trait_objects = "warn"
166+
# remember to update RUSTFLAGS in ci.yml if you add something here
167+
167168
elided_lifetimes_in_paths = "warn"
168-
ellipsis_inclusive_range_patterns = "warn"
169169
explicit_outlives_requirements = "warn"
170+
unsafe_op_in_unsafe_fn = "warn"
170171
unused_extern_crates = "warn"
171172
unused_lifetimes = "warn"
172173
unreachable_pub = "warn"
173-
semicolon_in_expressions_from_macros = "warn"
174174

175175
[workspace.lints.clippy]
176176
# FIXME Remove the tidy test once the lint table is stable

src/tools/rust-analyzer/crates/salsa/src/intern_id.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ impl InternId {
6363
/// `value` must be less than `MAX`
6464
pub const unsafe fn new_unchecked(value: u32) -> Self {
6565
debug_assert!(value < InternId::MAX);
66-
InternId { value: NonZeroU32::new_unchecked(value + 1) }
66+
let value = unsafe { NonZeroU32::new_unchecked(value + 1) };
67+
InternId { value }
6768
}
6869

6970
/// Convert this raw-id into a u32 value.

src/tools/rust-analyzer/crates/stdx/src/anymap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,12 @@ macro_rules! implement {
271271

272272
#[inline]
273273
unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T {
274-
&*(self as *const Self as *const T)
274+
unsafe { &*(self as *const Self as *const T) }
275275
}
276276

277277
#[inline]
278278
unsafe fn downcast_mut_unchecked<T: 'static>(&mut self) -> &mut T {
279-
&mut *(self as *mut Self as *mut T)
279+
unsafe { &mut *(self as *mut Self as *mut T) }
280280
}
281281
}
282282

src/tools/rust-analyzer/crates/stdx/src/process.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,13 @@ mod imp {
212212

213213
impl<'a> Pipe<'a> {
214214
unsafe fn new<P: IntoRawHandle>(p: P, dst: &'a mut Vec<u8>) -> Pipe<'a> {
215-
Pipe {
216-
dst,
217-
pipe: NamedPipe::from_raw_handle(p.into_raw_handle()),
218-
overlapped: Overlapped::zero(),
219-
done: false,
220-
}
215+
let pipe = unsafe { NamedPipe::from_raw_handle(p.into_raw_handle()) };
216+
Pipe { dst, pipe, overlapped: Overlapped::zero(), done: false }
221217
}
222218

223219
unsafe fn read(&mut self) -> io::Result<()> {
224-
let dst = slice_to_end(self.dst);
225-
match self.pipe.read_overlapped(dst, self.overlapped.raw()) {
220+
let dst = unsafe { slice_to_end(self.dst) };
221+
match unsafe { self.pipe.read_overlapped(dst, self.overlapped.raw()) } {
226222
Ok(_) => Ok(()),
227223
Err(e) => {
228224
if e.raw_os_error() == Some(ERROR_BROKEN_PIPE as i32) {
@@ -237,7 +233,7 @@ mod imp {
237233

238234
unsafe fn complete(&mut self, status: &CompletionStatus) {
239235
let prev = self.dst.len();
240-
self.dst.set_len(prev + status.bytes_transferred() as usize);
236+
unsafe { self.dst.set_len(prev + status.bytes_transferred() as usize) };
241237
if status.bytes_transferred() == 0 {
242238
self.done = true;
243239
}
@@ -251,7 +247,9 @@ mod imp {
251247
if v.capacity() == v.len() {
252248
v.reserve(1);
253249
}
254-
slice::from_raw_parts_mut(v.as_mut_ptr().add(v.len()), v.capacity() - v.len())
250+
let data = unsafe { v.as_mut_ptr().add(v.len()) };
251+
let len = v.capacity() - v.len();
252+
unsafe { slice::from_raw_parts_mut(data, len) }
255253
}
256254
}
257255

src/tools/rust-analyzer/lib/line-index/src/lib.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -275,21 +275,21 @@ unsafe fn analyze_source_file_sse2(
275275
let ptr = src_bytes.as_ptr() as *const __m128i;
276276
// We don't know if the pointer is aligned to 16 bytes, so we
277277
// use `loadu`, which supports unaligned loading.
278-
let chunk = _mm_loadu_si128(ptr.add(chunk_index));
278+
let chunk = unsafe { _mm_loadu_si128(ptr.add(chunk_index)) };
279279

280280
// For character in the chunk, see if its byte value is < 0, which
281281
// indicates that it's part of a UTF-8 char.
282-
let multibyte_test = _mm_cmplt_epi8(chunk, _mm_set1_epi8(0));
282+
let multibyte_test = unsafe { _mm_cmplt_epi8(chunk, _mm_set1_epi8(0)) };
283283
// Create a bit mask from the comparison results.
284-
let multibyte_mask = _mm_movemask_epi8(multibyte_test);
284+
let multibyte_mask = unsafe { _mm_movemask_epi8(multibyte_test) };
285285

286286
// If the bit mask is all zero, we only have ASCII chars here:
287287
if multibyte_mask == 0 {
288288
assert!(intra_chunk_offset == 0);
289289

290290
// Check for newlines in the chunk
291-
let newlines_test = _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8));
292-
let newlines_mask = _mm_movemask_epi8(newlines_test);
291+
let newlines_test = unsafe { _mm_cmpeq_epi8(chunk, _mm_set1_epi8(b'\n' as i8)) };
292+
let newlines_mask = unsafe { _mm_movemask_epi8(newlines_test) };
293293

294294
if newlines_mask != 0 {
295295
// All control characters are newlines, record them
@@ -349,8 +349,8 @@ unsafe fn analyze_source_file_sse2(
349349
unsafe fn move_mask(v: std::arch::aarch64::uint8x16_t) -> u64 {
350350
use std::arch::aarch64::*;
351351

352-
let nibble_mask = vshrn_n_u16(vreinterpretq_u16_u8(v), 4);
353-
vget_lane_u64(vreinterpret_u64_u8(nibble_mask), 0)
352+
let nibble_mask = unsafe { vshrn_n_u16(vreinterpretq_u16_u8(v), 4) };
353+
unsafe { vget_lane_u64(vreinterpret_u64_u8(nibble_mask), 0) }
354354
}
355355

356356
#[target_feature(enable = "neon")]
@@ -368,7 +368,7 @@ unsafe fn analyze_source_file_neon(
368368

369369
let chunk_count = src.len() / CHUNK_SIZE;
370370

371-
let newline = vdupq_n_s8(b'\n' as i8);
371+
let newline = unsafe { vdupq_n_s8(b'\n' as i8) };
372372

373373
// This variable keeps track of where we should start decoding a
374374
// chunk. If a multi-byte character spans across chunk boundaries,
@@ -378,21 +378,21 @@ unsafe fn analyze_source_file_neon(
378378

379379
for chunk_index in 0..chunk_count {
380380
let ptr = src_bytes.as_ptr() as *const i8;
381-
let chunk = vld1q_s8(ptr.add(chunk_index * CHUNK_SIZE));
381+
let chunk = unsafe { vld1q_s8(ptr.add(chunk_index * CHUNK_SIZE)) };
382382

383383
// For character in the chunk, see if its byte value is < 0, which
384384
// indicates that it's part of a UTF-8 char.
385-
let multibyte_test = vcltzq_s8(chunk);
385+
let multibyte_test = unsafe { vcltzq_s8(chunk) };
386386
// Create a bit mask from the comparison results.
387-
let multibyte_mask = move_mask(multibyte_test);
387+
let multibyte_mask = unsafe { move_mask(multibyte_test) };
388388

389389
// If the bit mask is all zero, we only have ASCII chars here:
390390
if multibyte_mask == 0 {
391391
assert!(intra_chunk_offset == 0);
392392

393393
// Check for newlines in the chunk
394-
let newlines_test = vceqq_s8(chunk, newline);
395-
let mut newlines_mask = move_mask(newlines_test);
394+
let newlines_test = unsafe { vceqq_s8(chunk, newline) };
395+
let mut newlines_mask = unsafe { move_mask(newlines_test) };
396396

397397
// If the bit mask is not all zero, there are newlines in this chunk.
398398
if newlines_mask != 0 {

0 commit comments

Comments
 (0)