docs

#E0081: 無效的常數泛型引數

常數泛型引數的型別錯誤,或超出其參數的範圍。請傳入參數型別的常數。

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> {};
   |         ^^^^^^^^^^^^

傳入參數型別的常數:

nabi
struct Sep<const C: char> {}

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

{ .. } 引數會在編譯時期執行。它觸發 panic 時,錯誤會說明這一點並附上訊息(evaluating the const generic argument panicked: <message>):請傳入 const fn 接受的值,或傳入字面值。

相關錯誤碼:E0082 錯誤的泛型引數、E0079 無法在編譯時期求值

發現錯誤? 在 GitHub 上編輯此頁 最後更新: