Skip to content

Commit 31fef6f

Browse files
authored
Merge pull request #21225 from mlugg/std-builtin-type
std: update `std.builtin.Type` fields to follow naming conventions
2 parents 9a12905 + aaa7e73 commit 31fef6f

File tree

336 files changed

+4119
-4118
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

336 files changed

+4119
-4118
lines changed

doc/langref.html.in

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4299,7 +4299,7 @@ comptime {
42994299
Asserts that {#syntax#}@sizeOf(@TypeOf(value)) == @sizeOf(DestType){#endsyntax#}.
43004300
</p>
43014301
<p>
4302-
Asserts that {#syntax#}@typeInfo(DestType) != .Pointer{#endsyntax#}. Use {#syntax#}@ptrCast{#endsyntax#} or {#syntax#}@ptrFromInt{#endsyntax#} if you need this.
4302+
Asserts that {#syntax#}@typeInfo(DestType) != .pointer{#endsyntax#}. Use {#syntax#}@ptrCast{#endsyntax#} or {#syntax#}@ptrFromInt{#endsyntax#} if you need this.
43034303
</p>
43044304
<p>
43054305
Can be used for these things for example:
@@ -4517,7 +4517,7 @@ comptime {
45174517
{#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,
45184518
an integer or an enum.
45194519
</p>
4520-
<p>{#syntax#}@typeInfo(@TypeOf(ptr)).Pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>
4520+
<p>{#syntax#}@typeInfo(@TypeOf(ptr)).pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>
45214521
<p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
45224522
{#see_also|@atomicStore|@atomicLoad|@atomicRmw|@fence|@cmpxchgWeak#}
45234523
{#header_close#}
@@ -4549,7 +4549,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
45494549
{#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float,
45504550
an integer or an enum.
45514551
</p>
4552-
<p>{#syntax#}@typeInfo(@TypeOf(ptr)).Pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>
4552+
<p>{#syntax#}@typeInfo(@TypeOf(ptr)).pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p>
45534553
<p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p>
45544554
{#see_also|@atomicStore|@atomicLoad|@atomicRmw|@fence|@cmpxchgStrong#}
45554555
{#header_close#}
@@ -4672,7 +4672,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
46724672
<p>
46734673
Floored division. Rounds toward negative infinity. For unsigned integers it is
46744674
the same as {#syntax#}numerator / denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#} and
4675-
{#syntax#}!(@typeInfo(T) == .Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
4675+
{#syntax#}!(@typeInfo(T) == .int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
46764676
</p>
46774677
<ul>
46784678
<li>{#syntax#}@divFloor(-5, 3) == -2{#endsyntax#}</li>
@@ -4686,7 +4686,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
46864686
<p>
46874687
Truncated division. Rounds toward zero. For unsigned integers it is
46884688
the same as {#syntax#}numerator / denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator != 0{#endsyntax#} and
4689-
{#syntax#}!(@typeInfo(T) == .Int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
4689+
{#syntax#}!(@typeInfo(T) == .int and T.is_signed and numerator == std.math.minInt(T) and denominator == -1){#endsyntax#}.
46904690
</p>
46914691
<ul>
46924692
<li>{#syntax#}@divTrunc(-5, 3) == -1{#endsyntax#}</li>
@@ -5320,8 +5320,8 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
53205320
any bits that disagree with the resultant sign bit are shifted out.
53215321
</p>
53225322
<p>
5323-
The type of {#syntax#}shift_amt{#endsyntax#} is an unsigned integer with {#syntax#}log2(@typeInfo(T).Int.bits){#endsyntax#} bits.
5324-
This is because {#syntax#}shift_amt >= @typeInfo(T).Int.bits{#endsyntax#} is undefined behavior.
5323+
The type of {#syntax#}shift_amt{#endsyntax#} is an unsigned integer with {#syntax#}log2(@typeInfo(T).int.bits){#endsyntax#} bits.
5324+
This is because {#syntax#}shift_amt >= @typeInfo(T).int.bits{#endsyntax#} is undefined behavior.
53255325
</p>
53265326
<p>
53275327
{#syntax#}comptime_int{#endsyntax#} is modeled as an integer with an infinite number of bits,
@@ -5337,8 +5337,8 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
53375337
Performs {#syntax#}a << b{#endsyntax#} and returns a tuple with the result and a possible overflow bit.
53385338
</p>
53395339
<p>
5340-
The type of {#syntax#}shift_amt{#endsyntax#} is an unsigned integer with {#syntax#}log2(@typeInfo(@TypeOf(a)).Int.bits){#endsyntax#} bits.
5341-
This is because {#syntax#}shift_amt >= @typeInfo(@TypeOf(a)).Int.bits{#endsyntax#} is undefined behavior.
5340+
The type of {#syntax#}shift_amt{#endsyntax#} is an unsigned integer with {#syntax#}log2(@typeInfo(@TypeOf(a)).int.bits){#endsyntax#} bits.
5341+
This is because {#syntax#}shift_amt >= @typeInfo(@TypeOf(a)).int.bits{#endsyntax#} is undefined behavior.
53425342
</p>
53435343
{#see_also|@shlExact|@shrExact#}
53445344
{#header_close#}
@@ -5350,8 +5350,8 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
53505350
that the shift will not shift any 1 bits out.
53515351
</p>
53525352
<p>
5353-
The type of {#syntax#}shift_amt{#endsyntax#} is an unsigned integer with {#syntax#}log2(@typeInfo(T).Int.bits){#endsyntax#} bits.
5354-
This is because {#syntax#}shift_amt >= @typeInfo(T).Int.bits{#endsyntax#} is undefined behavior.
5353+
The type of {#syntax#}shift_amt{#endsyntax#} is an unsigned integer with {#syntax#}log2(@typeInfo(T).int.bits){#endsyntax#} bits.
5354+
This is because {#syntax#}shift_amt >= @typeInfo(T).int.bits{#endsyntax#} is undefined behavior.
53555355
</p>
53565356
{#see_also|@shlExact|@shlWithOverflow#}
53575357
{#header_close#}
@@ -5405,7 +5405,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val
54055405
This size may contain padding bytes. If there were two consecutive T in memory, the padding would be the offset
54065406
in bytes between element at index 0 and the element at index 1. For {#link|integer|Integers#},
54075407
consider whether you want to use {#syntax#}@sizeOf(T){#endsyntax#} or
5408-
{#syntax#}@typeInfo(T).Int.bits{#endsyntax#}.
5408+
{#syntax#}@typeInfo(T).int.bits{#endsyntax#}.
54095409
</p>
54105410
<p>
54115411
This function measures the size at runtime. For types that are disallowed at runtime, such as

doc/langref/inline_prong_range.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fn isFieldOptional(comptime T: type, field_index: usize) !bool {
2-
const fields = @typeInfo(T).Struct.fields;
2+
const fields = @typeInfo(T).@"struct".fields;
33
return switch (field_index) {
4-
inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].type) == .Optional,
4+
inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].type) == .optional,
55
else => return error.IndexOutOfBounds,
66
};
77
}

doc/langref/poc_printValue_fn.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const Writer = struct {
22
pub fn printValue(self: *Writer, value: anytype) !void {
33
switch (@typeInfo(@TypeOf(value))) {
4-
.Int => {
4+
.int => {
55
return self.writeInt(value);
66
},
7-
.Float => {
7+
.float => {
88
return self.writeFloat(value);
99
},
10-
.Pointer => {
10+
.pointer => {
1111
return self.write(value);
1212
},
1313
else => {

doc/langref/test_enums.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ const Small = enum {
9595
four,
9696
};
9797
test "std.meta.Tag" {
98-
try expect(@typeInfo(Small).Enum.tag_type == u2);
98+
try expect(@typeInfo(Small).@"enum".tag_type == u2);
9999
}
100100

101101
// @typeInfo tells us the field count and the fields names:
102102
test "@typeInfo" {
103-
try expect(@typeInfo(Small).Enum.fields.len == 4);
104-
try expect(mem.eql(u8, @typeInfo(Small).Enum.fields[1].name, "two"));
103+
try expect(@typeInfo(Small).@"enum".fields.len == 4);
104+
try expect(mem.eql(u8, @typeInfo(Small).@"enum".fields[1].name, "two"));
105105
}
106106

107107
// @tagName gives a [:0]const u8 representation of an enum value:

doc/langref/test_error_union.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ test "error union" {
1010
foo = error.SomeError;
1111

1212
// Use compile-time reflection to access the payload type of an error union:
13-
try comptime expect(@typeInfo(@TypeOf(foo)).ErrorUnion.payload == i32);
13+
try comptime expect(@typeInfo(@TypeOf(foo)).error_union.payload == i32);
1414

1515
// Use compile-time reflection to access the error set type of an error union:
16-
try comptime expect(@typeInfo(@TypeOf(foo)).ErrorUnion.error_set == anyerror);
16+
try comptime expect(@typeInfo(@TypeOf(foo)).error_union.error_set == anyerror);
1717
}
1818

1919
// test

doc/langref/test_fn_reflection.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ const math = std.math;
33
const testing = std.testing;
44

55
test "fn reflection" {
6-
try testing.expect(@typeInfo(@TypeOf(testing.expect)).Fn.params[0].type.? == bool);
7-
try testing.expect(@typeInfo(@TypeOf(testing.tmpDir)).Fn.return_type.? == testing.TmpDir);
6+
try testing.expect(@typeInfo(@TypeOf(testing.expect)).@"fn".params[0].type.? == bool);
7+
try testing.expect(@typeInfo(@TypeOf(testing.tmpDir)).@"fn".return_type.? == testing.TmpDir);
88

9-
try testing.expect(@typeInfo(@TypeOf(math.Log2Int)).Fn.is_generic);
9+
try testing.expect(@typeInfo(@TypeOf(math.Log2Int)).@"fn".is_generic);
1010
}
1111

1212
// test

doc/langref/test_inline_else.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const AnySlice = union(enum) {
1717
};
1818

1919
fn withFor(any: AnySlice) usize {
20-
const Tag = @typeInfo(AnySlice).Union.tag_type.?;
21-
inline for (@typeInfo(Tag).Enum.fields) |field| {
20+
const Tag = @typeInfo(AnySlice).@"union".tag_type.?;
21+
inline for (@typeInfo(Tag).@"enum".fields) |field| {
2222
// With `inline for` the function gets generated as
2323
// a series of `if` statements relying on the optimizer
2424
// to convert it to a switch.

doc/langref/test_inline_switch.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ const expect = std.testing.expect;
33
const expectError = std.testing.expectError;
44

55
fn isFieldOptional(comptime T: type, field_index: usize) !bool {
6-
const fields = @typeInfo(T).Struct.fields;
6+
const fields = @typeInfo(T).@"struct".fields;
77
return switch (field_index) {
88
// This prong is analyzed twice with `idx` being a
99
// comptime-known value each time.
10-
inline 0, 1 => |idx| @typeInfo(fields[idx].type) == .Optional,
10+
inline 0, 1 => |idx| @typeInfo(fields[idx].type) == .optional,
1111
else => return error.IndexOutOfBounds,
1212
};
1313
}

doc/langref/test_optional_type.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test "optional type" {
88
foo = 1234;
99

1010
// Use compile-time reflection to access the child type of the optional:
11-
try comptime expect(@typeInfo(@TypeOf(foo)).Optional.child == i32);
11+
try comptime expect(@typeInfo(@TypeOf(foo)).optional.child == i32);
1212
}
1313

1414
// test

doc/langref/test_pointer_casting.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test "pointer casting" {
1717

1818
test "pointer child type" {
1919
// pointer types have a `child` field which tells you the type they point to.
20-
try expect(@typeInfo(*u32).Pointer.child == u32);
20+
try expect(@typeInfo(*u32).pointer.child == u32);
2121
}
2222

2323
// test

0 commit comments

Comments
 (0)