我想使用float::consts::pi
. 例如:
import float::consts::pi;
const pi2:float = pi*pi;
fn main() {
io::println(#fmt("pi^2=%.4f", pi2));
}
我收到这些错误:
pi2.rs:3:18: 3:20 error: constant contains unimplemented expression type
pi2.rs:3 const pi2:float = pi*pi;
^~
pi2.rs:3:21: 3:23 error: constant contains unimplemented expression type
pi2.rs:3 const pi2:float = pi*pi;
^~
如果我写,编译成功:
const pi2:float = 3.14*3.14;
但如果我定义自己的,则不是pi
:
const pi:float = 3.141592653589793;
const pi2:float = pi*pi;
我正在使用 rust-0.2。
更新。rust-0.3.1 中的消息更友好,并确认该功能尚未实现。现在允许引用相同的板条箱常量:
$ rustc pi2.rs
pi2.rs:2:18: 2:20 error: paths in constants may only refer to crate-local constants
pi2.rs:2 const pi2:float = pi*pi;
^~
pi2.rs:2:21: 2:23 error: paths in constants may only refer to crate-local constants
pi2.rs:2 const pi2:float = pi*pi;
^~
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=0,::rt::backtrace to get further details and report the results to github.com/mozilla/rust/issues