History

rust: enable `clippy::undocumented_unsafe_blocks` lint

Checking that we are not missing any `// SAFETY` comments in our `unsafe` blocks is something we have wanted to do for a long time, as well as cleaning up the remaining cases that were not documented [1]. Back when Rust for Linux started, this was something that could have been done via a script, like Rust's `tidy`. Soon after, in Rust 1.58.0, Clippy implemented the `undocumented_unsafe_blocks` lint [2]. Even though the lint has a few false positives, e.g. in some cases where attributes appear between the comment and the `unsafe` block [3], there are workarounds and the lint seems quite usable already. Thus enable the lint now. We still have a few cases to clean up, so just allow those for the moment by writing a `TODO` comment -- some of those may be good candidates for new contributors.

Miguel Ojeda committed 2 years ago

Commit db4f72c1 parent 567cdff16 files · +47 −10Browse files

Showing the changes to rust/kernel/workqueue.rs (1 of 16 files). Show all

Unified · Split

rust/kernel/workqueue.rs+4−0
@@ -519,6 +519,7 @@ impl_has_work! { · 518 unmodified lines
519519 impl{T} HasWork<Self> for ClosureWork<T> { self.work }
520520 }
521521
522+// SAFETY: TODO.
522523 unsafe impl<T, const ID: u64> WorkItemPointer<ID> for Arc<T>
523524 where
524525 T: WorkItem<ID, Pointer = Self>,
@@ -536,6 +537,7 @@ where · 11 unmodified lines
536537 }
537538 }
538539
540+// SAFETY: TODO.
539541 unsafe impl<T, const ID: u64> RawWorkItem<ID> for Arc<T>
540542 where
541543 T: WorkItem<ID, Pointer = Self>,
@@ -564,6 +566,7 @@ where · 22 unmodified lines
564566 }
565567 }
566568
569+// SAFETY: TODO.
567570 unsafe impl<T, const ID: u64> WorkItemPointer<ID> for Pin<Box<T>>
568571 where
569572 T: WorkItem<ID, Pointer = Self>,
@@ -583,6 +586,7 @@ where · 13 unmodified lines
583586 }
584587 }
585588
589+// SAFETY: TODO.
586590 unsafe impl<T, const ID: u64> RawWorkItem<ID> for Pin<Box<T>>
587591 where
588592 T: WorkItem<ID, Pointer = Self>,