# \[Pre-RFC\] Implicit number type widening

**URL:** <https://internals.rust-lang.org/t/pre-rfc-implicit-number-type-widening/10432>\
**Category:** Uncategorized\
**Created:** [June 19, 2019, 8:12pm UTC](https://internals.rust-lang.org/t/pre-rfc-implicit-number-type-widening/10432 "2019-06-19T20:12:01Z")\
**Posts on this page:** 1\
**Showing post:** 89

<div class="post-metadata">

**Author:** ![RalfJung](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/ralfjung/32/2415_2.png) [@RalfJung](https://internals.rust-lang.org/u/RalfJung)\
**Post date:** [July 12, 2019, 8:11am UTC](https://internals.rust-lang.org/t/pre-rfc-implicit-number-type-widening/10432/89 "2019-07-12T08:11:02Z")

</div>

> [@scottmcm](#):
>
> I consider this a non-issue, because `arr[usize::MAX]` or `let idx = -1; arr[idx as usize]` will _also_ assert at runtime. So one needs to get the _value_ correct when indexing regardless of the _type_ , so I don’t see any harm in allowing additional types.

Agreed. "Index into that array with this `u16`/`u32`/..." is a perfectly well-defined operation. It is partial, just like normal indexing. It could be implemented as

```rust
fn get<I>(&self, i: I) -> Option<&T> where usize: TryFrom<I> {
  self.get_with_usize(usize::try_from(i)?)
}

```

If either the cast or the indexing fails, we get `None`, otherwise we get `Some`. There is nothing lossy about this.

Is there any situation in which this method would not do what is intended, would lead to subtle bugs or would generally not be desirable? Off the top of my head, I don't see any.

---

_[View the full topic](https://internals.rust-lang.org/t/pre-rfc-implicit-number-type-widening/10432)._
