Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Implicit Conversions

Wherever any rule of this specification requires an expression to have some type, an expression whose type differs is accepted when a conversion from its type to the required type is specified on this page. The conversion is applied implicitly; conversions require no notation, and the rules that rely on them need not mention them.

Widening

An expression of type T implicitly converts to U when T widens to U within the same family:

  • signed integers: i8 → i16 → i32 → i64
  • unsigned integers: u8 → u16 → u32 → u64
  • floating-point: f32 → f64

Conversions between families are not allowed; in particular, signed and unsigned integers, or integers and floating-point types, cannot be implicitly converted.

Handle Dereference

An expression of handle type &T implicitly converts to T by dereferencing the handle. Conversions compose: an expression of type &&T converts first to &T, and then to T.

Common Type

Two or more types have a common type when they are all identical, or when they are all numeric types within the same family; in the latter case, the common type is the widest of them.

When determining a common type, a candidate type may be replaced by any type it converts to; the replacement is repeated until the types are identical or all numeric within one family, and the resulting type is the common type. Thus, for example, &T and T have the common type T.