Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You might be referring to slices. Arrays in rust have to have a known length at compile time.


Rustc may still need to do runtime bounds check if it can’t conclude that a dynamically computed index is in-bounds.

The length is known statically, but whether the index is in-bounds may not be.

The binary search GP talks about is exactly one such case, go on Godbolt, write up a simple binary search (with a static size so you get code), and you’ll see that the compiler checks against the literal array size on every iteration.


I have no idea how I totally missed that from the GP's comment. Thanks for correcting me.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: