arraydeque icon indicating copy to clipboard operation
arraydeque copied to clipboard

Shrink unsafe blocks

Open peamaeq opened this issue 3 years ago • 0 comments

In this function you use the unsafe keyword for many safe expressions. However, I found that only 2 functions are real unsafe operations (see the list below).

We need to mark unsafe operations more precisely using unsafe keyword. Keeping unsafe blocks small can bring many benefits. For example, when mistakes happen, we can locate any errors related to memory safety within an unsafe block. This is the balance between Safe and Unsafe Rust. The separation is designed to make using Safe Rust as ergonomic as possible, but requires extra effort and care when writing Unsafe Rust. Real unsafe operation list:

  1. dereference raw pointer(*(self as *const Self as *mut Self))
  2. the copy_nonoverlapping() function(unsafe function)

Hope this PR can help you. Best regards. References https://doc.rust-lang.org/nomicon/safe-unsafe-meaning.html https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html

peamaeq avatar Jun 23 '22 06:06 peamaeq