Skip to content

Commit c18fa46

Browse files
authored
Rollup merge of #76504 - Flying-Toast:master, r=lcnr
Capitalize safety comments
2 parents 342b406 + 2799aec commit c18fa46

File tree

19 files changed

+42
-42
lines changed

19 files changed

+42
-42
lines changed

compiler/rustc_data_structures/src/temp_dir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct MaybeTempDir {
1212

1313
impl Drop for MaybeTempDir {
1414
fn drop(&mut self) {
15-
// Safety: We are in the destructor, and no further access will
15+
// SAFETY: We are in the destructor, and no further access will
1616
// occur.
1717
let dir = unsafe { ManuallyDrop::take(&mut self.dir) };
1818
if self.keep {

library/alloc/src/alloc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl Global {
157157
}
158158
}
159159

160-
// Safety: Same as `AllocRef::grow`
160+
// SAFETY: Same as `AllocRef::grow`
161161
#[inline]
162162
unsafe fn grow_impl(
163163
&mut self,

library/alloc/src/collections/vec_deque.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2388,7 +2388,7 @@ impl<T> VecDeque<T> {
23882388
}
23892389
}
23902390

2391-
// Safety: the following two methods require that the rotation amount
2391+
// SAFETY: the following two methods require that the rotation amount
23922392
// be less than half the length of the deque.
23932393
//
23942394
// `wrap_copy` requires that `min(x, cap() - x) + copy_len <= cap()`,

library/core/src/future/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ where
7171
impl<T: Generator<ResumeTy, Yield = ()>> Future for GenFuture<T> {
7272
type Output = T::Return;
7373
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
74-
// Safety: Safe because we're !Unpin + !Drop, and this is just a field projection.
74+
// SAFETY: Safe because we're !Unpin + !Drop, and this is just a field projection.
7575
let gen = unsafe { Pin::map_unchecked_mut(self, |s| &mut s.0) };
7676

7777
// Resume the generator, turning the `&mut Context` into a `NonNull` raw pointer. The

library/core/src/iter/adapters/fuse.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ where
530530
#[inline]
531531
unsafe fn as_inner(&mut self) -> &mut S {
532532
match self.iter {
533-
// Safety: unsafe function forwarding to unsafe function with the same requirements
533+
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
534534
Some(ref mut iter) => unsafe { SourceIter::as_inner(iter) },
535535
// SAFETY: the specialized iterator never sets `None`
536536
None => unsafe { intrinsics::unreachable() },

library/core/src/iter/adapters/mod.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ where
10191019

10201020
#[inline]
10211021
unsafe fn as_inner(&mut self) -> &mut S {
1022-
// Safety: unsafe function forwarding to unsafe function with the same requirements
1022+
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
10231023
unsafe { SourceIter::as_inner(&mut self.iter) }
10241024
}
10251025
}
@@ -1168,7 +1168,7 @@ where
11681168

11691169
#[inline]
11701170
unsafe fn as_inner(&mut self) -> &mut S {
1171-
// Safety: unsafe function forwarding to unsafe function with the same requirements
1171+
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
11721172
unsafe { SourceIter::as_inner(&mut self.iter) }
11731173
}
11741174
}
@@ -1312,7 +1312,7 @@ where
13121312

13131313
#[inline]
13141314
unsafe fn as_inner(&mut self) -> &mut S {
1315-
// Safety: unsafe function forwarding to unsafe function with the same requirements
1315+
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
13161316
unsafe { SourceIter::as_inner(&mut self.iter) }
13171317
}
13181318
}
@@ -1550,7 +1550,7 @@ where
15501550

15511551
#[inline]
15521552
unsafe fn as_inner(&mut self) -> &mut S {
1553-
// Safety: unsafe function forwarding to unsafe function with the same requirements
1553+
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
15541554
unsafe { SourceIter::as_inner(&mut self.iter) }
15551555
}
15561556
}
@@ -1848,7 +1848,7 @@ where
18481848

18491849
#[inline]
18501850
unsafe fn as_inner(&mut self) -> &mut S {
1851-
// Safety: unsafe function forwarding to unsafe function with the same requirements
1851+
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
18521852
unsafe { SourceIter::as_inner(&mut self.iter) }
18531853
}
18541854
}
@@ -1967,7 +1967,7 @@ where
19671967

19681968
#[inline]
19691969
unsafe fn as_inner(&mut self) -> &mut S {
1970-
// Safety: unsafe function forwarding to unsafe function with the same requirements
1970+
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
19711971
unsafe { SourceIter::as_inner(&mut self.iter) }
19721972
}
19731973
}
@@ -2102,7 +2102,7 @@ where
21022102

21032103
#[inline]
21042104
unsafe fn as_inner(&mut self) -> &mut S {
2105-
// Safety: unsafe function forwarding to unsafe function with the same requirements
2105+
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
21062106
unsafe { SourceIter::as_inner(&mut self.iter) }
21072107
}
21082108
}
@@ -2200,7 +2200,7 @@ where
22002200

22012201
#[inline]
22022202
unsafe fn as_inner(&mut self) -> &mut S {
2203-
// Safety: unsafe function forwarding to unsafe function with the same requirements
2203+
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
22042204
unsafe { SourceIter::as_inner(&mut self.iter) }
22052205
}
22062206
}
@@ -2403,7 +2403,7 @@ where
24032403

24042404
#[inline]
24052405
unsafe fn as_inner(&mut self) -> &mut S {
2406-
// Safety: unsafe function forwarding to unsafe function with the same requirements
2406+
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
24072407
unsafe { SourceIter::as_inner(&mut self.iter) }
24082408
}
24092409
}
@@ -2530,7 +2530,7 @@ where
25302530

25312531
#[inline]
25322532
unsafe fn as_inner(&mut self) -> &mut S {
2533-
// Safety: unsafe function forwarding to unsafe function with the same requirements
2533+
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
25342534
unsafe { SourceIter::as_inner(&mut self.iter) }
25352535
}
25362536
}
@@ -2712,7 +2712,7 @@ where
27122712

27132713
#[inline]
27142714
unsafe fn as_inner(&mut self) -> &mut S {
2715-
// Safety: unsafe function forwarding to unsafe function with the same requirements
2715+
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
27162716
unsafe { SourceIter::as_inner(&mut self.iter) }
27172717
}
27182718
}
@@ -2879,7 +2879,7 @@ where
28792879

28802880
#[inline]
28812881
unsafe fn as_inner(&mut self) -> &mut S {
2882-
// Safety: unsafe function forwarding to unsafe function with the same requirements
2882+
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
28832883
unsafe { SourceIter::as_inner(&mut self.iter) }
28842884
}
28852885
}

library/core/src/iter/adapters/zip.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ where
343343

344344
#[inline]
345345
unsafe fn as_inner(&mut self) -> &mut S {
346-
// Safety: unsafe function forwarding to unsafe function with the same requirements
346+
// SAFETY: unsafe function forwarding to unsafe function with the same requirements
347347
unsafe { SourceIter::as_inner(&mut self.a) }
348348
}
349349
}

library/core/src/lazy.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<T> OnceCell<T> {
9292
/// Returns `None` if the cell is empty.
9393
#[unstable(feature = "once_cell", issue = "74465")]
9494
pub fn get(&self) -> Option<&T> {
95-
// Safety: Safe due to `inner`'s invariant
95+
// SAFETY: Safe due to `inner`'s invariant
9696
unsafe { &*self.inner.get() }.as_ref()
9797
}
9898

@@ -101,7 +101,7 @@ impl<T> OnceCell<T> {
101101
/// Returns `None` if the cell is empty.
102102
#[unstable(feature = "once_cell", issue = "74465")]
103103
pub fn get_mut(&mut self) -> Option<&mut T> {
104-
// Safety: Safe because we have unique access
104+
// SAFETY: Safe because we have unique access
105105
unsafe { &mut *self.inner.get() }.as_mut()
106106
}
107107

@@ -129,13 +129,13 @@ impl<T> OnceCell<T> {
129129
/// ```
130130
#[unstable(feature = "once_cell", issue = "74465")]
131131
pub fn set(&self, value: T) -> Result<(), T> {
132-
// Safety: Safe because we cannot have overlapping mutable borrows
132+
// SAFETY: Safe because we cannot have overlapping mutable borrows
133133
let slot = unsafe { &*self.inner.get() };
134134
if slot.is_some() {
135135
return Err(value);
136136
}
137137

138-
// Safety: This is the only place where we set the slot, no races
138+
// SAFETY: This is the only place where we set the slot, no races
139139
// due to reentrancy/concurrency are possible, and we've
140140
// checked that slot is currently `None`, so this write
141141
// maintains the `inner`'s invariant.

library/core/src/mem/maybe_uninit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ impl<T> MaybeUninit<T> {
599599
/// // Now that our `MaybeUninit<_>` is known to be initialized, it is okay to
600600
/// // create a shared reference to it:
601601
/// let x: &Vec<u32> = unsafe {
602-
/// // Safety: `x` has been initialized.
602+
/// // SAFETY: `x` has been initialized.
603603
/// x.assume_init_ref()
604604
/// };
605605
/// assert_eq!(x, &vec![1, 2, 3]);
@@ -676,7 +676,7 @@ impl<T> MaybeUninit<T> {
676676
/// // To assert our buffer has been initialized without copying it, we upgrade
677677
/// // the `&mut MaybeUninit<[u8; 2048]>` to a `&mut [u8; 2048]`:
678678
/// let buf: &mut [u8; 2048] = unsafe {
679-
/// // Safety: `buf` has been initialized.
679+
/// // SAFETY: `buf` has been initialized.
680680
/// buf.assume_init_mut()
681681
/// };
682682
///

library/core/src/num/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ assert_eq!(size_of::<Option<core::num::", stringify!($Ty), ">>(), size_of::<", s
124124
type Output = Self;
125125
#[inline]
126126
fn bitor(self, rhs: Self) -> Self::Output {
127-
// Safety: since `self` and `rhs` are both nonzero, the
127+
// SAFETY: since `self` and `rhs` are both nonzero, the
128128
// result of the bitwise-or will be nonzero.
129129
unsafe { $Ty::new_unchecked(self.get() | rhs.get()) }
130130
}
@@ -135,7 +135,7 @@ assert_eq!(size_of::<Option<core::num::", stringify!($Ty), ">>(), size_of::<", s
135135
type Output = Self;
136136
#[inline]
137137
fn bitor(self, rhs: $Int) -> Self::Output {
138-
// Safety: since `self` is nonzero, the result of the
138+
// SAFETY: since `self` is nonzero, the result of the
139139
// bitwise-or will be nonzero regardless of the value of
140140
// `rhs`.
141141
unsafe { $Ty::new_unchecked(self.get() | rhs) }
@@ -147,7 +147,7 @@ assert_eq!(size_of::<Option<core::num::", stringify!($Ty), ">>(), size_of::<", s
147147
type Output = $Ty;
148148
#[inline]
149149
fn bitor(self, rhs: $Ty) -> Self::Output {
150-
// Safety: since `rhs` is nonzero, the result of the
150+
// SAFETY: since `rhs` is nonzero, the result of the
151151
// bitwise-or will be nonzero regardless of the value of
152152
// `self`.
153153
unsafe { $Ty::new_unchecked(self | rhs.get()) }

library/core/src/pin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ impl<P: Deref<Target: Unpin>> Pin<P> {
474474
#[stable(feature = "pin", since = "1.33.0")]
475475
#[inline(always)]
476476
pub fn new(pointer: P) -> Pin<P> {
477-
// Safety: the value pointed to is `Unpin`, and so has no requirements
477+
// SAFETY: the value pointed to is `Unpin`, and so has no requirements
478478
// around pinning.
479479
unsafe { Pin::new_unchecked(pointer) }
480480
}

library/core/src/slice/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3245,7 +3245,7 @@ fn is_ascii(s: &[u8]) -> bool {
32453245
(word_ptr as usize) - (start as usize) == byte_pos
32463246
);
32473247

3248-
// Safety: We know `word_ptr` is properly aligned (because of
3248+
// SAFETY: We know `word_ptr` is properly aligned (because of
32493249
// `align_offset`), and we know that we have enough bytes between `word_ptr` and the end
32503250
let word = unsafe { word_ptr.read() };
32513251
if contains_nonascii(word) {

library/std/src/alloc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl System {
149149
}
150150
}
151151

152-
// Safety: Same as `AllocRef::grow`
152+
// SAFETY: Same as `AllocRef::grow`
153153
#[inline]
154154
unsafe fn grow_impl(
155155
&mut self,

library/std/src/ffi/c_str.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -881,13 +881,13 @@ impl From<Vec<NonZeroU8>> for CString {
881881
unsafe {
882882
// Transmute `Vec<NonZeroU8>` to `Vec<u8>`.
883883
let v: Vec<u8> = {
884-
// Safety:
884+
// SAFETY:
885885
// - transmuting between `NonZeroU8` and `u8` is sound;
886886
// - `alloc::Layout<NonZeroU8> == alloc::Layout<u8>`.
887887
let (ptr, len, cap): (*mut NonZeroU8, _, _) = Vec::into_raw_parts(v);
888888
Vec::from_raw_parts(ptr.cast::<u8>(), len, cap)
889889
};
890-
// Safety: `v` cannot contain null bytes, given the type-level
890+
// SAFETY: `v` cannot contain null bytes, given the type-level
891891
// invariant of `NonZeroU8`.
892892
CString::from_vec_unchecked(v)
893893
}

library/std/src/ffi/os_str.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -510,14 +510,14 @@ impl OsStr {
510510

511511
#[inline]
512512
fn from_inner(inner: &Slice) -> &OsStr {
513-
// Safety: OsStr is just a wrapper of Slice,
513+
// SAFETY: OsStr is just a wrapper of Slice,
514514
// therefore converting &Slice to &OsStr is safe.
515515
unsafe { &*(inner as *const Slice as *const OsStr) }
516516
}
517517

518518
#[inline]
519519
fn from_inner_mut(inner: &mut Slice) -> &mut OsStr {
520-
// Safety: OsStr is just a wrapper of Slice,
520+
// SAFETY: OsStr is just a wrapper of Slice,
521521
// therefore converting &mut Slice to &mut OsStr is safe.
522522
// Any method that mutates OsStr must be careful not to
523523
// break platform-specific encoding, in particular Wtf8 on Windows.

library/std/src/lazy.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl<T> SyncOnceCell<T> {
293293

294294
debug_assert!(self.is_initialized());
295295

296-
// Safety: The inner value has been initialized
296+
// SAFETY: The inner value has been initialized
297297
Ok(unsafe { self.get_unchecked() })
298298
}
299299

@@ -316,7 +316,7 @@ impl<T> SyncOnceCell<T> {
316316
/// ```
317317
#[unstable(feature = "once_cell", issue = "74465")]
318318
pub fn into_inner(mut self) -> Option<T> {
319-
// Safety: Safe because we immediately free `self` without dropping
319+
// SAFETY: Safe because we immediately free `self` without dropping
320320
let inner = unsafe { self.take_inner() };
321321

322322
// Don't drop this `SyncOnceCell`. We just moved out one of the fields, but didn't set
@@ -416,7 +416,7 @@ impl<T> SyncOnceCell<T> {
416416

417417
unsafe impl<#[may_dangle] T> Drop for SyncOnceCell<T> {
418418
fn drop(&mut self) {
419-
// Safety: The cell is being dropped, so it can't be accessed again.
419+
// SAFETY: The cell is being dropped, so it can't be accessed again.
420420
// We also don't touch the `T`, which validates our usage of #[may_dangle].
421421
unsafe { self.take_inner() };
422422
}

library/std/src/sys/windows/os_str.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ impl Buf {
7777
}
7878

7979
pub fn as_slice(&self) -> &Slice {
80-
// Safety: Slice is just a wrapper for Wtf8,
80+
// SAFETY: Slice is just a wrapper for Wtf8,
8181
// and self.inner.as_slice() returns &Wtf8.
8282
// Therefore, transmuting &Wtf8 to &Slice is safe.
8383
unsafe { mem::transmute(self.inner.as_slice()) }
8484
}
8585

8686
pub fn as_mut_slice(&mut self) -> &mut Slice {
87-
// Safety: Slice is just a wrapper for Wtf8,
87+
// SAFETY: Slice is just a wrapper for Wtf8,
8888
// and self.inner.as_mut_slice() returns &mut Wtf8.
8989
// Therefore, transmuting &mut Wtf8 to &mut Slice is safe.
9090
// Additionally, care should be taken to ensure the slice

library/std/src/sys_common/os_str_bytes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ impl Buf {
106106

107107
#[inline]
108108
pub fn as_slice(&self) -> &Slice {
109-
// Safety: Slice just wraps [u8],
109+
// SAFETY: Slice just wraps [u8],
110110
// and &*self.inner is &[u8], therefore
111111
// transmuting &[u8] to &Slice is safe.
112112
unsafe { mem::transmute(&*self.inner) }
113113
}
114114

115115
#[inline]
116116
pub fn as_mut_slice(&mut self) -> &mut Slice {
117-
// Safety: Slice just wraps [u8],
117+
// SAFETY: Slice just wraps [u8],
118118
// and &mut *self.inner is &mut [u8], therefore
119119
// transmuting &mut [u8] to &mut Slice is safe.
120120
unsafe { mem::transmute(&mut *self.inner) }

src/test/ui/generator/static-generators.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() {
1212
yield;
1313
assert_eq!(b as *const _, &a as *const _);
1414
};
15-
// Safety: We shadow the original generator variable so have no safe API to
15+
// SAFETY: We shadow the original generator variable so have no safe API to
1616
// move it after this point.
1717
let mut generator = unsafe { Pin::new_unchecked(&mut generator) };
1818
assert_eq!(generator.as_mut().resume(()), GeneratorState::Yielded(()));

0 commit comments

Comments
 (0)