Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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