From 5ab52b713294d7685b7e09b0f2ac2a1c94df6df4 Mon Sep 17 00:00:00 2001 From: est31 Date: Tue, 20 Sep 2022 04:28:31 +0200 Subject: [PATCH] Add example --- src/statements.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/statements.md b/src/statements.md index 42761809e..bf4745869 100644 --- a/src/statements.md +++ b/src/statements.md @@ -73,6 +73,17 @@ The `else` block has to always diverge (evaluate to type `!`). If an `else` block is present, restrictions apply on the expression: It might not be a [_LazyBooleanExpression_], or end in a `}` token. +```rust +let (mut v, w) = (vec![1, 2, 3], 42); // The bindings may be mut or const +let Some(t) = v.pop() else { // Refutable patterns require an else block + panic!(); // The else block has to diverge +}; +let [u, v] = [v[0], v[1]] else { // This pattern is irrefutable, so the compiler + // will lint as the else block is redundant. + panic!(); +}; +``` + ## Expression statements > **Syntax**\