Code Fix

中級E0072: recursive type has infinite size の原因と直し方 › パターン5

E0072: recursive type has infinite size の原因と直し方

構造体が自分自身の型を直接フィールドに持つと、サイズが無限になってしまいコンパイルエラーになります。

 1  struct Frame {
 2      depth: i32,
 3      parent: __________________,
                         ^
 4  }
 5  fn main() {
 6      let n = Frame { depth: 1, parent: None };
 7      println!("{}", n.depth);
 8  }
error[E0072]: recursive type `Frame` has infinite size

空欄を埋めて実行を通す

広告
広告スロット(未設定)

E0072: recursive type has infinite size の原因と直し方

Boxなどのポインタ経由の間接参照を挟むことで、サイズを確定させる必要があります。

このエラーの解説と類題をまとめて見る →

広告
広告スロット(未設定)