]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_error_codes/src/error_codes/E0029.md
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / compiler / rustc_error_codes / src / error_codes / E0029.md
CommitLineData
60c5eb7d
XL
1Something other than numbers and characters has been used for a range.
2
3Erroneous code example:
4
5```compile_fail,E0029
6let string = "salutations !";
7
8// The ordering relation for strings cannot be evaluated at compile time,
9// so this doesn't work:
10match string {
11 "hello" ..= "world" => {}
12 _ => {}
13}
14
15// This is a more general version, using a guard:
16match string {
17 s if s >= "hello" && s <= "world" => {}
18 _ => {}
19}
20```
21
22In a match expression, only numbers and characters can be matched against a
23range. This is because the compiler checks that the range is non-empty at
24compile-time, and is unable to evaluate arbitrary comparison functions. If you
25want to capture values of an orderable type between two end-points, you can use
26a guard.