Skip to content

Commit

Permalink
Rollup merge of rust-lang#76305 - CDirkx:const-tests, r=matklad
Browse files Browse the repository at this point in the history
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 rust-lang#76268

r? @matklad
  • Loading branch information
matklad committed Sep 4, 2020
2 parents 5d77a38 + 538e198 commit 352ca85
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 46 deletions.
13 changes: 13 additions & 0 deletions library/alloc/tests/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions library/alloc/tests/lib.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
11 changes: 11 additions & 0 deletions library/core/tests/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
17 changes: 17 additions & 0 deletions library/core/tests/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
16 changes: 0 additions & 16 deletions src/test/ui/consts/const-nonzero.rs

This file was deleted.

15 changes: 0 additions & 15 deletions src/test/ui/consts/cow-is-borrowed.rs

This file was deleted.

15 changes: 0 additions & 15 deletions src/test/ui/consts/is_ascii.rs

This file was deleted.

0 comments on commit 352ca85

Please sign in to comment.