You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you have a preference as to how detailed the documentation should be? Unsafe Rust is a tricky beast and many of the unsafe functions that are used have quite a long list of safety requirements. The way I'm approaching this now is to go through these lists and verify that each requirement is met and document that accordingly, but that makes the SAFETY comments quite long in some cases. Here is one example in DequeInner::make_contiguous, which uses a lot of pointer arithmetics and raw memcpy:
...}elseiffree >= back_len{// there is enough free space to copy the tail in one go,// this means that we first shift the head forwards, and then// copy the tail to the correct position.//// from: FGH....ABCDE// to: ...ABCDEFGH.// SAFETY: Explaining it visually is easier:// step 1: FGH....ABCDE// | |// 1 2// |__|___|___|// back_len---^ ^ ^---- front_len// free// step 2: FGHABCDE....// | |// 3 4// Pointers: 1: `buffer_ptr.add(self.back)`// 2: `buffer_ptr.add(self.front)`// 3: `buffer_ptr`// 4: `buffer_ptr.add(self.back + front_len)`// All pointers are clearly within the underlying buffer and are properly aligned, meeting the first safety// requirement for `ptr.add` and the `ptr::copy...` variants.// In step 1 above, we see that pointer 1 is always `<=` than pointer 2, so the copy stays within the bounds// of the buffer, but it might overlap, hence the usage of `ptr::copy`// In step 2 above, we see that the target memory region does not overlap with the source region, as pointer 4// is larger than pointer 3 plus `back_len`. Finally the branch condition assures that the gap is large enough// to copy `back_len` elements into
unsafe {ptr::copy(
buffer_ptr.add(self.front),
buffer_ptr.add(self.back),
front_len,);// FGHABCDE....
ptr::copy_nonoverlapping(
buffer_ptr,
buffer_ptr.add(self.back + front_len),
back_len,);// ...ABCDEFGH.}self.front = back;self.back = 0;}
...
The unit tests should catch the various edge cases that the algorithm itself has, so maybe I could reduce the comment length and simply state "We ensure that all pointers always stay within their bounds through the tests"?
Do you have a preference as to how detailed the documentation should be?
I can't speak for @reitermarkus here but IMO while your attention to detail is appreciated, I really don't think we need this level of detail. Typically, you'd just have a bullet list for each safety requirement mentioned in the documentation of the API being used, shortly explaining why/how the requirement is satisfied.
I found one potential safety violation related to #579 (see my comment in there). I'll continue checking and commenting the rest of the unsafe code and will comment here if I find something else, then we can discuss how to deal with each issue.
Activity
Mortano commentedon Aug 13, 2025
I should be able to help with that, if the help is still wanted. Are there any contribution guidelines for first-time contributors?
zeenix commentedon Aug 13, 2025
I'm pretty sure it is. :) Thanks.
None really. We do have a CoC (see
CODE_OF_CONDUCT.mdfile) but that's pretty normal these days.Mortano commentedon Aug 13, 2025
Ok I'll start working on this then :)
Mortano commentedon Aug 15, 2025
Do you have a preference as to how detailed the documentation should be? Unsafe Rust is a tricky beast and many of the unsafe functions that are used have quite a long list of safety requirements. The way I'm approaching this now is to go through these lists and verify that each requirement is met and document that accordingly, but that makes the
SAFETYcomments quite long in some cases. Here is one example inDequeInner::make_contiguous, which uses a lot of pointer arithmetics and raw memcpy:The unit tests should catch the various edge cases that the algorithm itself has, so maybe I could reduce the comment length and simply state "We ensure that all pointers always stay within their bounds through the tests"?
zeenix commentedon Aug 16, 2025
I can't speak for @reitermarkus here but IMO while your attention to detail is appreciated, I really don't think we need this level of detail. Typically, you'd just have a bullet list for each safety requirement mentioned in the documentation of the API being used, shortly explaining why/how the requirement is satisfied.
I typically keep them short but probably that's a bit too short. :)
Mortano commentedon Aug 17, 2025
Ok I'll try to keep it more concise then, thanks for the clarification
Mortano commentedon Aug 20, 2025
I found one potential safety violation related to #579 (see my comment in there). I'll continue checking and commenting the rest of the
unsafecode and will comment here if I find something else, then we can discuss how to deal with each issue.