rust-lang / rust-lang/rust

Range patterns that cover the full range, and unit struct/variant patterns do not "read the value"

Open
#153,400 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-patterns C-bug T-lang T-opsem
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

See https://github.com/rust-lang/miri/issues/4237 for a previous similar issue.

I tried this code:

fn main() {
    let c: char;
    let char::MIN..=char::MAX = c;
}

I expected a compile error. Instead, the code compiled without errors.

My mental model is that matching against char::MIN..=char::MAX should at least "verify" that the bit pattern is a valid char, not to mention uninitialized bytes. Therefore, the pattern should "read" from c, and produce a compile error.

This also has an effect on opsem. For example, Miri doesn't report UB in the following code:

enum Foo {
    A(char), // valid values: 0..=0x10FFFF
    B,       // valid value:      0x110000
}
fn main() {
    unsafe {
        let x: u32 = 0x110001;
        let invalid: *const Foo = (&raw const x).cast();
        match *invalid {
            Foo::B => {}
            Foo::A(ref c @ char::MIN..=char::MAX) => {}
        }
    }
}

See https://github.com/rust-lang/rust/issues/91095 for more context about how niches work in opsem.

Meta

Reproducible on the playground with version 1.96.0-nightly (2026-03-03 d9563937fa3b030c5845)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two Rust examples from the issue on the stated nightly version, then read the related discussions in rust-lang/miri#4237 and rust-lang/rust#91095. Determine the intended pattern-matching and opsem behavior for full-range and unit struct/variant patterns; done means the invalid or uninitialized values are handled consistently and regression coverage exists.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.