Skip to content

Commit 7107935

Browse files
ojedasmb49
authored andcommitted
rust: enable clippy::unnecessary_safety_comment lint
BugLink: https://bugs.launchpad.net/bugs/2107437 commit c28bfe7 upstream. In Rust 1.67.0, Clippy added the `unnecessary_safety_comment` lint [1], which is the "inverse" of `undocumented_unsafe_blocks`: it finds places where safe code has a `// SAFETY` comment attached. The lint currently finds 3 places where we had such mistakes, thus it seems already quite useful. Thus clean those and enable it. Link: https://rust-lang.github.io/rust-clippy/master/index.html#/unnecessary_safety_comment [1] Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Trevor Gross <tmgross@umich.edu> Reviewed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com> Tested-by: Gary Guo <gary@garyguo.net> Reviewed-by: Gary Guo <gary@garyguo.net> Link: https://lore.kernel.org/r/20240904204347.168520-6-ojeda@kernel.org Signed-off-by: Miguel Ojeda <ojeda@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> [nwager: Context change due to missing commit: 4e7072490d67c ("rust: enable `clippy::undocumented_unsafe_blocks` lint") Signed-off-by: Noah Wager <noah.wager@canonical.com> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
1 parent 50de79f commit 7107935

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ export rust_common_flags := --edition=2021 \
458458
-Wclippy::needless_continue \
459459
-Aclippy::needless_lifetimes \
460460
-Wclippy::no_mangle_with_rust_abi \
461+
-Wclippy::unnecessary_safety_comment \
461462
-Wrustdoc::missing_crate_level_docs
462463

463464
KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) \

rust/kernel/sync/arc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ impl<T: 'static> ForeignOwnable for Arc<T> {
359359
}
360360

361361
unsafe fn borrow<'a>(ptr: *const core::ffi::c_void) -> ArcBorrow<'a, T> {
362-
// SAFETY: By the safety requirement of this function, we know that `ptr` came from
362+
// By the safety requirement of this function, we know that `ptr` came from
363363
// a previous call to `Arc::into_foreign`.
364364
let inner = NonNull::new(ptr as *mut ArcInner<T>).unwrap();
365365

rust/kernel/workqueue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ where
525525
T: HasWork<T, ID>,
526526
{
527527
unsafe extern "C" fn run(ptr: *mut bindings::work_struct) {
528-
// SAFETY: The `__enqueue` method always uses a `work_struct` stored in a `Work<T, ID>`.
528+
// The `__enqueue` method always uses a `work_struct` stored in a `Work<T, ID>`.
529529
let ptr = ptr as *mut Work<T, ID>;
530530
// SAFETY: This computes the pointer that `__enqueue` got from `Arc::into_raw`.
531531
let ptr = unsafe { T::work_container_of(ptr) };
@@ -570,7 +570,7 @@ where
570570
T: HasWork<T, ID>,
571571
{
572572
unsafe extern "C" fn run(ptr: *mut bindings::work_struct) {
573-
// SAFETY: The `__enqueue` method always uses a `work_struct` stored in a `Work<T, ID>`.
573+
// The `__enqueue` method always uses a `work_struct` stored in a `Work<T, ID>`.
574574
let ptr = ptr as *mut Work<T, ID>;
575575
// SAFETY: This computes the pointer that `__enqueue` got from `Arc::into_raw`.
576576
let ptr = unsafe { T::work_container_of(ptr) };

0 commit comments

Comments
 (0)