about summary refs log tree commit diff
diff options
context:
space:
mode:
authorcsmoe <35686186+csmoe@users.noreply.github.com>2018-09-16 21:13:11 +0800
committercsmoe <35686186+csmoe@users.noreply.github.com>2018-09-16 21:22:47 +0800
commit17a28f706395bab81047c5e4fd3d903304cc5c72 (patch)
tree78f55820b9b04bb0067fc63e3fdf7dad553a717a
parent0ff0669b79d768dd32ceefeb76cad7332221492b (diff)
downloadrust-17a28f706395bab81047c5e4fd3d903304cc5c72.tar.gz
rust-17a28f706395bab81047c5e4fd3d903304cc5c72.zip
add test for numeric literal cast
-rw-r--r--src/test/ui/mismatched_types/numeric-literal-cast.rs15
-rw-r--r--src/test/ui/mismatched_types/numeric-literal-cast.stderr13
2 files changed, 28 insertions, 0 deletions
diff --git a/src/test/ui/mismatched_types/numeric-literal-cast.rs b/src/test/ui/mismatched_types/numeric-literal-cast.rs
new file mode 100644
index 00000000000..8d8c9d75973
--- /dev/null
+++ b/src/test/ui/mismatched_types/numeric-literal-cast.rs
@@ -0,0 +1,15 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn foo(_: u16) {}
+fn main() {
+    foo(8u8);
+}
+
diff --git a/src/test/ui/mismatched_types/numeric-literal-cast.stderr b/src/test/ui/mismatched_types/numeric-literal-cast.stderr
new file mode 100644
index 00000000000..8fda8243115
--- /dev/null
+++ b/src/test/ui/mismatched_types/numeric-literal-cast.stderr
@@ -0,0 +1,13 @@
+error[E0308]: mismatched types
+  --> $DIR/numeric-literal-cast.rs:13:9
+   |
+LL |     foo(8u8);
+   |         ^^^ expected u16, found u8
+help: change the type of the numeric literal from `u8` to `u16`
+   |
+LL |     foo(8u16);
+   |         ^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.