logoalt Hacker News

wasmpersonyesterday at 8:19 PM1 replyview on HN

This isn't entirely true. Rust's indexing operator performs a dynamic check but the language and stdlib have a number of ways to access array elements without indexing, which is effectively a form of static checking. For example, the following loop is statically guaranteed to not go OOB, and will not emit any unnecessary bounds checks:

  for i in some_arr {
    println!("{i}");
  }
I suspect most techniques you could think of to statically avoid bounds checks are possible in rust's type system.

Replies

ueckeryesterday at 9:01 PM

These are not terribly interesting cases though, as it would also be impossible to get an oob access in other languages either.

show 1 reply