-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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 (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
GrigorenkoPVchipnertkj
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.