本頁尚未翻譯,以下為英文原文。
#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