This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +42
-46
lines changed Expand file tree Collapse file tree 7 files changed +42
-46
lines changed Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff line change 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) ]
Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff 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+ }
Load Diff This file was deleted.
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments