count_ones is not provided by a trait shared among integral types - it's implemented separately for each of them. This means you need to specify the type in order for that method to be applicable to the number you want to use it on - the compiler needs to know which type's implementation to use.
In addition, if you are wondering why in this case the compiler doesn't know that
let x = 5; without a specified type should assign
i32 (the default integral type) and use its implementation of
count_ones, it is just not that compilation stage yet - the default types are assigned after the method and function names are resolved.