docs

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

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

#E0024: invalid generic parameters

The generic parameter list breaks a rule: a parameter without a default after one with a default, a const parameter of a type that cannot be a constant, or a where clause that bounds something it cannot. Reorder or change the parameters as the message says.

nabi
struct Pair<T = i32, U> { a: T; b: U; }
error[E0024]: generic parameter `U` has no default but follows one that does; defaults must be trailing
  --> main.nabi:1:22
   |
 1 | struct Pair<T = i32, U> { a: T; b: U; }
   |                      ^

Put the parameters with defaults last:

nabi
struct Pair<U, T = i32> { a: T; b: U; }
let p: Pair<str> = Pair { a: 1, b: "x" };
println(f"{p.a} {p.b}");
1 x

Related: E0082 wrong generic arguments

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