docs

#E0047: 以错误的形式使用项

以项所没有的形式使用了它:把关联函数当作方法调用(用 v.new() 代替 T::new())、只写方法名而没有调用、用 {..} 构造元组结构体或用 (..) 构造具名结构体,或者把类型当作值使用。按消息给出的形式书写。

nabi
struct P { a: i32; }
impl P { fn get(self) -> i32 { self.a } }

let p = P { a: 3 };
let f = p.get;
error[E0047]: `p.get` names a method without calling it; `.method` is not a function value
  --> main.nabi:5:9
   |
 5 | let f = p.get;
   |         ^^^^^
   |
   = help: call it (`p.get(..)`), wrap it in a closure (`|..| p.get(..)`), or use the method path `P::get`

调用这个方法,或者把调用包在闭包里:

nabi
struct P { a: i32; }
impl P { fn get(self) -> i32 { self.a } }

let p = P { a: 3 };
let f = || p.get();
println(f"{f()}");
3

相关错误码:E0046 没有这个方法或关联项,E0052 值不可调用

发现错误? 在 GitHub 上编辑此页 最后更新: