You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/patterns.md
+23Lines changed: 23 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -257,6 +257,28 @@ Its objective is exclusively to make the matched binding a reference, instead of
257
257
r[patterns.ident.precedent]
258
258
[Path patterns](#path-patterns) take precedence over identifier patterns.
259
259
260
+
> [!NOTE]
261
+
> When a pattern is a single-segment identifier, the grammar is ambiguous whether it means an [IdentifierPattern] or a [PathPattern]. This ambiguity can only be resolved after [name resolution]. In the following example, the pattern is disambiguated to mean a PathPattern to a constant:
262
+
>
263
+
> ```rust
264
+
> constEXPECTED_VALUE:i32=42;
265
+
>
266
+
> fncheck_value(x:i32) ->bool {
267
+
> matchx {
268
+
> EXPECTED_VALUE=>true, // PathPattern - matches the constant 42
269
+
> _=>false,
270
+
> }
271
+
> }
272
+
>
273
+
> fnmain() {
274
+
> // If EXPECTED_VALUE were treated as an IdentifierPattern, it would bind
275
+
> // any value to a new variable, making this function always return true
0 commit comments