Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No i32/f64 fallback when using pow()

Tags:

rust

With the following:

4.pow(2)

I get:

error: no method named `pow` found for type `_` in the current scope

I have to be more explicit about it, e.g.:

4_i32.pow(2)

With floats, I get a similar problem (and solution), where:

4.0.powf(2.0)

Must also be explicit:

4.0_f64.powf(2.0)
like image 773
tshepang Avatar asked May 23 '15 13:05

tshepang


1 Answers

I believe this is because the fallback only happens when all the constraints on the literal have been considered (and it finds that there aren't any).

In this case, to know what the type of 4 is, it has to know what pow is. But pow is defined separately for each integral type. So to know what pow you're talking about, it has to know what the type of 4 is. But to know what the type of 4 is... and so on.

like image 159
DK. Avatar answered Nov 09 '22 19:11

DK.