rust/tests/ui/binding
Guillaume Boisseau cc7edbc1e4
Rollup merge of #120479 - estebank:issue-61788, r=wesleywiser
Suggest turning `if let` into irrefutable `let` if appropriate

When encountering an `if let` tail expression without an `else` arm for an enum with a single variant, suggest writing an irrefutable `let` binding instead.

```
error[E0317]: `if` may be missing an `else` clause
  --> $DIR/irrefutable-if-let-without-else.rs:8:5
   |
LL |   fn foo(x: Enum) -> i32 {
   |                      --- expected `i32` because of this return type
LL | /     if let Enum::Variant(value) = x {
LL | |         value
LL | |     }
   | |_____^ expected `i32`, found `()`
   |
   = note: `if` expressions without `else` evaluate to `()`
   = help: consider adding an `else` block that evaluates to the expected type
help: consider using an irrefutable `let` binding instead
   |
LL ~     let Enum::Variant(value) = x;
LL ~         value
   |
```

Fix #61788.
2024-02-07 18:24:43 +01:00
..
ambiguity-item.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
ambiguity-item.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
bind-field-short-with-modifiers.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
borrowed-ptr-pattern-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
borrowed-ptr-pattern-3.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
borrowed-ptr-pattern-infallible.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
borrowed-ptr-pattern-option.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
borrowed-ptr-pattern.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
const-param.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
const-param.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
empty-types-in-patterns.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
exhaustive-bool-match-sanity.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
expr-match-generic-unique1.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
expr-match-generic-unique2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
expr-match-generic.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
expr-match-panic-all.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
expr-match-panic.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
expr-match-unique.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
expr-match.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
fat-arrow-match.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
fn-arg-incomplete-pattern-drop-order.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
fn-pattern-expected-type-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
fn-pattern-expected-type.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
func-arg-incomplete-pattern.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
func-arg-ref-pattern.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
func-arg-wild-pattern.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
if-let.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
inconsistent-lifetime-mismatch.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
inferred-suffix-in-pattern-range.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
irrefutable-if-let-without-else.fixed Suggest turnging if let into irrefutable let if appropriate 2024-02-06 03:53:06 +00:00
irrefutable-if-let-without-else.rs Suggest turnging if let into irrefutable let if appropriate 2024-02-06 03:53:06 +00:00
irrefutable-if-let-without-else.stderr Suggest turnging if let into irrefutable let if appropriate 2024-02-06 03:53:06 +00:00
irrefutable-slice-patterns.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-53114-borrow-checks.rs Add diverging match guard test. 2023-10-24 15:30:17 +00:00
issue-53114-safety-checks.rs Ignore AscribeUserType in unsafeck to avoid duplicate diagnostics. 2023-03-09 17:45:13 +00:00
issue-53114-safety-checks.stderr Stabilize THIR unsafeck 2024-01-05 10:00:59 +00:00
let-assignability.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
let-destruct-ref.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
let-var-hygiene.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-arm-statics.rs Remove asmjs from tests 2023-10-28 23:11:03 -07:00
match-beginning-vert.rs Add more if let guard tests 2023-09-19 12:48:40 +00:00
match-borrowed_str.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-bot-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-bot.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-byte-array-patterns.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-enum-struct-0.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-enum-struct-1.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-implicit-copy-unique.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-in-macro.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-join.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-larger-const.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-naked-record-expr.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-naked-record.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-path.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-pattern-bindings.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-pattern-lit.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-pattern-no-type-params.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-pattern-simple.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-phi.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-pipe-binding.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-range-infer.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-range-static.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-range.rs remove illegal_floating_point_literal_pattern lint 2024-01-26 17:25:02 +01:00
match-reassign.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-ref-binding-in-guard-3256.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-ref-binding-mut-option.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-ref-binding-mut.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-ref-binding.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-ref-unsized.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-str.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-struct-0.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-tag.rs Adjust compiler tests for unused_tuple_struct_fields -> dead_code 2024-01-02 15:34:37 -05:00
match-unique-bind.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-unsized.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-value-binding-in-guard-3291.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-var-hygiene.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-vec-alternatives.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-vec-rvalue.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
match-with-ret-arm.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
multi-let.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
mut-in-ident-patterns.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
nested-matchs.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
nested-pattern.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
nil-pattern.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
nullary-or-pattern.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
optional_comma_in_match_arm.rs remove invalid ignore-pretty 2023-04-03 09:24:11 +02:00
or-pattern.rs Adjust compiler tests for unused_tuple_struct_fields -> dead_code 2024-01-02 15:34:37 -05:00
order-drop-with-match.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pat-ranges.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pat-tuple-1.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pat-tuple-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pat-tuple-3.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pat-tuple-4.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pat-tuple-5.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pat-tuple-6.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pat-tuple-7.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pattern-bound-var-in-for-each.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
pattern-in-closure.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
range-inclusive-pattern-precedence.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
shadow.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
simple-generic-match.rs Adjust compiler tests for unused_tuple_struct_fields -> dead_code 2024-01-02 15:34:37 -05:00
use-uninit-match2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
use-uninit-match.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
zero_sized_subslice_match.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00