What is the {integer} in the compiler error message?

Surprisingly hard to find this in the docs. It may even be a matter of two parts:

  • Is {integer}a kind of language alias for a particular primitive type?

  • What does it mean that the type name will be enclosed in braces in a compilation / syntax error message?

Example:

error: {integer}no methods were found for the method with the name powin the current Volume

+4
source share
2 answers

{integer}- an integer value whose specific type has not been specified and has not yet been inferred by the compiler; following code:

fn main() {
    let x = 1;
    let () = x;
}

Will result in the following error:

error[E0308]: mismatched types

 --> <anon>:3:9
  |
3 |     let () = x;
  |         ^^ expected integral variable, found ()
  |
  = note: expected type `{integer}`
  = note:    found type `()`

The same thing will happen with a floating number:

fn main() {
    let x = 1.0;
    let () = x;
}
error[E0308]: mismatched types
 --> <anon>:3:9
  |
3 |     let () = x;
  |         ^^ expected floating-point variable, found ()
  |
  = note: expected type `{float}`
  = note:    found type `()`

, let () = x, , .

, , , float (, ) , i32 f64 float, {integer} {float}.

+8

{integer} ({i,u}{8,16,32,64,128}). ()

Rust - , . , 123 u8 , u64 - :

let a: u8 = 123;
let a: u64 = 123;

{integer} , .

+7

Source: https://habr.com/ru/post/1668589/


All Articles