rust-lang / nomicon

The Dark Arts of Advanced and Unsafe Rust Programming
https://doc.rust-lang.org/nomicon/
Apache License 2.0
1.75k stars 256 forks source link

wrong comment/docs in "Vec from scratch" chapter? #390

Closed lauti7 closed 1 year ago

lauti7 commented 1 year ago

Hi, I'm opening up this issue because in this chapter (Vec from scratch), the code example at the end of the page has one comments which say:

 // This can't overflow since self.cap <= isize::MAX.

I think the above comment is wrong because self.cap is an usize type so actually it can be greater than isize::MAX.

Is this actually wrong or am I misunderstanding something? Hope you can help me out.

ehuss commented 1 year ago

There is an invariant enforced by an assert just a few lines below that it cannot be over isize::MAX.

lauti7 commented 1 year ago

Thank you