Panic when advance_slices()'ing too far and update docs.#94855
Panic when advance_slices()'ing too far and update docs.#94855bors merged 3 commits intorust-lang:masterfrom
Conversation
|
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
6a4862e to
4d7daa0
Compare
Thomasdezeeuw
left a comment
There was a problem hiding this comment.
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 |
| *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.
maybe use assert_eq here to include the expected length in the panic message?
There was a problem hiding this comment.
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.)
|
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)