Skip to content

Commit e73125e

Browse files
sfacklerMark-Simulacrum
authored andcommitted
make check a bit more clear
1 parent 2fe7ddc commit e73125e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library/std/src/io/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,15 @@ where
385385
}
386386
}
387387

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

0 commit comments

Comments
 (0)