Skip to content

Commit 27b44a0

Browse files
ehussgitbot
authored and
gitbot
committed
core: Apply unsafe_op_in_unsafe_fn
1 parent 220f426 commit 27b44a0

File tree

8 files changed

+15
-15
lines changed

8 files changed

+15
-15
lines changed

core/src/alloc/global.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ use crate::{cmp, ptr};
7070
/// {
7171
/// return null_mut();
7272
/// };
73-
/// self.arena.get().cast::<u8>().add(allocated)
73+
/// unsafe { self.arena.get().cast::<u8>().add(allocated) }
7474
/// }
7575
/// unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {}
7676
/// }

core/src/hint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use crate::{intrinsics, ub_checks};
5252
/// // Safety: `divisor` can't be zero because of `prepare_inputs`,
5353
/// // but the compiler does not know about this. We *promise*
5454
/// // that we always call `prepare_inputs`.
55-
/// std::hint::unreachable_unchecked()
55+
/// unsafe { std::hint::unreachable_unchecked() }
5656
/// }
5757
/// // The compiler would normally introduce a check here that prevents
5858
/// // a division by zero. However, if `divisor` was zero, the branch

core/src/intrinsics/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1703,12 +1703,12 @@ pub const fn forget<T: ?Sized>(_: T) {
17031703
/// ```
17041704
/// struct R<'a>(&'a i32);
17051705
/// unsafe fn extend_lifetime<'b>(r: R<'b>) -> R<'static> {
1706-
/// std::mem::transmute::<R<'b>, R<'static>>(r)
1706+
/// unsafe { std::mem::transmute::<R<'b>, R<'static>>(r) }
17071707
/// }
17081708
///
17091709
/// unsafe fn shorten_invariant_lifetime<'b, 'c>(r: &'b mut R<'static>)
17101710
/// -> &'b mut R<'c> {
1711-
/// std::mem::transmute::<&'b mut R<'static>, &'b mut R<'c>>(r)
1711+
/// unsafe { std::mem::transmute::<&'b mut R<'static>, &'b mut R<'c>>(r) }
17121712
/// }
17131713
/// ```
17141714
///
@@ -4498,11 +4498,11 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
44984498
///
44994499
/// // SAFETY: Our precondition ensures the source is aligned and valid,
45004500
/// // and `Vec::with_capacity` ensures that we have usable space to write them.
4501-
/// ptr::copy(ptr, dst.as_mut_ptr(), elts);
4501+
/// unsafe { ptr::copy(ptr, dst.as_mut_ptr(), elts); }
45024502
///
45034503
/// // SAFETY: We created it with this much capacity earlier,
45044504
/// // and the previous `copy` has initialized these elements.
4505-
/// dst.set_len(elts);
4505+
/// unsafe { dst.set_len(elts); }
45064506
/// dst
45074507
/// }
45084508
/// ```

core/src/mem/maybe_uninit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ use crate::{fmt, intrinsics, ptr, slice};
9898
///
9999
/// unsafe fn make_vec(out: *mut Vec<i32>) {
100100
/// // `write` does not drop the old contents, which is important.
101-
/// out.write(vec![1, 2, 3]);
101+
/// unsafe { out.write(vec![1, 2, 3]); }
102102
/// }
103103
///
104104
/// let mut v = MaybeUninit::uninit();
@@ -844,7 +844,7 @@ impl<T> MaybeUninit<T> {
844844
/// # #![allow(unexpected_cfgs)]
845845
/// use std::mem::MaybeUninit;
846846
///
847-
/// # unsafe extern "C" fn initialize_buffer(buf: *mut [u8; 1024]) { *buf = [0; 1024] }
847+
/// # unsafe extern "C" fn initialize_buffer(buf: *mut [u8; 1024]) { unsafe { *buf = [0; 1024] } }
848848
/// # #[cfg(FALSE)]
849849
/// extern "C" {
850850
/// /// Initializes *all* the bytes of the input buffer.

core/src/mem/transmutability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::marker::{ConstParamTy_, UnsizedConstParamTy};
3232
/// src: ManuallyDrop::new(src),
3333
/// };
3434
///
35-
/// let dst = transmute.dst;
35+
/// let dst = unsafe { transmute.dst };
3636
///
3737
/// ManuallyDrop::into_inner(dst)
3838
/// }

core/src/ptr/const_ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -724,13 +724,13 @@ impl<T: ?Sized> *const T {
724724
/// that their safety preconditions are met:
725725
/// ```rust
726726
/// # #![feature(ptr_sub_ptr)]
727-
/// # unsafe fn blah(ptr: *const i32, origin: *const i32, count: usize) -> bool {
727+
/// # unsafe fn blah(ptr: *const i32, origin: *const i32, count: usize) -> bool { unsafe {
728728
/// ptr.sub_ptr(origin) == count
729729
/// # &&
730730
/// origin.add(count) == ptr
731731
/// # &&
732732
/// ptr.sub(count) == origin
733-
/// # }
733+
/// # } }
734734
/// ```
735735
///
736736
/// # Safety

core/src/ptr/mut_ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -896,13 +896,13 @@ impl<T: ?Sized> *mut T {
896896
/// that their safety preconditions are met:
897897
/// ```rust
898898
/// # #![feature(ptr_sub_ptr)]
899-
/// # unsafe fn blah(ptr: *mut i32, origin: *mut i32, count: usize) -> bool {
899+
/// # unsafe fn blah(ptr: *mut i32, origin: *mut i32, count: usize) -> bool { unsafe {
900900
/// ptr.sub_ptr(origin) == count
901901
/// # &&
902902
/// origin.add(count) == ptr
903903
/// # &&
904904
/// ptr.sub(count) == origin
905-
/// # }
905+
/// # } }
906906
/// ```
907907
///
908908
/// # Safety

core/src/ptr/non_null.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -857,13 +857,13 @@ impl<T: ?Sized> NonNull<T> {
857857
/// that their safety preconditions are met:
858858
/// ```rust
859859
/// # #![feature(ptr_sub_ptr)]
860-
/// # unsafe fn blah(ptr: std::ptr::NonNull<u32>, origin: std::ptr::NonNull<u32>, count: usize) -> bool {
860+
/// # unsafe fn blah(ptr: std::ptr::NonNull<u32>, origin: std::ptr::NonNull<u32>, count: usize) -> bool { unsafe {
861861
/// ptr.sub_ptr(origin) == count
862862
/// # &&
863863
/// origin.add(count) == ptr
864864
/// # &&
865865
/// ptr.sub(count) == origin
866-
/// # }
866+
/// # } }
867867
/// ```
868868
///
869869
/// # Safety

0 commit comments

Comments
 (0)