Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ch18-02-refutabilityのビルド結果が異なっている #231

Open
pea-sys opened this issue Jan 26, 2023 · 0 comments
Open

ch18-02-refutabilityのビルド結果が異なっている #231

pea-sys opened this issue Jan 26, 2023 · 0 comments

Comments

@pea-sys
Copy link

pea-sys commented Jan 26, 2023

次のコードをビルドすると

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant