5

On page 51 of "Programming Rust" by Jim Blandy & Jason Orendorff the authors state,

Unlike C and C++, Rust performs almost no numeric conversions implicitly.

Why "almost"? What implicit numeric conversions will Rust perform?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
  • 2
    None that come to mind. See also [How do I convert between numeric types safely and idiomatically?](https://stackoverflow.com/q/28273169/155423). My gut says that the authors used "weasel words" because proving a negative is hard and prone to breaking if Rust ever decides to add one. – Shepmaster Aug 14 '19 at 01:55
  • @Shepmaster I think the only fair thing, in light of how hard it is to prove a negative is to mark your comment as an answer pending someone else demonstrating otherwise. – Evan Carroll Aug 14 '19 at 02:27
  • 1
    The only thing that comes to mind is the way that numeric constants are handled. E.g. `let a: u8 = 1;` automatically "converts" the `1` into an `u8` ("converts" between quotes because it is not strictly speaking a conversion, but it could look that way at first glance). – Jmb Aug 14 '19 at 06:36

1 Answers1

1

Like the comments above I don't know of any such implicit conversion and couldn't find an example, but the Rust by example book states the following about type casts

Rust provides no implicit type conversion (coercion) between primitive types. But, explicit type conversion (casting) can be performed using the as keyword.

There is/was a Pre-RFC where this topic got discussed in more detail showing the pro/con arguments about why Rust should/n't have this feature.

For further information you may have a look at the From and Into traits.

Jarrrkob
  • 11
  • 1
  • 3