Q:

Rust: "the type of this value must be known in this context" error for Float::pi

I have the following line of code which I expect to just work:
const pi_n4th_root : f32 = Float::pi().powf(-1.0/4.0);

but it produces the following error:
f.rs:7:28: 7:54 error: the type of this value must be known in this context
f.rs:7 const pi_n4th_root : f32 = Float::pi().powf(-1.0/4.0);
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~

I tried to add every type annotation that I can:
const pi_n4th_root : f32 = (Float::pi() as f32).powf(-1.0/4.0 as f32) as f32;

but it still fails with the same error:
f.rs:7:30: 9:55 error: the type of this value must be known in this context
f.rs:7 const pi_m4th_root : f32 = (Float::pi::<f32>() as f32).powf(-1.0/4.0 as f32) as f32;
                                   ^~~~~~~~~~~~~~~~~~~~~~~~~

Seems that I need to specify somehow that Float::pi is called for the f32 type but how to do that?

A:

Unfortunately, what you want to do won't work for two reasons.
First, you can't write anything like this:
const pi_n4th_root : f32 = Float::pi().powf(-1.0/4.0);

That is, you can't call any functions in constant definitions, because exact values of constants should be known to the compiler, and Rust does not have compile-time function evaluation yet.
Second, as UFCS is not yet implemented, you cannot invoke trait methods for some specific type directly. I'm not sure why Float::pi() as f32 does not work, but you can't specify desired type in paths too. The only way to do it would be writing a separate function:
#[inline]
pub fn pi<T: Float>() -> T { Float::pi() }

There are many such functions in Rust standard library. For Pi constant, however, there is a better way - you can use the constant of appropriate type directly:
use std::f32;

let pi = f32::consts::PI;

You can find a list of constants here and here (you can press [src] link if the page itself is empty, seems to be a bug in Rustdoc).

