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
519 impl{T} HasWork<Self> for ClosureWork<T> { self.work }519 impl{T} HasWork<Self> for ClosureWork<T> { self.work }
520}520}
521 521
522// SAFETY: TODO.
522unsafe impl<T, const ID: u64> WorkItemPointer<ID> for Arc<T>523unsafe impl<T, const ID: u64> WorkItemPointer<ID> for Arc<T>
523where524where
524 T: WorkItem<ID, Pointer = Self>,525 T: WorkItem<ID, Pointer = Self>,
@@ -536,6 +537,7 @@ where · 11 unmodified lines
536 }537 }
537}538}
538 539
540// SAFETY: TODO.
539unsafe impl<T, const ID: u64> RawWorkItem<ID> for Arc<T>541unsafe impl<T, const ID: u64> RawWorkItem<ID> for Arc<T>
540where542where
541 T: WorkItem<ID, Pointer = Self>,543 T: WorkItem<ID, Pointer = Self>,
@@ -564,6 +566,7 @@ where · 22 unmodified lines
564 }566 }
565}567}
566 568
569// SAFETY: TODO.
567unsafe impl<T, const ID: u64> WorkItemPointer<ID> for Pin<Box<T>>570unsafe impl<T, const ID: u64> WorkItemPointer<ID> for Pin<Box<T>>
568where571where
569 T: WorkItem<ID, Pointer = Self>,572 T: WorkItem<ID, Pointer = Self>,
@@ -583,6 +586,7 @@ where · 13 unmodified lines
583 }586 }
584}587}
585 588
589// SAFETY: TODO.
586unsafe impl<T, const ID: u64> RawWorkItem<ID> for Pin<Box<T>>590unsafe impl<T, const ID: u64> RawWorkItem<ID> for Pin<Box<T>>
587where591where
588 T: WorkItem<ID, Pointer = Self>,592 T: WorkItem<ID, Pointer = Self>,