From 47bb99df83d7d53ae536df42a9bf81ce93f67f4a Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Thu, 31 Oct 2024 13:39:15 +0000 Subject: [PATCH 1/2] Warn about the risks of using catch-all patterns This may not be obvious to people who have never experienced compiler-driven refactoring before, and feels worth calling out. --- book/src/05_ticket_v2/02_match.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/book/src/05_ticket_v2/02_match.md b/book/src/05_ticket_v2/02_match.md index 8541c7af50..806b089380 100644 --- a/book/src/05_ticket_v2/02_match.md +++ b/book/src/05_ticket_v2/02_match.md @@ -68,3 +68,10 @@ match status { ``` The `_` pattern matches anything that wasn't matched by the previous patterns. + +
+By using this catch-all pattern, you _won't_ get the benefits of compiler-driven refactoring.\ +If you add a new enum variant, the compiler _won't_ tell you that you're not handling it. + +In general, prefer to avoid catch-all patterns unless you're really sure future new variants should be handled the same way. +
From 530a9a37798a1ec640eb6f200992c0d2ec0b800a Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:04:48 +0100 Subject: [PATCH 2/2] Update 02_match.md --- book/src/05_ticket_v2/02_match.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/src/05_ticket_v2/02_match.md b/book/src/05_ticket_v2/02_match.md index 806b089380..905765073e 100644 --- a/book/src/05_ticket_v2/02_match.md +++ b/book/src/05_ticket_v2/02_match.md @@ -73,5 +73,5 @@ The `_` pattern matches anything that wasn't matched by the previous patterns. By using this catch-all pattern, you _won't_ get the benefits of compiler-driven refactoring.\ If you add a new enum variant, the compiler _won't_ tell you that you're not handling it. -In general, prefer to avoid catch-all patterns unless you're really sure future new variants should be handled the same way. +If you're keen on correctness, avoid using catch-alls. Leverage the compiler to re-examine all matching sites and determine how new enum variants should be handled.