Calling methods on fallback integer type?

Why does the first code snippet fail with error error[E0599]: no method named abs found for type {integer} in the current scope:

let a = 3;
println!("{}", a.abs());

whereas, on specifying the type explicitly, this passes:

 let a = 3_i32;
 println!("{}", a.abs());

Isn't the default inferred type for numbers i32 as per this RFC? Then why are above two code snippets treated differently?

You are entirely correct. See Is not being able apply abs() without explicit types a limitation of type inference? for a discussion. The answer is "yes".

1 Like

Thanks for the pointer!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.