From eefec8abda7cb8e8693aa876fbd1e21f2a6a5c2d Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Wed, 24 Feb 2021 05:48:44 +0100 Subject: library: Normalize safety-for-unsafe-block comments Almost all safety comments are of the form `// SAFETY:`, so normalize the rest and fix a few of them that should have been a `/// # Safety` section instead. Furthermore, make `tidy` only allow the uppercase form. While currently `tidy` only checks `core`, it is a good idea to prevent `core` from drifting to non-uppercase comments, so that later we can start checking `alloc` etc. too. Signed-off-by: Miguel Ojeda --- library/alloc/src/collections/btree/map/entry.rs | 4 ++-- library/alloc/src/vec/mod.rs | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'library/alloc/src') diff --git a/library/alloc/src/collections/btree/map/entry.rs b/library/alloc/src/collections/btree/map/entry.rs index 6cc8813bc52..941f82a8070 100644 --- a/library/alloc/src/collections/btree/map/entry.rs +++ b/library/alloc/src/collections/btree/map/entry.rs @@ -278,14 +278,14 @@ impl<'a, K: Ord, V> VacantEntry<'a, K, V> { pub fn insert(self, value: V) -> &'a mut V { let out_ptr = match self.handle.insert_recursing(self.key, value) { (Fit(_), val_ptr) => { - // Safety: We have consumed self.handle and the handle returned. + // SAFETY: We have consumed self.handle and the handle returned. let map = unsafe { self.dormant_map.awaken() }; map.length += 1; val_ptr } (Split(ins), val_ptr) => { drop(ins.left); - // Safety: We have consumed self.handle and the reference returned. + // SAFETY: We have consumed self.handle and the reference returned. let map = unsafe { self.dormant_map.awaken() }; let root = map.root.as_mut().unwrap(); root.push_internal_level().push(ins.kv.0, ins.kv.1, ins.right); diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index dbb7708b600..b1b26194283 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1938,13 +1938,13 @@ impl Vec { pub fn split_at_spare_mut(&mut self) -> (&mut [T], &mut [MaybeUninit]) { let ptr = self.as_mut_ptr(); - // Safety: + // SAFETY: // - `ptr` is guaranteed to be in bounds for `capacity` elements // - `len` is guaranteed to less or equal to `capacity` // - `MaybeUninit` has the same layout as `T` let spare_ptr = unsafe { ptr.cast::>().add(self.len) }; - // Safety: + // SAFETY: // - `ptr` is guaranteed to be valid for `len` elements // - `spare_ptr` is offseted from `ptr` by `len`, so it doesn't overlap `initialized` slice unsafe { @@ -2154,7 +2154,8 @@ pub fn from_elem_in(elem: T, n: usize, alloc: A) -> Vec< } trait ExtendFromWithinSpec { - /// Safety: + /// # Safety + /// /// - `src` needs to be valid index /// - `self.capacity() - self.len()` must be `>= src.len()` unsafe fn spec_extend_from_within(&mut self, src: Range); @@ -2165,14 +2166,14 @@ impl ExtendFromWithinSpec for Vec { let initialized = { let (this, spare) = self.split_at_spare_mut(); - // Safety: + // SAFETY: // - caller guaratees that src is a valid index let to_clone = unsafe { this.get_unchecked(src) }; to_clone.iter().cloned().zip(spare.iter_mut()).map(|(e, s)| s.write(e)).count() }; - // Safety: + // SAFETY: // - elements were just initialized unsafe { let new_len = self.len() + initialized; @@ -2187,11 +2188,11 @@ impl ExtendFromWithinSpec for Vec { { let (init, spare) = self.split_at_spare_mut(); - // Safety: + // SAFETY: // - caller guaratees that `src` is a valid index let source = unsafe { init.get_unchecked(src) }; - // Safety: + // SAFETY: // - Both pointers are created from unique slice references (`&mut [_]`) // so they are valid and do not overlap. // - Elements are :Copy so it's OK to to copy them, without doing @@ -2203,7 +2204,7 @@ impl ExtendFromWithinSpec for Vec { unsafe { ptr::copy_nonoverlapping(source.as_ptr(), spare.as_mut_ptr() as _, count) }; } - // Safety: + // SAFETY: // - The elements were just initialized by `copy_nonoverlapping` self.len += count; } -- cgit 1.4.1-3-g733a5