summaryrefslogtreecommitdiffstats
path: root/tests/ui/consts/const-negation.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/consts/const-negation.rs
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/consts/const-negation.rs')
-rw-r--r--tests/ui/consts/const-negation.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/ui/consts/const-negation.rs b/tests/ui/consts/const-negation.rs
new file mode 100644
index 000000000..18bcdfb01
--- /dev/null
+++ b/tests/ui/consts/const-negation.rs
@@ -0,0 +1,33 @@
+// run-pass
+#![allow(overflowing_literals)]
+
+fn main() {
+ #[cfg(target_pointer_width = "32")]
+ const I: isize = -2147483648isize;
+ #[cfg(target_pointer_width = "64")]
+ const I: isize = -9223372036854775808isize;
+ assert_eq!(i32::MIN as u64, 0xffffffff80000000);
+ assert_eq!(-2147483648isize as u64, 0xffffffff80000000);
+ assert_eq!(-2147483648i32 as u64, 0xffffffff80000000);
+ assert_eq!(i64::MIN as u64, 0x8000000000000000);
+ #[cfg(target_pointer_width = "64")]
+ assert_eq!(-9223372036854775808isize as u64, 0x8000000000000000);
+ #[cfg(target_pointer_width = "32")]
+ assert_eq!(-9223372036854775808isize as u64, 0);
+ assert_eq!(-9223372036854775808i32 as u64, 0);
+ const J: usize = i32::MAX as usize;
+ const K: usize = -1i32 as u32 as usize;
+ const L: usize = i32::MIN as usize;
+ const M: usize = i64::MIN as usize;
+ match 5 {
+ J => {},
+ K => {},
+ L => {},
+ M => {},
+ _ => {}
+ }
+ match 5 {
+ I => {},
+ _ => {}
+ }
+}