Skip to content

Commit ed903f9

Browse files
committed
add ui test for new typeof error messages
1 parent 81e4d5f commit ed903f9

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/test/ui/typeof/type_mismatch.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Test that using typeof results in the correct type mismatch errors instead of always assuming
2+
// `usize`, in addition to the pre-existing "typeof is reserved and unimplemented" error
3+
fn main() {
4+
const a: u8 = 1;
5+
let b: typeof(a) = 1i8;
6+
//~^ ERROR `typeof` is a reserved keyword but unimplemented
7+
//~| ERROR mismatched types
8+
//~| expected `u8`, found `i8`
9+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0516]: `typeof` is a reserved keyword but unimplemented
2+
--> $DIR/type_mismatch.rs:5:12
3+
|
4+
LL | let b: typeof(a) = 1i8;
5+
| ^^^^^^^^^ reserved keyword
6+
7+
error[E0308]: mismatched types
8+
--> $DIR/type_mismatch.rs:5:24
9+
|
10+
LL | let b: typeof(a) = 1i8;
11+
| --------- ^^^ expected `u8`, found `i8`
12+
| |
13+
| expected due to this
14+
|
15+
help: change the type of the numeric literal from `i8` to `u8`
16+
|
17+
LL | let b: typeof(a) = 1u8;
18+
| ^^^
19+
20+
error: aborting due to 2 previous errors
21+
22+
Some errors have detailed explanations: E0308, E0516.
23+
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)