I thought this would work:
let x = 5;
println!("x = {}", x);
But it gives the following compile error:
main.rs:3:24: 3:25 error: unable to infer enough type information to locate the impl of the trait `core::fmt::Show` for the type `_`; type annotations required
main.rs:3 println!("x = {}", x);
Am I missing something?
I'm using an online Rust compiler and the version they have is Rust v0.13.0
.
The error is because the compiler you use is old. For this compiler, try by explicitly giving an integer type:
let x: i32 = 5;
println!("x = {}", x);
On newer compilers, your code will work as is, even without specifying i32
explicitly:
let x = 5;
println!("x = {}", x);
You can use the official online compiler at https://play.rust-lang.org/, which is always an up-to-date version of Rust.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With