# Subscripts and sizes should be signed

**URL:** <https://internals.rust-lang.org/t/subscripts-and-sizes-should-be-signed/17699>\
**Category:** language design\
**Created:** [November 6, 2022, 6:29pm UTC](https://internals.rust-lang.org/t/subscripts-and-sizes-should-be-signed/17699 "2022-11-06T18:29:09Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [November 7, 2022, 9:51pm UTC](https://internals.rust-lang.org/t/subscripts-and-sizes-should-be-signed/17699/16 "2022-11-07T21:51:43Z")

</div>

> [@T4r4sB](#):
>
> And I dont understand, why Rust repeats this mistake.

Rust doesn't make this mistake because it didn't repeat the core mistake from C++ in the first place.

If you look at the paper, the primary reason is

> Signed values are the result of most integer calculations

That's _just not true in Rust_.

C++ has the "usual arithmetic conversions" which mean that if you add `unsigned short` to `unsigned short` you get **not** another `unsigned short`, but an `int`! (Well, probably. Depending on your platform's integer sizes things could be even weirder.)

In Rust if you add a `u16` to a `u16` you get a `u16`, **not** an `i32`.

So unsigned types aren't second-class in Rust the way they are in C++, and thus it's good and correct for indexing and `.len()` and such to be unsigned in Rust.

---

_[View the full topic](https://internals.rust-lang.org/t/subscripts-and-sizes-should-be-signed/17699)._
