-
Notifications
You must be signed in to change notification settings - Fork 104
Open
Description
次のコードをビルドすると
if let x = 5 {
println!("{}", x);
};
次のように出力されると記載があります。
error[E0162]: irrefutable if-let pattern
(エラー: 論駁不可能なif-letパターン)
--> <anon>:2:8
|
2 | if let x = 5 {
| ^ irrefutable pattern
実際には次のようになりました。
cargo run
warning: irrefutable `if let` pattern
--> src\main.rs:2:8
|
2 | if let x = 5 {
| ^^^^^^^^^
|
= note: this pattern will always match, so the `if let` is useless
= help: consider replacing the `if let` with a `let`
= note: `#[warn(irrefutable_let_patterns)]` on by default
warning: `testing` (bin "testing") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.03s
Running `target\debug\testing.exe`
5
英語版も実際の動作に一致する内容で記載されています。
https://doc.rust-lang.org/book/ch18-02-refutability.html
$ cargo run
Compiling patterns v0.1.0 (file:///projects/patterns)
warning: irrefutable `if let` pattern
--> src/main.rs:2:8
|
2 | if let x = 5 {
| ^^^^^^^^^
|
= note: `#[warn(irrefutable_let_patterns)]` on by default
= note: this pattern will always match, so the `if let` is useless
= help: consider replacing the `if let` with a `let`
warning: `patterns` (bin "patterns") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.39s
Running `target/debug/patterns`
5
Metadata
Metadata
Assignees
Labels
No labels