-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Panic when advance_slices()'ing too far and update docs. #94855
Conversation
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
6a4862e
to
4d7daa0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't really have a strong opinion here. On one hand it introduces an additional assert
(don't know if it's compiled away), on the other hand having consistent behaviour with advance
which is pretty nice.
The number of bytes to advance will in most cases be the result of a syscall, so in those cases the check can't be optimized away, unfortunately. Consistency with |
@@ -1155,7 +1162,9 @@ impl<'a> IoSliceMut<'a> { | |||
} | |||
|
|||
*bufs = &mut replace(bufs, &mut [])[remove..]; | |||
if !bufs.is_empty() { | |||
if bufs.is_empty() { | |||
assert!(n == accumulated_len, "advancing io slices beyond their length"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use assert_eq
here to include the expected length in the panic message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then the user would just see left: 200, right: 100
, which doesn't mean much. (Also, assert_eq
results in mode codegen, which is a bit of a waste.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
triage: |
@bors r=kennytm |
📌 Commit 1890372 has been approved by |
Rollup of 8 pull requests Successful merges: - rust-lang#93080 (Implement `core::slice::IterMut::as_mut_slice` and `impl<T> AsMut<[T]> for IterMut<'_, T>`) - rust-lang#94855 (Panic when advance_slices()'ing too far and update docs.) - rust-lang#96609 (Add `{Arc, Rc}::downcast_unchecked`) - rust-lang#96719 (Fix the generator example for `pin!()`) - rust-lang#97149 (Windows: `CommandExt::async_pipes`) - rust-lang#97150 (`Stdio::makes_pipe`) - rust-lang#97837 (Document Rust's stance on `/proc/self/mem`) - rust-lang#98159 (Include ForeignItem when visiting types for WF check) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This updates advance_slices() to panic when advancing too far, like advance() already does. And updates the docs to say so.
See #62726 (comment)