docs

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

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

#E0081: invalid const generic argument

A const generic argument has the wrong type or is out of range for its parameter. Pass a constant of the parameter's type.

nabi
struct Sep<const C: char> {}

let s = Sep::<97> {};
error[E0081]: const argument for `C: char` must be a `char`, found an integer
  --> main.nabi:3:9
   |
 3 | let s = Sep::<97> {};
   |         ^^^^^^^^^^^^

Pass a constant of the parameter's type:

nabi
struct Sep<const C: char> {}

let s = Sep::<'a'> {};
println("ok");
ok

A { .. } argument runs at compile time. When it panics, the error says so and carries the message (evaluating the const generic argument panicked: <message>): pass a value the const fn accepts, or a literal.

Related: E0082 wrong generic arguments, E0079 cannot evaluate at compile time

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