about summary refs log tree commit diff
path: root/tests/ui/consts
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-10-17 11:18:57 +0000
committerbors <bors@rust-lang.org>2024-10-17 11:18:57 +0000
commite09bf4c07af8a424f9022bfe8d42ec714a51f0be (patch)
tree0aa83217a4da4a550ed80601e35381bb06db1c33 /tests/ui/consts
parentecf6fc5336a7fe24607b8c394f34a4fcd20079c8 (diff)
parent6e4f8fea36cd04f623c46d99adc3c370b1879883 (diff)
downloadrust-e09bf4c07af8a424f9022bfe8d42ec714a51f0be.tar.gz
rust-e09bf4c07af8a424f9022bfe8d42ec714a51f0be.zip
Auto merge of #18317 - lnicola:sync-from-rust, r=Veykril
minor: sync from downstream
Diffstat (limited to 'tests/ui/consts')
-rw-r--r--tests/ui/consts/const-eval/float_methods.rs47
-rw-r--r--tests/ui/consts/const-unwrap.rs10
-rw-r--r--tests/ui/consts/const-unwrap.stderr12
-rw-r--r--tests/ui/consts/load-preserves-partial-init.rs1
4 files changed, 63 insertions, 7 deletions
diff --git a/tests/ui/consts/const-eval/float_methods.rs b/tests/ui/consts/const-eval/float_methods.rs
new file mode 100644
index 00000000000..49c31f68c5f
--- /dev/null
+++ b/tests/ui/consts/const-eval/float_methods.rs
@@ -0,0 +1,47 @@
+//@ run-pass
+//! Tests the float intrinsics: min, max, abs, copysign
+
+#![feature(const_float_methods)]
+#![feature(f16, f128)]
+
+const F16_MIN: f16 = 1.0_f16.min(0.5_f16);
+const F16_MAX: f16 = 1.0_f16.max(0.5_f16);
+const F16_ABS: f16 = (-1.0_f16).abs();
+const F16_COPYSIGN: f16 = 1.0_f16.copysign(-2.0_f16);
+
+const F32_MIN: f32 = 1.0_f32.min(0.5_f32);
+const F32_MAX: f32 = 1.0_f32.max(0.5_f32);
+const F32_ABS: f32 = (-1.0_f32).abs();
+const F32_COPYSIGN: f32 = 1.0_f32.copysign(-2.0_f32);
+
+const F64_MIN: f64 = 1.0_f64.min(0.5_f64);
+const F64_MAX: f64 = 1.0_f64.max(0.5_f64);
+const F64_ABS: f64 = (-1.0_f64).abs();
+const F64_COPYSIGN: f64 = 1.0_f64.copysign(-2.0_f64);
+
+const F128_MIN: f128 = 1.0_f128.min(0.5_f128);
+const F128_MAX: f128 = 1.0_f128.max(0.5_f128);
+const F128_ABS: f128 = (-1.0_f128).abs();
+const F128_COPYSIGN: f128 = 1.0_f128.copysign(-2.0_f128);
+
+fn main() {
+    assert_eq!(F16_MIN, 0.5);
+    assert_eq!(F16_MAX, 1.0);
+    assert_eq!(F16_ABS, 1.0);
+    assert_eq!(F16_COPYSIGN, -1.0);
+
+    assert_eq!(F32_MIN, 0.5);
+    assert_eq!(F32_MAX, 1.0);
+    assert_eq!(F32_ABS, 1.0);
+    assert_eq!(F32_COPYSIGN, -1.0);
+
+    assert_eq!(F64_MIN, 0.5);
+    assert_eq!(F64_MAX, 1.0);
+    assert_eq!(F64_ABS, 1.0);
+    assert_eq!(F64_COPYSIGN, -1.0);
+
+    assert_eq!(F128_MIN, 0.5);
+    assert_eq!(F128_MAX, 1.0);
+    assert_eq!(F128_ABS, 1.0);
+    assert_eq!(F128_COPYSIGN, -1.0);
+}
diff --git a/tests/ui/consts/const-unwrap.rs b/tests/ui/consts/const-unwrap.rs
index bc79c7db2fc..ea0a15af1be 100644
--- a/tests/ui/consts/const-unwrap.rs
+++ b/tests/ui/consts/const-unwrap.rs
@@ -1,11 +1,15 @@
 //@ check-fail
-
-#![feature(const_option)]
+// Verify that panicking `const_option` methods do the correct thing
 
 const FOO: i32 = Some(42i32).unwrap();
 
 const BAR: i32 = Option::<i32>::None.unwrap();
-//~^ERROR: evaluation of constant value failed
+//~^ ERROR: evaluation of constant value failed
+//~| NOTE: the evaluated program panicked
+
+const BAZ: i32 = Option::<i32>::None.expect("absolutely not!");
+//~^ ERROR: evaluation of constant value failed
+//~| NOTE: absolutely not!
 
 fn main() {
     println!("{}", FOO);
diff --git a/tests/ui/consts/const-unwrap.stderr b/tests/ui/consts/const-unwrap.stderr
index fee22a1d070..aa5dd9a5c36 100644
--- a/tests/ui/consts/const-unwrap.stderr
+++ b/tests/ui/consts/const-unwrap.stderr
@@ -1,9 +1,15 @@
 error[E0080]: evaluation of constant value failed
-  --> $DIR/const-unwrap.rs:7:18
+  --> $DIR/const-unwrap.rs:6:18
    |
 LL | const BAR: i32 = Option::<i32>::None.unwrap();
-   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'called `Option::unwrap()` on a `None` value', $DIR/const-unwrap.rs:7:38
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'called `Option::unwrap()` on a `None` value', $DIR/const-unwrap.rs:6:38
 
-error: aborting due to 1 previous error
+error[E0080]: evaluation of constant value failed
+  --> $DIR/const-unwrap.rs:10:18
+   |
+LL | const BAZ: i32 = Option::<i32>::None.expect("absolutely not!");
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'absolutely not!', $DIR/const-unwrap.rs:10:38
+
+error: aborting due to 2 previous errors
 
 For more information about this error, try `rustc --explain E0080`.
diff --git a/tests/ui/consts/load-preserves-partial-init.rs b/tests/ui/consts/load-preserves-partial-init.rs
index d97e9cb3d9d..2a8adbd5e16 100644
--- a/tests/ui/consts/load-preserves-partial-init.rs
+++ b/tests/ui/consts/load-preserves-partial-init.rs
@@ -1,6 +1,5 @@
 //@ run-pass
 
-#![feature(const_ptr_write)]
 // issue: https://github.com/rust-lang/rust/issues/69488
 // Loads of partially-initialized data could produce completely-uninitialized results.
 // Test to make sure that we no longer do such a "deinitializing" load.