Code Fix

上級E0004: non-exhaustive patterns の原因と直し方 › パターン3

E0004: non-exhaustive patterns の原因と直し方

match式は、値が取りうるすべてのパターンを網羅していなければコンパイルできません。

 1  enum Weather { Sunny, Rainy, Cloudy }
 2  fn main() {
 3      let w = Weather::Rainy;
 4      let msg = match w {
 5          Weather::Sunny => "bring sunscreen",
 6          ______________________________________________________________________________
                                                   ^
 7      };
 8      println!("{}", msg);
 9  }
error[E0004]: non-exhaustive patterns: `Weather::Cloudy` not covered

空欄を埋めて実行を通す

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

E0004: non-exhaustive patterns の原因と直し方

一部のケースだけを書いて残りを省略すると、E0004エラーになります。

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

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