rust-lang / rust-lang/rust

Wrongly suggests error E0029 in match range

Open
#131,327 2 comments 3 reactions 1 assignee View on GitHub

@chenyukang is already working on this.

Since Sep 15, 2026.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
fn cmp<T: PartialOrd, R>(x: T, y: T, smaller: R, equal: R, greater: R) -> R {
    match x {
        ..y => smaller,
        y   => equal,
        _   => greater
    }
}
Current output
error[E0029]: only `char` and numeric types are allowed in range patterns
 --> src/main.rs:3:11
  |
3 |         ..y => smaller,
  |           ^ this is of type `T` but it should be `char` or numeric
Desired output
error[E0080]: runtime values cannot be referenced in patterns
 --> src/main.rs:3:11
  |
3 |         ..y => smaller,
  |           ^
Rationale and extra context

The second output comes when following that wrong suggestion and changing to

fn cmp<R>(x: char, y: char, smaller: R, equal: R, greater: R) -> R {
    match x {
        ..y => smaller,
        y   => equal,
        _   => greater
    }
}

cf. forum

Other cases

No response

Rust Version

rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7

Anything else?

No response

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.