about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-04-27 15:10:52 +0200
committerGitHub <noreply@github.com>2023-04-27 15:10:52 +0200
commitc2a79fb490201e81b3d90191c8462dd2264ec174 (patch)
tree282bb70289ef3b9813e894b0cf6750ffcb0daee1 /src
parent6ce22733b973355573efd1e6294e585460e90e17 (diff)
parent0776a4bf27bd8fe813e33354b43b5b50e5469852 (diff)
downloadrust-c2a79fb490201e81b3d90191c8462dd2264ec174.tar.gz
rust-c2a79fb490201e81b3d90191c8462dd2264ec174.zip
Rollup merge of #110426 - calebcartwright:style-let-else-examples, r=compiler-errors
docs(style): add more let-else examples

Adding a few more examples for increased clarity based on subsequent discussion that arose after implementation work began.

Will need approval from t-style, but also cc ```@ytmimi``` to make sure these examples don't contradict any examples we've been incorporating as part of the rustfmt implementation
Diffstat (limited to 'src')
-rw-r--r--src/doc/style-guide/src/statements.md37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/doc/style-guide/src/statements.md b/src/doc/style-guide/src/statements.md
index 4ab1c36f976..671e6d31a57 100644
--- a/src/doc/style-guide/src/statements.md
+++ b/src/doc/style-guide/src/statements.md
@@ -138,18 +138,31 @@ Otherwise, the `else` keyword and opening brace should be placed on the next lin
 For example:
 
 ```rust
-let Some(x) = abcdef()
-    .foo(
-        "abc",
-        some_really_really_really_long_ident,
-        "ident",
-        "123456",
-    )
-    .bar()
-    .baz()
-    .qux("fffffffffffffffff")
-else {
-    foo_bar()
+fn main() {
+    let Some(x) = abcdef()
+        .foo(
+            "abc",
+            some_really_really_really_long_ident,
+            "ident",
+            "123456",
+        )
+        .bar()
+        .baz()
+        .qux("fffffffffffffffff")
+    else {
+        return
+    };
+
+    let Some(x) = some_really_really_really_really_really_really_really_really_really_long_name
+    else {
+        return;
+    };
+
+    let Some(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) =
+        bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
+    else {
+        return;
+    };
 }
 ```