Commit 538e198 1 parent 0d0f6b1 commit 538e198 Copy full SHA for 538e198
File tree 7 files changed +42
-46
lines changed
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() {
45
45
let path = Path :: new ( "hello" ) ;
46
46
test_from_cow ! ( path: & Path ) ;
47
47
}
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 1
1
#![ feature( allocator_api) ]
2
2
#![ feature( box_syntax) ]
3
+ #![ feature( cow_is_borrowed) ]
3
4
#![ feature( drain_filter) ]
4
5
#![ feature( exact_size_is_empty) ]
5
6
#![ feature( new_uninit) ]
Original file line number Diff line number Diff line change @@ -397,3 +397,14 @@ fn test_is_ascii_align_size_thoroughly() {
397
397
}
398
398
}
399
399
}
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() {
195
195
assert ! ( NonZeroI8 :: try_from( 0 ) . is_err( ) ) ;
196
196
assert ! ( NonZeroI32 :: try_from( 0 ) . is_err( ) ) ;
197
197
}
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