Kap*_*chu 16 pi ambiguous rust
考虑以下代码:
fn main() {
let i = f32::consts::PI;
}
Run Code Online (Sandbox Code Playgroud)
出现以下错误:
$ rustc --version
rustc 1.0.0 (a59de37e9 2015-05-13) (built 2015-05-14)
$ rustc -
<anon>:2:13: 2:28 error: ambiguous associated type; specify the type using the syntax `<f32 as Trait>::consts` [E0223]
<anon>:2 let i = f32::consts::PI;
^~~~~~~~~~~~~~~
error: aborting due to previous error
Run Code Online (Sandbox Code Playgroud)
f32,它没有关联. f32.<f32 as Trait>::consts语法?我以前从未见过它.Kap*_*chu 12
要解决这个问题,请添加use std::f32或使用std::f32::consts::PI,以便编译器知道我们在这里讨论模块 f32,而不是类型 f32.