]> git.proxmox.com Git - rustc.git/blobdiff - library/core/tests/intrinsics.rs
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / library / core / tests / intrinsics.rs
index fed7c4a5bf3991ddc69aaf9d46bbd46cfd54def1..de163a60c98f42686e4a1277b234c55befb5698e 100644 (file)
@@ -1,4 +1,5 @@
 use core::any::TypeId;
+use core::intrinsics::assume;
 
 #[test]
 fn test_typeid_sized_types() {
@@ -20,3 +21,17 @@ fn test_typeid_unsized_types() {
     assert_eq!(TypeId::of::<Y>(), TypeId::of::<Y>());
     assert!(TypeId::of::<X>() != TypeId::of::<Y>());
 }
+
+// Check that `const_assume` feature allow `assume` intrinsic
+// to be used in const contexts.
+#[test]
+fn test_assume_can_be_in_const_contexts() {
+    const unsafe fn foo(x: usize, y: usize) -> usize {
+        // SAFETY: the entire function is not safe,
+        // but it is just an example not used elsewhere.
+        unsafe { assume(y != 0) };
+        x / y
+    }
+    let rs = unsafe { foo(42, 97) };
+    assert_eq!(rs, 0);
+}