about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-09-07 01:17:59 +0200
committerGitHub <noreply@github.com>2020-09-07 01:17:59 +0200
commit52d9162645b031e2cb9ed7ec239992017be99356 (patch)
treeae9dd17b53e178f00c31af50addfb1f3c585ae2f
parent5b8f76d564ac7bacb604d364ada044f289992ddf (diff)
parent538e198193451e680cc95b66c82baac3ac687c8c (diff)
downloadrust-52d9162645b031e2cb9ed7ec239992017be99356.tar.gz
rust-52d9162645b031e2cb9ed7ec239992017be99356.zip
Rollup merge of #76305 - CDirkx:const-tests, r=matklad
Move various ui const tests to `library`

Move:
 - `src\test\ui\consts\const-nonzero.rs` to `library\core`
 - `src\test\ui\consts\ascii.rs` to `library\core`
 - `src\test\ui\consts\cow-is-borrowed` to `library\alloc`

Part of #76268

r? @matklad
-rw-r--r--library/alloc/tests/borrow.rs13
-rw-r--r--library/alloc/tests/lib.rs1
-rw-r--r--library/core/tests/ascii.rs11
-rw-r--r--library/core/tests/nonzero.rs17
-rw-r--r--src/test/ui/consts/const-nonzero.rs16
-rw-r--r--src/test/ui/consts/cow-is-borrowed.rs15
-rw-r--r--src/test/ui/consts/is_ascii.rs15
7 files changed, 42 insertions, 46 deletions
diff --git a/library/alloc/tests/borrow.rs b/library/alloc/tests/borrow.rs
index 8bfcf323f67..57976aa6cdf 100644
--- a/library/alloc/tests/borrow.rs
+++ b/library/alloc/tests/borrow.rs
@@ -45,3 +45,16 @@ fn test_from_cow_path() {
     let path = Path::new("hello");
     test_from_cow!(path: &Path);
 }
+
+#[test]
+fn cow_const() {
+    // test that the methods of `Cow` are usable in a const context
+
+    const COW: Cow<'_, str> = Cow::Borrowed("moo");
+
+    const IS_BORROWED: bool = COW.is_borrowed();
+    assert!(IS_BORROWED);
+
+    const IS_OWNED: bool = COW.is_owned();
+    assert!(!IS_OWNED);
+}
diff --git a/library/alloc/tests/lib.rs b/library/alloc/tests/lib.rs
index b1513d1b056..590639d9834 100644
--- a/library/alloc/tests/lib.rs
+++ b/library/alloc/tests/lib.rs
@@ -1,5 +1,6 @@
 #![feature(allocator_api)]
 #![feature(box_syntax)]
+#![feature(cow_is_borrowed)]
 #![feature(drain_filter)]
 #![feature(exact_size_is_empty)]
 #![feature(new_uninit)]
diff --git a/library/core/tests/ascii.rs b/library/core/tests/ascii.rs
index 0b975083947..3244bbc2d67 100644
--- a/library/core/tests/ascii.rs
+++ b/library/core/tests/ascii.rs
@@ -397,3 +397,14 @@ fn test_is_ascii_align_size_thoroughly() {
         }
     }
 }
+
+#[test]
+fn ascii_const() {
+    // test that the `is_ascii` methods of `char` and `u8` are usable in a const context
+
+    const CHAR_IS_ASCII: bool = 'a'.is_ascii();
+    assert!(CHAR_IS_ASCII);
+
+    const BYTE_IS_ASCII: bool = 97u8.is_ascii();
+    assert!(BYTE_IS_ASCII);
+}
diff --git a/library/core/tests/nonzero.rs b/library/core/tests/nonzero.rs
index 48aec6d718d..825e5e63b59 100644
--- a/library/core/tests/nonzero.rs
+++ b/library/core/tests/nonzero.rs
@@ -195,3 +195,20 @@ fn test_nonzero_from_int_on_err() {
     assert!(NonZeroI8::try_from(0).is_err());
     assert!(NonZeroI32::try_from(0).is_err());
 }
+
+#[test]
+fn nonzero_const() {
+    // test that the methods of `NonZeroX>` are usable in a const context
+    // Note: only tests NonZero8
+
+    const NONZERO: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(5) };
+
+    const GET: u8 = NONZERO.get();
+    assert_eq!(GET, 5);
+
+    const ZERO: Option<NonZeroU8> = NonZeroU8::new(0);
+    assert!(ZERO.is_none());
+
+    const ONE: Option<NonZeroU8> = NonZeroU8::new(1);
+    assert!(ONE.is_some());
+}
diff --git a/src/test/ui/consts/const-nonzero.rs b/src/test/ui/consts/const-nonzero.rs
deleted file mode 100644
index cf6f8c8d69a..00000000000
--- a/src/test/ui/consts/const-nonzero.rs
+++ /dev/null
@@ -1,16 +0,0 @@
-// run-pass
-
-use std::num::NonZeroU8;
-
-const X: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(5) };
-const Y: u8 = X.get();
-
-const ZERO: Option<NonZeroU8> = NonZeroU8::new(0);
-const ONE: Option<NonZeroU8> = NonZeroU8::new(1);
-
-fn main() {
-    assert_eq!(Y, 5);
-
-    assert!(ZERO.is_none());
-    assert_eq!(ONE.unwrap().get(), 1);
-}
diff --git a/src/test/ui/consts/cow-is-borrowed.rs b/src/test/ui/consts/cow-is-borrowed.rs
deleted file mode 100644
index adebe20f5a2..00000000000
--- a/src/test/ui/consts/cow-is-borrowed.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-// run-pass
-
-#![feature(cow_is_borrowed)]
-
-use std::borrow::Cow;
-
-fn main() {
-    const COW: Cow<str> = Cow::Borrowed("moo");
-
-    const IS_BORROWED: bool = COW.is_borrowed();
-    assert!(IS_BORROWED);
-
-    const IS_OWNED: bool = COW.is_owned();
-    assert!(!IS_OWNED);
-}
diff --git a/src/test/ui/consts/is_ascii.rs b/src/test/ui/consts/is_ascii.rs
deleted file mode 100644
index d8424549f93..00000000000
--- a/src/test/ui/consts/is_ascii.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-// run-pass
-
-static X: bool = 'a'.is_ascii();
-static Y: bool = 'รค'.is_ascii();
-
-static BX: bool = b'a'.is_ascii();
-static BY: bool = 192u8.is_ascii();
-
-fn main() {
-    assert!(X);
-    assert!(!Y);
-
-    assert!(BX);
-    assert!(!BY);
-}