docs

你正在阅读 v0.1.2 的文档。Nabi 0.1.2 已不再提供支持。 最新版本:v0.1.3 →

本页尚未翻译,以下为英文原文。

#E0047: item used in the wrong form

An item is used in a form it does not have: an associated function called as a method (v.new() for T::new()), a method named without a call, a tuple struct built with {..} or a named one with (..), or a type used as a value. Write the form the message gives.

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`

Call the method, or wrap the call in a closure:

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

Related: E0046 no such method or associated item, E0052 value is not callable

Found a mistake? Edit this page on GitHub. Last updated