Skip to content

Wrongly suggests error E0029 in match range #131327

@daniel-pfeiffer

Description

@daniel-pfeiffer

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 (eeb90cd 2024-09-04)
binary: rustc
commit-hash: eeb90cd
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions