error: missing type for `const` item

error: missing type for `static` item

const または static のアイテムで型推論を使おうとした。

原因

型推論の未対応箇所』によると、conststatic のアイテムでは型推論が使えない。

そのため、型を指定しないとエラーになる。

サンプル


pub const VAL = 1_i32;

error: missing type for `const` item
 --> src\lib.rs:1:14
  |
1 | pub const VAL = 1_i32;
  |              ^ help: provide a type for the constant: `: i32`

解決策

以下のように型を明示するとよい。


pub const VAL: i32 = 1_i32;