Skip to content

A character or byte literal is not accepted as a match pattern ("expected pattern") #1295

Closed

Description

@ehartford

Found rewriting `examples/json-parser` under #1150 ruling 4 (its tokenizer matches the next byte).

§22 (Lexical) says character and byte literals are integer literal values (`'a'`, `b'X'`), and integer literals are patterns (§9.7). The parser rejects both in pattern position:

```
fn kind(ch: u8) -> i32:
match ch:
'{' => 1
b'"' => 2
_ => 0
```

```
error: expected pattern
--> j2.w:3:9
3 | '{' => 1
```

Also inside a constructor pattern (`Some(b'{') => ...`). Both literals work in expressions (`ch == b'{'`, `ch in [b' ', b'\t']`). Expected: a char/byte literal pattern matches the integer value, exactly like `123 => ...`. Installed `with v0.15.2.1-g478b26481`.

The example spells the arms as guards (`Some(ch) if ch == b'{' =>`) until this lands.

Activity

  1. added a commit that references this issue on Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions