Skip to content

Commit 538e198

Browse files
committed
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
1 parent 0d0f6b1 commit 538e198

File tree

7 files changed

+42
-46
lines changed

7 files changed

+42
-46
lines changed

library/alloc/tests/borrow.rs

+13
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,16 @@ fn test_from_cow_path() {
4545
let path = Path::new("hello");
4646
test_from_cow!(path: &Path);
4747
}
48+
49+
#[test]
50+
fn cow_const() {
51+
// test that the methods of `Cow` are usable in a const context
52+
53+
const COW: Cow<'_, str> = Cow::Borrowed("moo");
54+
55+
const IS_BORROWED: bool = COW.is_borrowed();
56+
assert!(IS_BORROWED);
57+
58+
const IS_OWNED: bool = COW.is_owned();
59+
assert!(!IS_OWNED);
60+
}

library/alloc/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![feature(allocator_api)]
22
#![feature(box_syntax)]
3+
#![feature(cow_is_borrowed)]
34
#![feature(drain_filter)]
45
#![feature(exact_size_is_empty)]
56
#![feature(new_uninit)]

library/core/tests/ascii.rs

+11
Original file line numberDiff line numberDiff line change
@@ -397,3 +397,14 @@ fn test_is_ascii_align_size_thoroughly() {
397397
}
398398
}
399399
}
400+
401+
#[test]
402+
fn ascii_const() {
403+
// test that the `is_ascii` methods of `char` and `u8` are usable in a const context
404+
405+
const CHAR_IS_ASCII: bool = 'a'.is_ascii();
406+
assert!(CHAR_IS_ASCII);
407+
408+
const BYTE_IS_ASCII: bool = 97u8.is_ascii();
409+
assert!(BYTE_IS_ASCII);
410+
}

library/core/tests/nonzero.rs

+17
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,20 @@ fn test_nonzero_from_int_on_err() {
195195
assert!(NonZeroI8::try_from(0).is_err());
196196
assert!(NonZeroI32::try_from(0).is_err());
197197
}
198+
199+
#[test]
200+
fn nonzero_const() {
201+
// test that the methods of `NonZeroX>` are usable in a const context
202+
// Note: only tests NonZero8
203+
204+
const NONZERO: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(5) };
205+
206+
const GET: u8 = NONZERO.get();
207+
assert_eq!(GET, 5);
208+
209+
const ZERO: Option<NonZeroU8> = NonZeroU8::new(0);
210+
assert!(ZERO.is_none());
211+
212+
const ONE: Option<NonZeroU8> = NonZeroU8::new(1);
213+
assert!(ONE.is_some());
214+
}

src/test/ui/consts/const-nonzero.rs

-16
This file was deleted.

src/test/ui/consts/cow-is-borrowed.rs

-15
This file was deleted.

src/test/ui/consts/is_ascii.rs

-15
This file was deleted.

0 commit comments

Comments
 (0)