about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-04-19 05:38:13 +0000
committerbors <bors@rust-lang.org>2024-04-19 05:38:13 +0000
commit0ed85d0c8d225b4eac2085dc11d89b4e7455175a (patch)
tree95590b78726ee19dcc1f2ade18b9d6ddc7b28e74 /tests
parent13e63f7490109eecf905fa51190eacbe8051aefd (diff)
parentc8d58faba29805c499eb121ba6359b1284c8f293 (diff)
Auto merge of #124147 - workingjubilee:rollup-7pjnzr6, r=workingjubilee
Rollup of 7 pull requests

Successful merges:

 - #123406 (Force exhaustion in iter::ArrayChunks::into_remainder)
 - #123752 (Properly handle emojis as literal prefix in macros)
 - #123935 (Don't inline integer literals when they overflow - new attempt)
 - #123980 ( Add an opt-in to store incoming edges in `VecGraph` + misc)
 - #124019 (Use raw-dylib for Windows synchronization functions)
 - #124110 (Fix negating `f16` and `f128` constants)
 - #124116 (when suggesting RUST_BACKTRACE=1, add a special note for Miri's env var isolation)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/fmt/no-inline-literals-out-of-range.rs14
-rw-r--r--tests/ui/fmt/no-inline-literals-out-of-range.stderr56
-rw-r--r--tests/ui/lexer/emoji-literal-prefix.rs8
-rw-r--r--tests/ui/lexer/emoji-literal-prefix.stderr14
-rw-r--r--tests/ui/numbers-arithmetic/f16-f128-lit.rs16
5 files changed, 108 insertions, 0 deletions
diff --git a/tests/ui/fmt/no-inline-literals-out-of-range.rs b/tests/ui/fmt/no-inline-literals-out-of-range.rs
new file mode 100644
index 00000000000..d2532cdfbff
--- /dev/null
+++ b/tests/ui/fmt/no-inline-literals-out-of-range.rs
@@ -0,0 +1,14 @@
+//@ only-64bit
+
+fn main() {
+    format_args!("{}", 0x8f_i8); // issue #115423
+    //~^ ERROR literal out of range for `i8`
+    format_args!("{}", 0xffff_ffff_u8); // issue #116633
+    //~^ ERROR literal out of range for `u8`
+    format_args!("{}", 0xffff_ffff_ffff_ffff_ffff_usize);
+    //~^ ERROR literal out of range for `usize`
+    format_args!("{}", 0x8000_0000_0000_0000_isize);
+    //~^ ERROR literal out of range for `isize`
+    format_args!("{}", 0xffff_ffff); // treat unsuffixed literals as i32
+    //~^ ERROR literal out of range for `i32`
+}
diff --git a/tests/ui/fmt/no-inline-literals-out-of-range.stderr b/tests/ui/fmt/no-inline-literals-out-of-range.stderr
new file mode 100644
index 00000000000..78ec4888c27
--- /dev/null
+++ b/tests/ui/fmt/no-inline-literals-out-of-range.stderr
@@ -0,0 +1,56 @@
+error: literal out of range for `i8`
+  --> $DIR/no-inline-literals-out-of-range.rs:4:24
+   |
+LL |     format_args!("{}", 0x8f_i8); // issue #115423
+   |                        ^^^^^^^
+   |
+   = note: the literal `0x8f_i8` (decimal `143`) does not fit into the type `i8` and will become `-113i8`
+   = note: `#[deny(overflowing_literals)]` on by default
+help: consider using the type `u8` instead
+   |
+LL |     format_args!("{}", 0x8f_u8); // issue #115423
+   |                        ~~~~~~~
+help: to use as a negative number (decimal `-113`), consider using the type `u8` for the literal and cast it to `i8`
+   |
+LL |     format_args!("{}", 0x8f_u8 as i8); // issue #115423
+   |                        ~~~~~~~~~~~~~
+
+error: literal out of range for `u8`
+  --> $DIR/no-inline-literals-out-of-range.rs:6:24
+   |
+LL |     format_args!("{}", 0xffff_ffff_u8); // issue #116633
+   |                        ^^^^^^^^^^^^^^ help: consider using the type `u32` instead: `0xffff_ffff_u32`
+   |
+   = note: the literal `0xffff_ffff_u8` (decimal `4294967295`) does not fit into the type `u8` and will become `255u8`
+
+error: literal out of range for `usize`
+  --> $DIR/no-inline-literals-out-of-range.rs:8:24
+   |
+LL |     format_args!("{}", 0xffff_ffff_ffff_ffff_ffff_usize);
+   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: the literal `0xffff_ffff_ffff_ffff_ffff_usize` (decimal `1208925819614629174706175`) does not fit into the type `usize` and will become `18446744073709551615usize`
+
+error: literal out of range for `isize`
+  --> $DIR/no-inline-literals-out-of-range.rs:10:24
+   |
+LL |     format_args!("{}", 0x8000_0000_0000_0000_isize);
+   |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: the literal `0x8000_0000_0000_0000_isize` (decimal `9223372036854775808`) does not fit into the type `isize` and will become `-9223372036854775808isize`
+
+error: literal out of range for `i32`
+  --> $DIR/no-inline-literals-out-of-range.rs:12:24
+   |
+LL |     format_args!("{}", 0xffff_ffff); // treat unsuffixed literals as i32
+   |                        ^^^^^^^^^^^
+   |
+   = note: the literal `0xffff_ffff` (decimal `4294967295`) does not fit into the type `i32` and will become `-1i32`
+   = help: consider using the type `u32` instead
+help: to use as a negative number (decimal `-1`), consider using the type `u32` for the literal and cast it to `i32`
+   |
+LL |     format_args!("{}", 0xffff_ffffu32 as i32); // treat unsuffixed literals as i32
+   |                        ~~~~~~~~~~~~~~~~~~~~~
+
+error: aborting due to 5 previous errors
+
diff --git a/tests/ui/lexer/emoji-literal-prefix.rs b/tests/ui/lexer/emoji-literal-prefix.rs
new file mode 100644
index 00000000000..ccc8d48d4cc
--- /dev/null
+++ b/tests/ui/lexer/emoji-literal-prefix.rs
@@ -0,0 +1,8 @@
+macro_rules! lexes {($($_:tt)*) => {}}
+
+lexes!(🐛#); //~ ERROR identifiers cannot contain emoji
+lexes!(🐛"foo");
+lexes!(🐛'q');
+lexes!(🐛'q);
+
+fn main() {}
diff --git a/tests/ui/lexer/emoji-literal-prefix.stderr b/tests/ui/lexer/emoji-literal-prefix.stderr
new file mode 100644
index 00000000000..25aafed48ea
--- /dev/null
+++ b/tests/ui/lexer/emoji-literal-prefix.stderr
@@ -0,0 +1,14 @@
+error: identifiers cannot contain emoji: `🐛`
+  --> $DIR/emoji-literal-prefix.rs:3:8
+   |
+LL | lexes!(🐛#);
+   |        ^^
+LL | lexes!(🐛"foo");
+   |        ^^
+LL | lexes!(🐛'q');
+   |        ^^
+LL | lexes!(🐛'q);
+   |        ^^
+
+error: aborting due to 1 previous error
+
diff --git a/tests/ui/numbers-arithmetic/f16-f128-lit.rs b/tests/ui/numbers-arithmetic/f16-f128-lit.rs
new file mode 100644
index 00000000000..762436edb16
--- /dev/null
+++ b/tests/ui/numbers-arithmetic/f16-f128-lit.rs
@@ -0,0 +1,16 @@
+//@ run-pass
+
+#![feature(f16)]
+#![feature(f128)]
+
+fn main() {
+    assert_eq!(0.0_f16.to_bits(), 0x0000);
+    assert_eq!((-0.0_f16).to_bits(), 0x8000);
+    assert_eq!(10.0_f16.to_bits(), 0x4900);
+    assert_eq!((-10.0_f16).to_bits(), 0xC900);
+
+    assert_eq!(0.0_f128.to_bits(), 0x0000_0000_0000_0000_0000_0000_0000_0000);
+    assert_eq!((-0.0_f128).to_bits(), 0x8000_0000_0000_0000_0000_0000_0000_0000);
+    assert_eq!(10.0_f128.to_bits(), 0x4002_4000_0000_0000_0000_0000_0000_0000);
+    assert_eq!((-10.0_f128).to_bits(), 0xC002_4000_0000_0000_0000_0000_0000_0000);
+}