Skip to content

Commit

Permalink
add ui test for new typeof error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
yaahc committed Apr 26, 2021
1 parent 81e4d5f commit ed903f9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/test/ui/typeof/type_mismatch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Test that using typeof results in the correct type mismatch errors instead of always assuming
// `usize`, in addition to the pre-existing "typeof is reserved and unimplemented" error
fn main() {
const a: u8 = 1;
let b: typeof(a) = 1i8;
//~^ ERROR `typeof` is a reserved keyword but unimplemented
//~| ERROR mismatched types
//~| expected `u8`, found `i8`
}
23 changes: 23 additions & 0 deletions src/test/ui/typeof/type_mismatch.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error[E0516]: `typeof` is a reserved keyword but unimplemented
--> $DIR/type_mismatch.rs:5:12
|
LL | let b: typeof(a) = 1i8;
| ^^^^^^^^^ reserved keyword

error[E0308]: mismatched types
--> $DIR/type_mismatch.rs:5:24
|
LL | let b: typeof(a) = 1i8;
| --------- ^^^ expected `u8`, found `i8`
| |
| expected due to this
|
help: change the type of the numeric literal from `i8` to `u8`
|
LL | let b: typeof(a) = 1u8;
| ^^^

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0308, E0516.
For more information about an error, try `rustc --explain E0308`.

0 comments on commit ed903f9

Please sign in to comment.