New Lint: Unsafe block in safe functions without SAFETY comment (original) (raw)

What it does

Detects unsafe blocks used in safe functions missing a comment explaining/justifying the use of unsafe.

Categories (optional)

What is the advantage of the recommended code over the original code

Drawbacks

None.

Example

fn get(self, slice: &[T]) -> Option { if self < slice.len() { unsafe { Some(&*self.get_unchecked(slice)) } } else { None } }

Could be written as:

fn get(self, slice: &[T]) -> Option { // SAFETY: self is checked to be in bounds. if self < slice.len() { unsafe { Some(&*self.get_unchecked(slice)) } } else { None } }