File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,30 @@ 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
+ let size = layout. size ( ) ;
67
+ let size_max = isize:: MAX as usize ;
68
+ let align_max = size_max / size;
69
+
70
+ assert ! ( layout. align_to( size_max + 1 ) . is_err( ) ) ;
71
+
72
+ assert ! ( layout. repeat( align_max) . is_ok( ) ) ;
73
+ assert ! ( layout. repeat( align_max + 1 ) . is_err( ) ) ;
74
+
75
+ assert ! ( layout. repeat_packed( align_max) . is_ok( ) ) ;
76
+ assert ! ( layout. repeat_packed( align_max + 1 ) . is_err( ) ) ;
77
+
78
+ let next = Layout :: from_size_align ( size_max, 1 ) . unwrap ( ) ;
79
+ assert ! ( layout. extend( next) . is_err( ) ) ;
80
+ }
81
+
58
82
#[ test]
59
83
fn layout_debug_shows_log2_of_alignment ( ) {
60
84
// `Debug` is not stable, but here's what it does right now
You can’t perform that action at this time.
0 commit comments