上級 › 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
空欄を埋めて実行を通す
switch文がフォールスルーする言語と違い、Rustのmatchは網羅性チェックが必須です。
次の問題