Skip to content

Suggest to change numeric literal instead of casting #54273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add test for float/integer
  • Loading branch information
csmoe committed Sep 17, 2018
commit 2fb6585f33bf1af3b6b5143347eb534cebd257e4
7 changes: 6 additions & 1 deletion src/test/ui/mismatched_types/numeric-literal-cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
// except according to those terms.

fn foo(_: u16) {}
fn foo1(_: f64) {}
fn foo2(_: i32) {}

fn main() {
foo(8u8);
foo(1u8);
foo1(2f32);
foo2(3i16);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for floats too?


28 changes: 24 additions & 4 deletions src/test/ui/mismatched_types/numeric-literal-cast.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
error[E0308]: mismatched types
--> $DIR/numeric-literal-cast.rs:13:9
--> $DIR/numeric-literal-cast.rs:16:9
|
LL | foo(8u8);
LL | foo(1u8);
| ^^^ expected u16, found u8
help: change the type of the numeric literal from `u8` to `u16`
|
LL | foo(8u16);
LL | foo(1u16);
| ^^^^

error: aborting due to previous error
error[E0308]: mismatched types
--> $DIR/numeric-literal-cast.rs:17:10
|
LL | foo1(2f32);
| ^^^^ expected f64, found f32
help: change the type of the numeric literal from `f32` to `f64`
|
LL | foo1(2f64);
| ^^^^

error[E0308]: mismatched types
--> $DIR/numeric-literal-cast.rs:18:10
|
LL | foo2(3i16);
| ^^^^ expected i32, found i16
help: change the type of the numeric literal from `i16` to `i32`
|
LL | foo2(3i32);
| ^^^^

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0308`.