Skip to content

Commit

Permalink
[clippy] Be more permissive with safety comments (#398)
Browse files Browse the repository at this point in the history
Set the following Clippy configuration variables, which we set to
`true`:
- `accept-comment-above-statement`
- `accept-comment-above-attributes`
  • Loading branch information
joshlf committed Oct 24, 2023
1 parent 344fe4a commit 1f74e5c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
6 changes: 6 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright 2023 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

accept-comment-above-statement = true
accept-comment-above-attributes = true
5 changes: 0 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3626,11 +3626,6 @@ mod tests {
let slc_field_ptr = addr_of_slice_field(ptr).as_ptr();
// SAFETY: Both `slc_field_ptr` and `ptr` are pointers to
// the same valid Rust object.
//
// TODO(https://github.com/rust-lang/rust-clippy/issues/11534):
// Remove this `allow` once Clippy recognizes this block as
// having a safety comment.
#[allow(clippy::undocumented_unsafe_blocks)]
let offset: usize =
unsafe { slc_field_ptr.byte_offset_from(ptr.as_ptr()).try_into().unwrap() };
assert_eq!(offset, args.offset);
Expand Down
18 changes: 7 additions & 11 deletions src/wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,13 @@ impl<T> Unalign<T> {

impl<T> Drop for WriteBackOnDrop<T> {
fn drop(&mut self) {
// SAFETY: See inline comments.
unsafe {
// SAFETY: We never use `copy` again as required by
// `ManuallyDrop::take`.
let copy = ManuallyDrop::take(&mut self.copy);
// SAFETY: `slf` is the raw pointer value of `self`. We know
// it is valid for writes and properly aligned because
// `self` is a mutable reference, which guarantees both of
// these properties.
ptr::write(self.slf, Unalign::new(copy));
}
// SAFETY: We never use `copy` again as required by
// `ManuallyDrop::take`.
let copy = unsafe { ManuallyDrop::take(&mut self.copy) };
// SAFETY: `slf` is the raw pointer value of `self`. We know it
// is valid for writes and properly aligned because `self` is a
// mutable reference, which guarantees both of these properties.
unsafe { ptr::write(self.slf, Unalign::new(copy)) };
}
}

Expand Down

0 comments on commit 1f74e5c

Please sign in to comment.