Skip to content

Range pattern does not perform type inference #88074

Closed

Description

trait Zero {
    const ZERO: Self;
}

impl Zero for i32 {
    const ZERO: Self = 0;
}

fn foo() {
    match 1 {
        Zero::ZERO ..= 1 => {},
        _ => {},
    }
}

currently throws E0029:

error[E0029]: only `char` and numeric types are allowed in range patterns
  --> src/lib.rs:11:9
   |
11 |         Zero::ZERO ..= 1 => {},
   |         ^^^^^^^^^^     - this is of type `{integer}`
   |         |
   |         this is of type `_` but it should be `char` or numeric

For more information about this error, try `rustc --explain E0029`.

while it should infer the constant to be <i32 as Zero>::ZERO.

@rustbot modify labels: +T-compiler +A-inference
@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-inferenceArea: Type inferenceC-bugCategory: This is a bug.T-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