File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,23 @@ fn layout_array_edge_cases() {
55
55
}
56
56
}
57
57
58
+ #[ test]
59
+ fn layout_errors ( ) {
60
+ let layout = Layout :: new :: < [ u8 ; 2 ] > ( ) ;
61
+ // Should error if the alignment is not a power of two.
62
+ assert ! ( layout. align_to( 3 ) . is_err( ) ) ;
63
+
64
+ // The remaining assertions ensure that the methods error on arithmetic overflow as the
65
+ // alignment cannot overflow `isize`.
66
+ assert ! ( layout. align_to( isize :: MAX as usize + 1 ) . is_err( ) ) ;
67
+ assert ! ( layout. repeat( usize :: MAX ) . is_err( ) ) ;
68
+
69
+ assert ! ( layout. repeat_packed( usize :: MAX ) . is_err( ) ) ;
70
+
71
+ let next = Layout :: from_size_align ( isize:: MAX as usize , 1 ) . unwrap ( ) ;
72
+ assert ! ( layout. extend( next) . is_err( ) ) ;
73
+ }
74
+
58
75
#[ test]
59
76
fn layout_debug_shows_log2_of_alignment ( ) {
60
77
// `Debug` is not stable, but here's what it does right now
You can’t perform that action at this time.
0 commit comments