Closed
Description
What it does
Detects unsafe blocks used in safe functions missing a comment explaining/justifying the use of unsafe
.
Categories (optional)
- Kind:
clippy::pedantic
What is the advantage of the recommended code over the original code
- Explains why the use of
unsafe
in the function is okay - Makes it easier to maintain
Drawbacks
None.
Example
fn get(self, slice: &[T]) -> Option<T> {
if self < slice.len() { unsafe { Some(&*self.get_unchecked(slice)) } } else { None }
}
Could be written as:
fn get(self, slice: &[T]) -> Option<T> {
// SAFETY: `self` is checked to be in bounds.
if self < slice.len() { unsafe { Some(&*self.get_unchecked(slice)) } } else { None }
}