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 上編輯此頁 最後更新: