Skip to content

Tweak irrefutable let else warning output#154325

Draft
WeiTheShinobi wants to merge 1 commit intorust-lang:mainfrom
WeiTheShinobi:tweak-let-else-output
Draft

Tweak irrefutable let else warning output#154325
WeiTheShinobi wants to merge 1 commit intorust-lang:mainfrom
WeiTheShinobi:tweak-let-else-output

Conversation

@WeiTheShinobi
Copy link
Contributor

Fixes #153454

Greeting!
This PR tweak diagnostic output for irrefutable-let-else patterns and adds a check for let a = Some(b) else {...}
Thanks for the review!

help: consider using `let Some(name) = case` to match on a specific variant
   |
LL -     let name = Some(case) else {
LL +     let Some(name) = case else {
   |

@rustbot
Copy link
Collaborator

rustbot commented Mar 24, 2026

Some changes occurred in match checking

cc @Nadrieril

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 24, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 24, 2026

r? @davidtwco

rustbot has assigned @davidtwco.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 13 candidates

@WeiTheShinobi WeiTheShinobi force-pushed the tweak-let-else-output branch from f9c1661 to 94d6023 Compare March 24, 2026 17:06
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-21-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
##[endgroup]
Executing "/scripts/stage_2_test_set1.sh"
+ /scripts/stage_2_test_set1.sh
+ '[' 1 == 1 ']'
+ echo 'PR_CI_JOB set; skipping tidy'
+ SKIP_TIDY='--skip tidy'
+ ../x.py --stage 2 test --skip tidy --skip compiler --skip src
PR_CI_JOB set; skipping tidy
##[group]Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.04s
##[endgroup]
---
11 warning: irrefutable `if let` pattern
-   --> $DIR/irrefutable-in-let-chains.rs:30:8
+   --> $DIR/irrefutable-in-let-chains.rs:30:12
13    |
14 LL |     if let Range { start: local_start, end: _ } = (None..Some(1)) {}
-    |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16    |
17    = note: this pattern will always match, so the `if let` is useless
18    = help: consider replacing the `if let` with a `let`
---
29 warning: irrefutable `if let` pattern
-   --> $DIR/irrefutable-in-let-chains.rs:49:15
+   --> $DIR/irrefutable-in-let-chains.rs:49:19
31    |
32 LL |     } else if let x = opt.clone().map(|_| 1) {
-    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+    |                   ^
34    |
35    = note: this pattern will always match, so the `if let` is useless
36    = help: consider replacing the `if let` with a `let`
---
To only update this specific test, also pass `--test-args binding/irrefutable-in-let-chains.rs`

error: 1 errors occurred comparing output.
status: exit status: 0
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/binding/irrefutable-in-let-chains.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/binding/irrefutable-in-let-chains" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "--edition=2024"
stdout: none
--- stderr -------------------------------
warning: irrefutable `if let` pattern
##[warning]  --> /checkout/tests/ui/binding/irrefutable-in-let-chains.rs:13:12
   |
---

warning: irrefutable `if let` pattern
##[warning]  --> /checkout/tests/ui/binding/irrefutable-in-let-chains.rs:30:12
   |
LL |     if let Range { start: local_start, end: _ } = (None..Some(1)) {}
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this pattern will always match, so the `if let` is useless
   = help: consider replacing the `if let` with a `let`

---

warning: irrefutable `if let` pattern
##[warning]  --> /checkout/tests/ui/binding/irrefutable-in-let-chains.rs:49:19
   |
LL |     } else if let x = opt.clone().map(|_| 1) {
   |                   ^
   |
   = note: this pattern will always match, so the `if let` is useless
   = help: consider replacing the `if let` with a `let`

---
To only update this specific test, also pass `--test-args closures/2229_closure_analysis/issue-88118-2.rs`

error: 1 errors occurred comparing output.
status: exit status: 0
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/closures/2229_closure_analysis/issue-88118-2.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "-O" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/closures/2229_closure_analysis/issue-88118-2/a" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "--edition=2021"
stdout: none
--- stderr -------------------------------
warning: irrefutable `if let` guard pattern
##[warning]  --> /checkout/tests/ui/closures/2229_closure_analysis/issue-88118-2.rs:9:29
   |
---
To only update this specific test, also pass `--test-args closures/2229_closure_analysis/migrations/issue-78720.rs`

error: 1 errors occurred comparing output.
status: exit status: 0
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/closures/2229_closure_analysis/migrations/issue-78720.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "-O" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/closures/2229_closure_analysis/migrations/issue-78720/a" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
warning: irrefutable `if let` pattern
##[warning]  --> /checkout/tests/ui/closures/2229_closure_analysis/migrations/issue-78720.rs:7:12
   |
---
1 warning: irrefutable `if let` pattern
-   --> $DIR/if-let.rs:6:16
+   --> $DIR/if-let.rs:17:10
3    |
- LL |               if let $p = $e $b
-    |                  ^^^^^^^^^^^
- ...
- LL | /     foo!(a, 1, {
- LL | |         println!("irrefutable pattern");
- LL | |     });
-    | |______- in this macro invocation
+ LL |     foo!(a, 1, {
+    |          ^
11    |
12    = note: this pattern will always match, so the `if let` is useless
13    = help: consider replacing the `if let` with a `let`

14    = note: `#[warn(irrefutable_let_patterns)]` on by default
-    = note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
16 
17 warning: irrefutable `if let` pattern
-   --> $DIR/if-let.rs:6:16
+   --> $DIR/if-let.rs:20:10
19    |
- LL |               if let $p = $e $b
-    |                  ^^^
- ...
- LL | /     bar!(a, 1, {
- LL | |         println!("irrefutable pattern");
- LL | |     });
-    | |______- in this macro invocation
+ LL |     bar!(a, 1, {
+    |          ^
27    |
28    = note: this pattern will always match, so the `if let` is useless
29    = help: consider replacing the `if let` with a `let`

---
-   --> /checkout/tests/ui/expr/if/if-let.rs:30:12
-   --> /checkout/tests/ui/expr/if/if-let.rs:40:19
-   --> /checkout/tests/ui/expr/if/if-let.rs:46:19
+   --> $DIR/if-let.rs:17:10
+ LL |     foo!(a, 1, {
+    |          ^
+   --> $DIR/if-let.rs:20:10
+ LL |     bar!(a, 1, {
+    |          ^
+   --> $DIR/if-let.rs:26:12
+    |            ^
+   --> $DIR/if-let.rs:30:12
+    |            ^
---
To only update this specific test, also pass `--test-args expr/if/if-let.rs`

error: 1 errors occurred comparing output.
status: exit status: 0
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/expr/if/if-let.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/expr/if/if-let" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
warning: irrefutable `if let` pattern
##[warning]  --> /checkout/tests/ui/expr/if/if-let.rs:17:10
   |
LL |     foo!(a, 1, {
   |          ^
   |
   = 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: irrefutable `if let` pattern
##[warning]  --> /checkout/tests/ui/expr/if/if-let.rs:20:10
   |
LL |     bar!(a, 1, {
   |          ^
   |
   = note: this pattern will always match, so the `if let` is useless
   = help: consider replacing the `if let` with a `let`

warning: irrefutable `if let` pattern
##[warning]  --> /checkout/tests/ui/expr/if/if-let.rs:26:12
   |
LL |     if let a = 1 { //~ WARN irrefutable `if let`
   |            ^
   |
   = note: this pattern will always match, so the `if let` is useless
   = help: consider replacing the `if let` with a `let`

warning: irrefutable `if let` pattern
##[warning]  --> /checkout/tests/ui/expr/if/if-let.rs:30:12
   |
LL |     if let a = 1 { //~ WARN irrefutable `if let`
   |            ^
   |
   = note: this pattern will always match, so the `if let` is useless
   = help: consider replacing the `if let` with a `let`

warning: irrefutable `if let` pattern
##[warning]  --> /checkout/tests/ui/expr/if/if-let.rs:40:19
   |
LL |     } else if let a = 1 { //~ WARN irrefutable `if let`
   |                   ^
   |
   = note: this pattern will always match, so the `if let` is useless
   = help: consider replacing the `if let` with a `let`

warning: irrefutable `if let` pattern
##[warning]  --> /checkout/tests/ui/expr/if/if-let.rs:46:19
   |
LL |     } else if let a = 1 { //~ WARN irrefutable `if let`
   |                   ^
   |
   = note: this pattern will always match, so the `if let` is useless
   = help: consider replacing the `if let` with a `let`

warning: 6 warnings emitted
------------------------------------------

---- [ui] tests/ui/expr/if/if-let.rs stdout end ----
---- [ui] tests/ui/for-loop-while/while-let-2.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/for-loop-while/while-let-2/while-let-2.stderr`
diff of stderr:

1 warning: irrefutable `while let` pattern
-   --> $DIR/while-let-2.rs:7:19
+   --> $DIR/while-let-2.rs:18:10
3    |
- LL |               while let $p = $e $b
-    |                     ^^^^^^^^^^^
- ...
- LL | /     foo!(_a, 1, {
- LL | |         println!("irrefutable pattern");
- LL | |     });
-    | |______- in this macro invocation
+ LL |     foo!(_a, 1, {
+    |          ^^
11    |
12    = note: this pattern will always match, so the loop will never exit
13    = help: consider instead using a `loop { ... }` with a `let` inside it

14    = note: `#[warn(irrefutable_let_patterns)]` on by default
-    = note: this warning originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
16 
17 warning: irrefutable `while let` pattern
-   --> $DIR/while-let-2.rs:7:19
+   --> $DIR/while-let-2.rs:21:10
19    |
- LL |               while let $p = $e $b
-    |                     ^^^
- ...
- LL | /     bar!(_a, 1, {
- LL | |         println!("irrefutable pattern");
- LL | |     });
-    | |______- in this macro invocation
+ LL |     bar!(_a, 1, {
+    |          ^^
27    |
28    = note: this pattern will always match, so the loop will never exit
29    = help: consider instead using a `loop { ... }` with a `let` inside it

-    = note: this warning originates in the macro `foo` which comes from the expansion of the macro `bar` (in Nightly builds, run with -Z macro-backtrace for more info)
31 
32 warning: irrefutable `while let` pattern
-   --> $DIR/while-let-2.rs:27:11
+   --> $DIR/while-let-2.rs:27:15
34    |
35 LL |     while let _a = 1 {
-    |           ^^^^^^^^^^
+    |               ^^
37    |
38    = note: this pattern will always match, so the loop will never exit
39    = help: consider instead using a `loop { ... }` with a `let` inside it

Note: some mismatched output was normalized before being compared
-   --> /checkout/tests/ui/for-loop-while/while-let-2.rs:18:10
-   --> /checkout/tests/ui/for-loop-while/while-let-2.rs:21:10
-   --> /checkout/tests/ui/for-loop-while/while-let-2.rs:27:15
+   --> $DIR/while-let-2.rs:18:10
+ LL |     foo!(_a, 1, {
+    |          ^^
+   --> $DIR/while-let-2.rs:21:10
+ LL |     bar!(_a, 1, {
+    |          ^^
+   --> $DIR/while-let-2.rs:27:15
+    |               ^^


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args for-loop-while/while-let-2.rs`

error: 1 errors occurred comparing output.
status: exit status: 0
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/for-loop-while/while-let-2.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "-O" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/for-loop-while/while-let-2/a" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
warning: irrefutable `while let` pattern
##[warning]  --> /checkout/tests/ui/for-loop-while/while-let-2.rs:18:10
   |
LL |     foo!(_a, 1, {
   |          ^^
   |
   = note: this pattern will always match, so the loop will never exit
   = help: consider instead using a `loop { ... }` with a `let` inside it
   = note: `#[warn(irrefutable_let_patterns)]` on by default

warning: irrefutable `while let` pattern
##[warning]  --> /checkout/tests/ui/for-loop-while/while-let-2.rs:21:10
   |
LL |     bar!(_a, 1, {
   |          ^^
   |
   = note: this pattern will always match, so the loop will never exit
   = help: consider instead using a `loop { ... }` with a `let` inside it

warning: irrefutable `while let` pattern
##[warning]  --> /checkout/tests/ui/for-loop-while/while-let-2.rs:27:15
   |
LL |     while let _a = 1 { //~ WARN irrefutable `while let`
   |               ^^
   |
   = note: this pattern will always match, so the loop will never exit
   = help: consider instead using a `loop { ... }` with a `let` inside it

---
13 error: irrefutable `if let` guard pattern
-   --> $DIR/lint-match-arms-2.rs:17:14
+   --> $DIR/lint-match-arms-2.rs:17:18
15    |
16 LL |         a if let b = a => {}
-    |              ^^^^^^^^^
+    |                  ^
18    |
19    = note: this pattern will always match, so the guard is useless
20    = help: consider removing the guard and adding a `let` inside the match arm
---
To only update this specific test, also pass `--test-args lint/lint-match-arms-2.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/lint/lint-match-arms-2.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/lint/lint-match-arms-2" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error[E0170]: pattern binding `A` is named the same as one of the variants of the type `E`
##[error]  --> /checkout/tests/ui/lint/lint-match-arms-2.rs:11:9
   |
LL |         A => {}
   |         ^ help: to match on the variant, qualify the path: `E::A`
   |
note: the lint level is defined here
  --> /checkout/tests/ui/lint/lint-match-arms-2.rs:10:16
   |
LL |         #[deny(bindings_with_variant_name)]
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: irrefutable `if let` guard pattern
##[error]  --> /checkout/tests/ui/lint/lint-match-arms-2.rs:17:18
   |
LL |         a if let b = a => {}
   |                  ^
   |
   = note: this pattern will always match, so the guard is useless
   = help: consider removing the guard and adding a `let` inside the match arm
note: the lint level is defined here
---
To only update this specific test, also pass `--test-args nll/match-cfg-fake-edges.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/nll/match-cfg-fake-edges.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/nll/match-cfg-fake-edges" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
warning: irrefutable `if let` pattern
##[warning]  --> /checkout/tests/ui/nll/match-cfg-fake-edges.rs:17:12
   |
LL |     if let _ = true { //~ WARN irrefutable
   |            ^
   |
   = 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
---

error[E0382]: borrow of moved value: `x.0`
##[error]  --> /checkout/tests/ui/nll/match-cfg-fake-edges.rs:28:5
   |
LL |         (y, _) | (_, y) => (),
   |          - value moved here
LL |     }
LL |     &x.0; //~ ERROR borrow of moved value
   |     ^^^^ value borrowed here after move
   |
   = note: move occurs because `x.0` has type `String`, which does not implement the `Copy` trait
help: borrow this binding in the pattern to avoid moving the value
   |
LL |         (ref y, _) | (_, y) => (),
   |          +++

error[E0382]: borrow of moved value: `x.1`
##[error]  --> /checkout/tests/ui/nll/match-cfg-fake-edges.rs:30:5
   |
LL |         (y, _) | (_, y) => (),
   |                      - value moved here
...
LL |     &x.1; //~ ERROR borrow of moved value
   |     ^^^^ value borrowed here after move
   |
   = note: move occurs because `x.1` has type `String`, which does not implement the `Copy` trait
help: borrow this binding in the pattern to avoid moving the value
   |
LL |         (y, _) | (_, ref y) => (),
   |                      +++

error[E0382]: borrow of moved value: `x.0`
##[error]  --> /checkout/tests/ui/nll/match-cfg-fake-edges.rs:34:5
   |
LL |     let ((y, _) | (_, y)) = x;
   |           - value moved here
LL |     &x.0; //~ ERROR borrow of moved value
   |     ^^^^ value borrowed here after move
   |
   = note: move occurs because `x.0` has type `String`, which does not implement the `Copy` trait
help: borrow this binding in the pattern to avoid moving the value
   |
LL |     let ((ref y, _) | (_, y)) = x;
   |           +++

error[E0382]: borrow of moved value: `x.1`
##[error]  --> /checkout/tests/ui/nll/match-cfg-fake-edges.rs:36:5
   |
LL |     let ((y, _) | (_, y)) = x;
   |                       - value moved here
...
LL |     &x.1; //~ ERROR borrow of moved value
   |     ^^^^ value borrowed here after move
   |
   = note: move occurs because `x.1` has type `String`, which does not implement the `Copy` trait
help: borrow this binding in the pattern to avoid moving the value
   |
LL |     let ((y, _) | (_, ref y)) = x;
   |                       +++

error[E0381]: used binding `x` is possibly-uninitialized
##[error]  --> /checkout/tests/ui/nll/match-cfg-fake-edges.rs:70:19
   |
LL |     let x;
   |         - binding declared here but left uninitialized
...
LL |         _ => drop(x), //~ ERROR used binding `x` is possibly-uninitialized
   |         -         ^ `x` used here but it is possibly-uninitialized
   |         |
   |         if this pattern is matched, `x` is not initialized

error[E0381]: used binding `x` isn't initialized
##[error]  --> /checkout/tests/ui/nll/match-cfg-fake-edges.rs:77:16
   |
LL |     let x;
   |         - binding declared here but left uninitialized
LL |     match y {
LL |         _ if { x = 2; true } => 1,
   |                ----- binding initialized here in some conditions
LL |         // Borrowck must not know the guard is always run.
LL |         _ if { x; false } => 2, //~ ERROR used binding `x` isn't initialized
   |                ^ `x` used here but it isn't initialized
   |
help: consider assigning a value
   |
LL |     let x = 42;
   |           ++++

error[E0381]: used binding `x` isn't initialized
##[error]  --> /checkout/tests/ui/nll/match-cfg-fake-edges.rs:84:31
   |
LL |     let x;
   |         - binding declared here but left uninitialized
LL |     match y {
LL |         _ if let Some(()) = { x = 2; Some(()) } => 1,
   |                               ----- binding initialized here in some conditions
LL |         _ if let Some(()) = { x; None } => 2, //~ ERROR used binding `x` isn't initialized
   |                               ^ `x` used here but it isn't initialized
   |
help: consider assigning a value
   |
LL |     let x = 42;
   |           ++++

error[E0382]: use of moved value: `x`
##[error]  --> /checkout/tests/ui/nll/match-cfg-fake-edges.rs:97:22
   |
LL |     let x = String::new();
   |         - move occurs because `x` has type `String`, which does not implement the `Copy` trait
LL |     match y {
LL |         false if { drop(x); true } => {},
   |                         - value moved here
LL |         // Borrowck must not know the guard is not run in the `true` case.
LL |         true => drop(x), //~ ERROR use of moved value: `x`
   |                      ^ value used here after move
   |
help: consider cloning the value if the performance cost is acceptable
   |
LL |         false if { drop(x.clone()); true } => {},
   |                          ++++++++

error[E0382]: use of moved value: `x`
##[error]  --> /checkout/tests/ui/nll/match-cfg-fake-edges.rs:112:22
   |
LL |     let x = String::new();
   |         - move occurs because `x` has type `String`, which does not implement the `Copy` trait
LL |     match y {
LL |         false if let Some(()) = { drop(x); Some(()) } => {},
   |                                        - value moved here
LL |         true => drop(x), //~ ERROR use of moved value: `x`
   |                      ^ value used here after move
   |
help: consider cloning the value if the performance cost is acceptable
   |
LL |         false if let Some(()) = { drop(x.clone()); Some(()) } => {},
   |                                         ++++++++

error: aborting due to 11 previous errors; 1 warning emitted

Some errors have detailed explanations: E0381, E0382.
---
24 error: irrefutable `if let` guard pattern
-   --> $DIR/deny-irrefutable-let-patterns.rs:11:14
+   --> $DIR/deny-irrefutable-let-patterns.rs:11:18
26    |
27 LL |         _ if let _ = 2 => {}
-    |              ^^^^^^^^^
+    |                  ^
29    |
30    = note: this pattern will always match, so the guard is useless
31    = help: consider removing the guard and adding a `let` inside the match arm
---
To only update this specific test, also pass `--test-args pattern/usefulness/deny-irrefutable-let-patterns.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/pattern/usefulness/deny-irrefutable-let-patterns.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/pattern/usefulness/deny-irrefutable-let-patterns" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: irrefutable `if let` pattern
##[error]  --> /checkout/tests/ui/pattern/usefulness/deny-irrefutable-let-patterns.rs:4:12
   |
LL |     if let _ = 5 {} //~ ERROR irrefutable `if let` pattern
   |            ^
   |
   = note: this pattern will always match, so the `if let` is useless
   = help: consider replacing the `if let` with a `let`
note: the lint level is defined here
---

error: irrefutable `while let` pattern
##[error]  --> /checkout/tests/ui/pattern/usefulness/deny-irrefutable-let-patterns.rs:6:15
   |
LL |     while let _ = 5 { //~ ERROR irrefutable `while let` pattern
   |               ^
   |
   = note: this pattern will always match, so the loop will never exit
   = help: consider instead using a `loop { ... }` with a `let` inside it

error: irrefutable `if let` guard pattern
##[error]  --> /checkout/tests/ui/pattern/usefulness/deny-irrefutable-let-patterns.rs:11:18
   |
LL |         _ if let _ = 2 => {} //~ ERROR irrefutable `if let` guard pattern
   |                  ^
   |
   = note: this pattern will always match, so the guard is useless
   = help: consider removing the guard and adding a `let` inside the match arm

---
15 error: irrefutable `if let` guard pattern
-   --> $DIR/warns.rs:13:14
+   --> $DIR/warns.rs:13:18
17    |
18 LL |         o if let x = 0 => {}
-    |              ^^^^^^^^^
+    |                  ^
20    |
21    = note: this pattern will always match, so the guard is useless
22    = help: consider removing the guard and adding a `let` inside the match arm
---
To only update this specific test, also pass `--test-args rfcs/rfc-2294-if-let-guard/warns.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/rfcs/rfc-2294-if-let-guard/warns.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/rfcs/rfc-2294-if-let-guard/warns" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: irrefutable `if let` guard pattern
##[error]  --> /checkout/tests/ui/rfcs/rfc-2294-if-let-guard/warns.rs:4:24
   |
---

error: irrefutable `if let` guard pattern
##[error]  --> /checkout/tests/ui/rfcs/rfc-2294-if-let-guard/warns.rs:13:18
   |
LL |         o if let x = 0 => {}
   |                  ^
   |
   = note: this pattern will always match, so the guard is useless
   = help: consider removing the guard and adding a `let` inside the match arm
note: the lint level is defined here
---

error: unreachable pattern
##[error]  --> /checkout/tests/ui/rfcs/rfc-2294-if-let-guard/warns.rs:30:25
   |
LL |         x if let None | None = x => {}
   |                  ----   ^^^^ no value can reach this
   |                  |
   |                  matches all the relevant values
   |
note: the lint level is defined here
---
1 warning: irrefutable `if let` pattern
-   --> $DIR/let-offset-of.rs:14:8
+   --> $DIR/let-offset-of.rs:14:12
3    |
4 LL |     if let x = offset_of!(Foo, field) {}
-    |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+    |            ^
6    |
7    = note: this pattern will always match, so the `if let` is useless
8    = help: consider replacing the `if let` with a `let`
---
-   --> $DIR/let-offset-of.rs:17:5
+ warning: unreachable `else` clause
+   --> $DIR/let-offset-of.rs:17:36
13    |
14 LL |     let x = offset_of!(Foo, field) else { return; };
-    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+    |         -                          ^^^^
+    |         |
+    |         assigning to binding pattern will always succeed
16    |
17    = note: this pattern always matches, so the else clause is unreachable
- help: remove this `else` block
-   --> $DIR/let-offset-of.rs:17:41
-    |
- LL |     let x = offset_of!(Foo, field) else { return; };
-    |                                         ^^^^^^^^^^^
23 
24 warning: 2 warnings emitted
25 

---
To only update this specific test, also pass `--test-args span/let-offset-of.rs`

error: 1 errors occurred comparing output.
status: exit status: 0
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/span/let-offset-of.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/span/let-offset-of" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers" "--edition=2024"
stdout: none
--- stderr -------------------------------
warning: irrefutable `if let` pattern
##[warning]  --> /checkout/tests/ui/span/let-offset-of.rs:14:12
   |
LL |     if let x = offset_of!(Foo, field) {}
   |            ^
   |
   = 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: unreachable `else` clause
##[warning]  --> /checkout/tests/ui/span/let-offset-of.rs:17:36
   |
LL |     let x = offset_of!(Foo, field) else { return; };
   |         -                          ^^^^
   |         |
   |         assigning to binding pattern will always succeed
   |
   = note: this pattern always matches, so the else clause is unreachable

@WeiTheShinobi WeiTheShinobi marked this pull request as draft March 24, 2026 17:48
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tweak irrefutable let else warning output

4 participants