Skip to content

Commit 5cb8303

Browse files
committed
make check a bit more clear
1 parent a9ef798 commit 5cb8303

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library/std/src/io/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,15 @@ where
384384
}
385385
}
386386

387-
match r.read(&mut g.buf[g.len..]) {
387+
let buf = &mut g.buf[g.len..];
388+
match r.read(buf) {
388389
Ok(0) => return Ok(g.len - start_len),
389390
Ok(n) => {
390391
// We can't let g.len overflow which would result in the vec shrinking when the function returns. In
391392
// particular, that could break read_to_string if the shortened buffer doesn't end on a UTF-8 boundary.
392393
// The minimal check would just be a checked_add, but this assert is a bit more precise and should be
393394
// just about the same cost.
394-
assert!(n <= g.buf.len() - g.len);
395+
assert!(n <= buf.len());
395396
g.len += n;
396397
}
397398
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}

0 commit comments

Comments
 (0)