docs

您正在閱讀 v0.1.0 的文件。Nabi 0.1.0 已停止支援。 最新版本:v0.1.3 →

本頁尚未翻譯,以下為英文原文。

#E0045: field given more than once

A struct literal names the same field twice. Remove one.

nabi
struct P { x: i32 }

let p = P { x: 1, x: 2 };
error[E0045]: field `x` specified more than once in `P` literal
  --> main.nabi:3:9
   |
 3 | let p = P { x: 1, x: 2 };
   |         ^^^^^^^^^^^^^^^^

Give the field once:

nabi
struct P { x: i32 }

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

Related: E0044 missing field in a literal, E0049 invalid named argument

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