@@ -296,7 +296,8 @@ pub fn zeroes(comptime T: type) T {
296
296
}
297
297
},
298
298
.Array = > | info | {
299
- if (info .sentinel ) | sentinel | {
299
+ if (info .sentinel ) | sentinel_ptr | {
300
+ const sentinel = @ptrCast (* const info .child , sentinel_ptr ).* ;
300
301
return [_ :sentinel ]info.child {zeroes (info .child )} ** info .len ;
301
302
}
302
303
return [_ ]info.child {zeroes (info .child )} ** info .len ;
@@ -453,7 +454,8 @@ pub fn zeroInit(comptime T: type, init: anytype) T {
453
454
@field (value , field .name ) = @field (init , field .name );
454
455
},
455
456
}
456
- } else if (field .default_value ) | default_value | {
457
+ } else if (field .default_value ) | default_value_ptr | {
458
+ const default_value = @ptrCast (* const field .field_type , default_value_ptr ).* ;
457
459
@field (value , field .name ) = default_value ;
458
460
}
459
461
}
@@ -599,7 +601,7 @@ pub fn Span(comptime T: type) type {
599
601
else = > @compileError ("invalid type given to std.mem.Span" ),
600
602
},
601
603
.C = > {
602
- new_ptr_info .sentinel = 0 ;
604
+ new_ptr_info .sentinel = & @as ( ptr_info . child , 0 ) ;
603
605
new_ptr_info .is_allowzero = false ;
604
606
},
605
607
.Many , .Slice = > {},
@@ -651,7 +653,9 @@ pub fn span(ptr: anytype) Span(@TypeOf(ptr)) {
651
653
}
652
654
const Result = Span (@TypeOf (ptr ));
653
655
const l = len (ptr );
654
- if (@typeInfo (Result ).Pointer .sentinel ) | s | {
656
+ const ptr_info = @typeInfo (Result ).Pointer ;
657
+ if (ptr_info .sentinel ) | s_ptr | {
658
+ const s = @ptrCast (* const ptr_info .child , s_ptr ).* ;
655
659
return ptr [0.. l :s ];
656
660
} else {
657
661
return ptr [0.. l ];
@@ -684,9 +688,10 @@ fn SliceTo(comptime T: type, comptime end: meta.Elem(T)) type {
684
688
// The return type must only be sentinel terminated if we are guaranteed
685
689
// to find the value searched for, which is only the case if it matches
686
690
// the sentinel of the type passed.
687
- if (array_info .sentinel ) | sentinel | {
691
+ if (array_info .sentinel ) | sentinel_ptr | {
692
+ const sentinel = @ptrCast (* const array_info .child , sentinel_ptr ).* ;
688
693
if (end == sentinel ) {
689
- new_ptr_info .sentinel = end ;
694
+ new_ptr_info .sentinel = & end ;
690
695
} else {
691
696
new_ptr_info .sentinel = null ;
692
697
}
@@ -698,16 +703,17 @@ fn SliceTo(comptime T: type, comptime end: meta.Elem(T)) type {
698
703
// The return type must only be sentinel terminated if we are guaranteed
699
704
// to find the value searched for, which is only the case if it matches
700
705
// the sentinel of the type passed.
701
- if (ptr_info .sentinel ) | sentinel | {
706
+ if (ptr_info .sentinel ) | sentinel_ptr | {
707
+ const sentinel = @ptrCast (* const ptr_info .child , sentinel_ptr ).* ;
702
708
if (end == sentinel ) {
703
- new_ptr_info .sentinel = end ;
709
+ new_ptr_info .sentinel = & end ;
704
710
} else {
705
711
new_ptr_info .sentinel = null ;
706
712
}
707
713
}
708
714
},
709
715
.C = > {
710
- new_ptr_info .sentinel = end ;
716
+ new_ptr_info .sentinel = & end ;
711
717
// C pointers are always allowzero, but we don't want the return type to be.
712
718
assert (new_ptr_info .is_allowzero );
713
719
new_ptr_info .is_allowzero = false ;
@@ -734,7 +740,9 @@ pub fn sliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) SliceTo(@Typ
734
740
}
735
741
const Result = SliceTo (@TypeOf (ptr ), end );
736
742
const length = lenSliceTo (ptr , end );
737
- if (@typeInfo (Result ).Pointer .sentinel ) | s | {
743
+ const ptr_info = @typeInfo (Result ).Pointer ;
744
+ if (ptr_info .sentinel ) | s_ptr | {
745
+ const s = @ptrCast (* const ptr_info .child , s_ptr ).* ;
738
746
return ptr [0.. length :s ];
739
747
} else {
740
748
return ptr [0.. length ];
@@ -786,7 +794,8 @@ fn lenSliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) usize {
786
794
.Pointer = > | ptr_info | switch (ptr_info .size ) {
787
795
.One = > switch (@typeInfo (ptr_info .child )) {
788
796
.Array = > | array_info | {
789
- if (array_info .sentinel ) | sentinel | {
797
+ if (array_info .sentinel ) | sentinel_ptr | {
798
+ const sentinel = @ptrCast (* const array_info .child , sentinel_ptr ).* ;
790
799
if (sentinel == end ) {
791
800
return indexOfSentinel (array_info .child , end , ptr );
792
801
}
@@ -795,7 +804,8 @@ fn lenSliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) usize {
795
804
},
796
805
else = > {},
797
806
},
798
- .Many = > if (ptr_info .sentinel ) | sentinel | {
807
+ .Many = > if (ptr_info .sentinel ) | sentinel_ptr | {
808
+ const sentinel = @ptrCast (* const ptr_info .child , sentinel_ptr ).* ;
799
809
// We may be looking for something other than the sentinel,
800
810
// but iterating past the sentinel would be a bug so we need
801
811
// to check for both.
@@ -808,7 +818,8 @@ fn lenSliceTo(ptr: anytype, comptime end: meta.Elem(@TypeOf(ptr))) usize {
808
818
return indexOfSentinel (ptr_info .child , end , ptr );
809
819
},
810
820
.Slice = > {
811
- if (ptr_info .sentinel ) | sentinel | {
821
+ if (ptr_info .sentinel ) | sentinel_ptr | {
822
+ const sentinel = @ptrCast (* const ptr_info .child , sentinel_ptr ).* ;
812
823
if (sentinel == end ) {
813
824
return indexOfSentinel (ptr_info .child , sentinel , ptr );
814
825
}
@@ -867,10 +878,12 @@ pub fn len(value: anytype) usize {
867
878
.Array = > value .len ,
868
879
else = > @compileError ("invalid type given to std.mem.len" ),
869
880
},
870
- .Many = > if (info .sentinel ) | sentinel |
871
- indexOfSentinel (info .child , sentinel , value )
872
- else
873
- @compileError ("length of pointer with no sentinel" ),
881
+ .Many = > {
882
+ const sentinel_ptr = info .sentinel orelse
883
+ @compileError ("length of pointer with no sentinel" );
884
+ const sentinel = @ptrCast (* const info .child , sentinel_ptr ).* ;
885
+ return indexOfSentinel (info .child , sentinel , value );
886
+ },
874
887
.C = > {
875
888
assert (value != null );
876
889
return indexOfSentinel (info .child , 0 , value );
@@ -2572,7 +2585,11 @@ test "alignPointer" {
2572
2585
try S .checkAlign ([* ]u32 , math .maxInt (usize ) - 3 , 8 , 0 );
2573
2586
}
2574
2587
2575
- fn CopyPtrAttrs (comptime source : type , comptime size : std.builtin.TypeInfo.Pointer.Size , comptime child : type ) type {
2588
+ fn CopyPtrAttrs (
2589
+ comptime source : type ,
2590
+ comptime size : std.builtin.TypeInfo.Pointer.Size ,
2591
+ comptime child : type ,
2592
+ ) type {
2576
2593
const info = @typeInfo (source ).Pointer ;
2577
2594
return @Type (.{
2578
2595
.Pointer = .{
0 commit comments