It is surprisingly hard to find this in the docs. This might even be a two part question:
Are
{integer}
and{float}
some sort of language alias for a specific primitive type?What does it mean for a type name to be enclosed in curly braces in a compilation/syntax error message?
Example:
error: no method named
pow
found for type{integer}
in the current scope
{integer}
in error messages is a placeholder for any of the integer types ({i,u}{8,16,32,64,128}
). (Source)Integer literals in Rust are type inferred based on their usage. For example, in the following code, the type of
123
isu8
in the first instance andu64
in the second:{integer}
is used to represent any integer type in error messages when the compiler hasn't figured out a concrete type of the value.{integer}
is an integral value whose concrete type was not specified and has not been inferred by the compiler yet; the following code:Will result in the following error:
The same would happen with a floating number:
Because the compilation error caused by the invalid assignment
let () = x
is thrown before the type inference can happen.In other words, until the compilation reaches the type inference stage where an integer or a float without a concrete type specified would be recognized (e.g. based on function application) or assigned the default type,
i32
for integers andf64
for floats, compilation errors will refer to it as an{integer}
or a{float}
.