From 4ffe3d83b80e3a9349e8be583450e07f8ec99be1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=C3=A4schle?= Date: Tue, 12 Jan 2021 12:10:44 +0100 Subject: [PATCH] docs: update match as syntax (#8056) --- doc/docs.md | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/doc/docs.md b/doc/docs.md index cdc7d93fd3..db285aa1de 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -1975,10 +1975,6 @@ fn land(w World) { `match` must have a pattern for each variant or have an `else` branch. -There are two ways to access the cast variant inside a match branch: -- the shadowed match variable -- using `as` to specify a variable name - ```v ignore struct Moon {} struct Mars {} @@ -1997,21 +1993,9 @@ fn pass_time(w World) { Mars { w.shiver() } else {} } - // using `as` to specify a name for each value - match w as var { - Mars { var.shiver() } - Venus { var.sweat() } - else { - // w is of type World - assert w is Moon - } - } } ``` -Note: shadowing only works when the match expression is a variable. -It will not work on struct fields, array indexes, or map keys. - ### Option/Result types and error handling Option types are declared with `?Type`: