Skip to content

docs: correct the Panics section on Bytes::slice_ref - #854

Open
hxperl wants to merge 1 commit into
tokio-rs:masterfrom
hxperl:docs/slice-ref-panics
Open

hxperl wants to merge 1 commit into
tokio-rs:masterfrom
hxperl:docs/slice-ref-panics

Conversation

@hxperl

@hxperl hxperl commented Sep 15, 2026 •

Copy link
Copy Markdown

The # Panics section on Bytes::slice_ref is wrong twice over:

/// Requires that the given `sub` slice is in fact contained within the
/// `Bytes` buffer; otherwise this function will panic.
pub fn slice_ref(&self, subset: &[u8]) -> Self {
  1. It names sub; the parameter is subset, which the rest of the doc comment already uses. `sub` appears nowhere else in src/.
  2. An empty subset does not panic even when it is outside the buffer — slice_ref returns early. The repo's own empty_slice_ref_catches_not_an_empty_subset test asserts exactly that.

Fixed both.

The section names a `sub` parameter that does not exist (the parameter is
`subset`), and states a containment requirement that has not held since
tokio-rs#355, which made an empty `subset` always succeed. Two tests in
tests/test_bytes.rs already assert the behaviour the docs deny.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant