docs

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

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

#E0043: no such field

The type has no field of this name (or a tuple has no element at this index). Check the spelling against the type's definition.

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

let p = P { x: 1, y: 2 };
println(f"{p.z}");
error[E0043]: struct `P` has no field `z`
  --> main.nabi:4:12
   |
 4 | println(f"{p.z}");
   |            ^^^
   |
   = help: available fields: `x`, `y`

Use a field the type has; the help lists them:

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

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

Related: E0044 missing field in a literal, E0046 no such method or associated item

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