Skip to content

Commit 52a0403

Browse files
committed
Add a range pattern inference failing test
1 parent ca1616c commit 52a0403

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
trait Zero {
2+
const ZERO: Self;
3+
}
4+
5+
impl Zero for String {
6+
const ZERO: Self = String::new();
7+
}
8+
9+
fn foo() {
10+
match String::new() {
11+
Zero::ZERO ..= Zero::ZERO => {},
12+
//~^ ERROR only `char` and numeric types are allowed in range patterns
13+
_ => {},
14+
}
15+
}
16+
17+
fn bar() {
18+
match Zero::ZERO {
19+
Zero::ZERO ..= Zero::ZERO => {},
20+
//~^ ERROR type annotations needed [E0282]
21+
_ => {},
22+
}
23+
}
24+
25+
fn main() {
26+
foo();
27+
bar();
28+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0029]: only `char` and numeric types are allowed in range patterns
2+
--> $DIR/issue-88074-pat-range-type-inference-err.rs:11:9
3+
|
4+
LL | Zero::ZERO ..= Zero::ZERO => {},
5+
| ----------^^^^^----------
6+
| | |
7+
| | this is of type `String` but it should be `char` or numeric
8+
| this is of type `String` but it should be `char` or numeric
9+
10+
error[E0282]: type annotations needed
11+
--> $DIR/issue-88074-pat-range-type-inference-err.rs:19:9
12+
|
13+
LL | Zero::ZERO ..= Zero::ZERO => {},
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
15+
|
16+
= note: type must be known at this point
17+
18+
error: aborting due to 2 previous errors
19+
20+
Some errors have detailed explanations: E0029, E0282.
21+
For more information about an error, try `rustc --explain E0029`.

0 commit comments

Comments
 (0)