# \[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:** 5

<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:** [June 19, 2019, 11:02pm UTC](https://internals.rust-lang.org/t/pre-rfc-implicit-number-type-widening/10432/5 "2019-06-19T23:02:51Z")

</div>

I think scoping this will be the difficult part.

I would be very happy for something like `Foo { some_u32_field: some_u8 }` to work, for example. But I get worried about things like `x * (y + z)` if that ends up being `x * (((y as u16) + y) as u32)` with multiple conversions inside with implications for wrapping.

There might also be weird things about this with literals -- if there's a coercion site, do more literals end up falling back to i32, and thus other things end up being i32 that weren't before? For example,

```rust
let mut x = 4; // Today in rust this is u8 because of the line below
x = 3_i8; // but if this is a coercion site, x could be i32
          // because the line above defaults to i32
          // and then this implicitly widens to i32

```

So I'd like to see more details about exactly when this would apply, and particularly how it'd interact with trait resolution.

> [@djc](#):
>
> called out the pervasive use of `usize` for indexing, so that it would be nice if smaller types could trivially be used as indexes.

Note that anything with traits could instead be done by implementing those traits for the other types. The current blocker for that is being able to "default" the inference on them, but I think that's wanted to support other versions of this, like comparisons between i32 and u32 that actually do the correct thing.

---

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