docs

#E0044: 字面值缺少欄位

結構或變體的字面值漏掉了一個沒有預設值的欄位。替每個欄位提供值,或在結構中宣告預設值(n: i32 = 0)。

nabi
struct P { x: i32; y: i32; }

let p = P { x: 1 };
error[E0044]: struct `P` is missing field `y` and no default is declared
  --> main.nabi:3:9
   |
 3 | let p = P { x: 1 };
   |         ^^^^^^^^^^

替欄位提供值,或在結構中宣告預設值:

nabi
struct P { x: i32; y: i32 = 0; }

let p = P { x: 1 };
println(f"{p.y}");
0

相關錯誤碼:E0043 沒有這個欄位、E0045 重複指定的欄位

發現錯誤? 在 GitHub 上編輯此頁 最後更新: