authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-11-17 13:16:07+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2023-11-19 11:11:49+00:00
loged4bab66d8a0c518245a6ca1ff401f0b30befe64
treeb288939bc5dea5c2345246ccaa56447267ca80b4
parent026a8278f829670b434fddce34030290b6910898
signaturelock-open Commit is signed but in an unrecognized format.

langref: correct unnecessary uses of 'var'


1 files changed, 121 insertions(+), 94 deletions(-)

doc/langref.html.in+121-94
......@@ -2609,16 +2609,17 @@ test "Basic vector usage" {
26092609
26102610test "Conversion between vectors, arrays, and slices" {
26112611 // Vectors and fixed-length arrays can be automatically assigned back and forth
2612 var arr1: [4]f32 = [_]f32{ 1.1, 3.2, 4.5, 5.6 };
2613 var vec: @Vector(4, f32) = arr1;
2614 var arr2: [4]f32 = vec;
2612 const arr1: [4]f32 = [_]f32{ 1.1, 3.2, 4.5, 5.6 };
2613 const vec: @Vector(4, f32) = arr1;
2614 const arr2: [4]f32 = vec;
26152615 try expectEqual(arr1, arr2);
26162616
26172617 // You can also assign from a slice with comptime-known length to a vector using .*
26182618 const vec2: @Vector(2, f32) = arr1[1..3].*;
26192619
2620 var slice: []const f32 = &arr1;
2621 var offset: u32 = 1;
2620 const slice: []const f32 = &arr1;
2621 var offset: u32 = 1; // var to make it runtime-known
2622 _ = &offset; // suppress 'var is never mutated' error
26222623 // To extract a comptime-known length from a runtime-known offset,
26232624 // first extract a new slice from the starting offset, then an array of
26242625 // comptime-known length
......@@ -2732,7 +2733,8 @@ test "pointer arithmetic with many-item pointer" {
27322733
27332734test "pointer arithmetic with slices" {
27342735 var array = [_]i32{ 1, 2, 3, 4 };
2735 var length: usize = 0;
2736 var length: usize = 0; // var to make it runtime-known
2737 _ = &length; // suppress 'var is never mutated' error
27362738 var slice = array[length..array.len];
27372739
27382740 try expect(slice[0] == 1);
......@@ -2759,7 +2761,8 @@ const expect = @import("std").testing.expect;
27592761
27602762test "pointer slicing" {
27612763 var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
2762 var start: usize = 2;
2764 var start: usize = 2; // var to make it runtime-known
2765 _ = &start; // suppress 'var is never mutated' error
27632766 const slice = array[start..4];
27642767 try expect(slice.len == 2);
27652768
......@@ -2961,8 +2964,9 @@ const std = @import("std");
29612964const expect = std.testing.expect;
29622965
29632966test "allowzero" {
2964 var zero: usize = 0;
2965 var ptr: *allowzero i32 = @ptrFromInt(zero);
2967 var zero: usize = 0; // var to make to runtime-known
2968 _ = &zero; // suppress 'var is never mutated' error
2969 const ptr: *allowzero i32 = @ptrFromInt(zero);
29662970 try expect(@intFromPtr(ptr) == 0);
29672971}
29682972 {#code_end#}
......@@ -3006,6 +3010,7 @@ const expect = @import("std").testing.expect;
30063010test "basic slices" {
30073011 var array = [_]i32{ 1, 2, 3, 4 };
30083012 var known_at_runtime_zero: usize = 0;
3013 _ = &known_at_runtime_zero;
30093014 const slice = array[known_at_runtime_zero..array.len];
30103015 try expect(@TypeOf(slice) == []i32);
30113016 try expect(&slice[0] == &array[0]);
......@@ -3020,6 +3025,7 @@ test "basic slices" {
30203025 // to perform some optimisations like recognising a comptime-known length when
30213026 // the start position is only known at runtime.
30223027 var runtime_start: usize = 1;
3028 _ = &runtime_start;
30233029 const length = 2;
30243030 const array_ptr_len = array[runtime_start..][0..length];
30253031 try expect(@TypeOf(array_ptr_len) == *[length]i32);
......@@ -3056,7 +3062,8 @@ test "using slices for strings" {
30563062 var all_together: [100]u8 = undefined;
30573063 // You can use slice syntax with at least one runtime-known index on an
30583064 // array to convert an array into a slice.
3059 var start : usize = 0;
3065 var start: usize = 0;
3066 _ = &start;
30603067 const all_together_slice = all_together[start..];
30613068 // String concatenation example.
30623069 const hello_world = try fmt.bufPrint(all_together_slice, "{s} {s}", .{ hello, world });
......@@ -3075,6 +3082,7 @@ test "slice pointer" {
30753082 // A pointer to an array can be sliced just like an array:
30763083 var start: usize = 0;
30773084 var end: usize = 5;
3085 _ = .{ &start, &end };
30783086 const slice = ptr[start..end];
30793087 // The slice is mutable because we sliced a mutable pointer.
30803088 try expect(@TypeOf(slice) == []u8);
......@@ -3121,6 +3129,7 @@ const expect = std.testing.expect;
31213129test "0-terminated slicing" {
31223130 var array = [_]u8{ 3, 2, 1, 0, 3, 2, 1, 0 };
31233131 var runtime_length: usize = 3;
3132 _ = &runtime_length;
31243133 const slice = array[0..runtime_length :0];
31253134
31263135 try expect(@TypeOf(slice) == [:0]u8);
......@@ -3143,6 +3152,7 @@ test "sentinel mismatch" {
31433152 // This does not match the indicated sentinel value of `0` and will lead
31443153 // to a runtime panic.
31453154 var runtime_length: usize = 2;
3155 _ = &runtime_length;
31463156 const slice = array[0..runtime_length :0];
31473157
31483158 _ = slice;
......@@ -3266,7 +3276,7 @@ test "linked list" {
32663276 // do this:
32673277 try expect(LinkedList(i32) == LinkedList(i32));
32683278
3269 var list = LinkedList(i32) {
3279 const list = LinkedList(i32){
32703280 .first = null,
32713281 .last = null,
32723282 .len = 0,
......@@ -3278,12 +3288,12 @@ test "linked list" {
32783288 const ListOfInts = LinkedList(i32);
32793289 try expect(ListOfInts == LinkedList(i32));
32803290
3281 var node = ListOfInts.Node {
3291 var node = ListOfInts.Node{
32823292 .prev = null,
32833293 .next = null,
32843294 .data = 1234,
32853295 };
3286 var list2 = LinkedList(i32) {
3296 const list2 = LinkedList(i32){
32873297 .first = &node,
32883298 .last = &node,
32893299 .len = 1,
......@@ -3372,13 +3382,13 @@ test "@bitCast between packed structs" {
33723382fn doTheTest() !void {
33733383 try expect(@sizeOf(Full) == 2);
33743384 try expect(@sizeOf(Divided) == 2);
3375 var full = Full{ .number = 0x1234 };
3376 var divided: Divided = @bitCast(full);
3385 const full = Full{ .number = 0x1234 };
3386 const divided: Divided = @bitCast(full);
33773387 try expect(divided.half1 == 0x34);
33783388 try expect(divided.quarter3 == 0x2);
33793389 try expect(divided.quarter4 == 0x1);
33803390
3381 var ordered: [2]u8 = @bitCast(full);
3391 const ordered: [2]u8 = @bitCast(full);
33823392 switch (native_endian) {
33833393 .big => {
33843394 try expect(ordered[0] == 0x12);
......@@ -3586,7 +3596,7 @@ const expect = std.testing.expect;
35863596const Point = struct {x: i32, y: i32};
35873597
35883598test "anonymous struct literal" {
3589 var pt: Point = .{
3599 const pt: Point = .{
35903600 .x = 13,
35913601 .y = 67,
35923602 };
......@@ -4051,14 +4061,14 @@ const Number = union {
40514061};
40524062
40534063test "anonymous union literal syntax" {
4054 var i: Number = .{.int = 42};
4055 var f = makeNumber();
4064 const i: Number = .{ .int = 42 };
4065 const f = makeNumber();
40564066 try expect(i.int == 42);
40574067 try expect(f.float == 12.34);
40584068}
40594069
40604070fn makeNumber() Number {
4061 return .{.float = 12.34};
4071 return .{ .float = 12.34 };
40624072}
40634073 {#code_end#}
40644074 {#header_close#}
......@@ -4098,7 +4108,7 @@ test "call foo" {
40984108test "access variable after block scope" {
40994109 {
41004110 var x: i32 = 1;
4101 _ = x;
4111 _ = &x;
41024112 }
41034113 x += 1;
41044114}
......@@ -4149,7 +4159,7 @@ test "separate scopes" {
41494159 }
41504160 {
41514161 var pi: bool = true;
4152 _ = pi;
4162 _ = &pi;
41534163 }
41544164}
41554165 {#code_end#}
......@@ -4423,7 +4433,7 @@ fn withSwitch(any: AnySlice) usize {
44234433}
44244434
44254435test "inline for and inline else similarity" {
4426 var any = AnySlice{ .c = "hello" };
4436 const any = AnySlice{ .c = "hello" };
44274437 try expect(withFor(any) == 5);
44284438 try expect(withSwitch(any) == 5);
44294439}
......@@ -4455,7 +4465,7 @@ fn getNum(u: U) u32 {
44554465}
44564466
44574467test "test" {
4458 var u = U{ .b = 42 };
4468 const u = U{ .b = 42 };
44594469 try expect(getNum(u) == 42);
44604470}
44614471 {#code_end#}
......@@ -4762,7 +4772,7 @@ test "multi object for" {
47624772}
47634773
47644774test "for reference" {
4765 var items = [_]i32 { 3, 4, 2 };
4775 var items = [_]i32{ 3, 4, 2 };
47664776
47674777 // Iterate over the slice by reference by
47684778 // specifying that the capture value is a pointer.
......@@ -4777,7 +4787,7 @@ test "for reference" {
47774787
47784788test "for else" {
47794789 // For allows an else attached to it, the same as a while loop.
4780 var items = [_]?i32 { 3, 4, null, 5 };
4790 const items = [_]?i32{ 3, 4, null, 5 };
47814791
47824792 // For loops can also be used as expressions.
47834793 // Similar to while loops, when you break from a for loop, the else branch is not evaluated.
......@@ -5347,7 +5357,7 @@ fn addFortyTwo(x: anytype) @TypeOf(x) {
53475357test "fn type inference" {
53485358 try expect(addFortyTwo(1) == 43);
53495359 try expect(@TypeOf(addFortyTwo(1)) == comptime_int);
5350 var y: i64 = 2;
5360 const y: i64 = 2;
53515361 try expect(addFortyTwo(y) == 44);
53525362 try expect(@TypeOf(addFortyTwo(y)) == i64);
53535363}
......@@ -5795,7 +5805,7 @@ fn getData() !u32 {
57955805}
57965806
57975807fn genFoos(allocator: Allocator, num: usize) ![]Foo {
5798 var foos = try allocator.alloc(Foo, num);
5808 const foos = try allocator.alloc(Foo, num);
57995809 errdefer allocator.free(foos);
58005810
58015811 for (foos, 0..) |*foo, i| {
......@@ -5833,7 +5843,7 @@ fn getData() !u32 {
58335843}
58345844
58355845fn genFoos(allocator: Allocator, num: usize) ![]Foo {
5836 var foos = try allocator.alloc(Foo, num);
5846 const foos = try allocator.alloc(Foo, num);
58375847 errdefer allocator.free(foos);
58385848
58395849 // Used to track how many foos have been initialized
......@@ -6325,13 +6335,13 @@ test "optional pointers" {
63256335 </p>
63266336 {#code_begin|test|test_type_coercion#}
63276337test "type coercion - variable declaration" {
6328 var a: u8 = 1;
6329 var b: u16 = a;
6338 const a: u8 = 1;
6339 const b: u16 = a;
63306340 _ = b;
63316341}
63326342
63336343test "type coercion - function call" {
6334 var a: u8 = 1;
6344 const a: u8 = 1;
63356345 foo(a);
63366346}
63376347
......@@ -6340,8 +6350,8 @@ fn foo(b: u16) void {
63406350}
63416351
63426352test "type coercion - @as builtin" {
6343 var a: u8 = 1;
6344 var b = @as(u16, a);
6353 const a: u8 = 1;
6354 const b = @as(u16, a);
63456355 _ = b;
63466356}
63476357 {#code_end#}
......@@ -6366,7 +6376,7 @@ test "type coercion - @as builtin" {
63666376 {#code_begin|test|test_no_op_casts#}
63676377test "type coercion - const qualification" {
63686378 var a: i32 = 1;
6369 var b: *i32 = &a;
6379 const b: *i32 = &a;
63706380 foo(b);
63716381}
63726382
......@@ -6399,26 +6409,26 @@ const expect = std.testing.expect;
63996409const mem = std.mem;
64006410
64016411test "integer widening" {
6402 var a: u8 = 250;
6403 var b: u16 = a;
6404 var c: u32 = b;
6405 var d: u64 = c;
6406 var e: u64 = d;
6407 var f: u128 = e;
6412 const a: u8 = 250;
6413 const b: u16 = a;
6414 const c: u32 = b;
6415 const d: u64 = c;
6416 const e: u64 = d;
6417 const f: u128 = e;
64086418 try expect(f == a);
64096419}
64106420
64116421test "implicit unsigned integer to signed integer" {
6412 var a: u8 = 250;
6413 var b: i16 = a;
6422 const a: u8 = 250;
6423 const b: i16 = a;
64146424 try expect(b == 250);
64156425}
64166426
64176427test "float widening" {
6418 var a: f16 = 12.34;
6419 var b: f32 = a;
6420 var c: f64 = b;
6421 var d: f128 = c;
6428 const a: f16 = 12.34;
6429 const b: f32 = a;
6430 const c: f64 = b;
6431 const d: f128 = c;
64226432 try expect(d == a);
64236433}
64246434 {#code_end#}
......@@ -6435,7 +6445,7 @@ test "float widening" {
64356445 {#code_begin|test_err|test_ambiguous_coercion#}
64366446// Compile time coercion of float to int
64376447test "implicit cast to comptime_int" {
6438 var f: f32 = 54.0 / 5;
6448 const f: f32 = 54.0 / 5;
64396449 _ = f;
64406450}
64416451 {#code_end#}
......@@ -6449,31 +6459,31 @@ const expect = std.testing.expect;
64496459// const modifier on the element type. Useful in particular for
64506460// String literals.
64516461test "*const [N]T to []const T" {
6452 var x1: []const u8 = "hello";
6453 var x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
6462 const x1: []const u8 = "hello";
6463 const x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
64546464 try expect(std.mem.eql(u8, x1, x2));
64556465
6456 var y: []const f32 = &[2]f32{ 1.2, 3.4 };
6466 const y: []const f32 = &[2]f32{ 1.2, 3.4 };
64576467 try expect(y[0] == 1.2);
64586468}
64596469
64606470// Likewise, it works when the destination type is an error union.
64616471test "*const [N]T to E![]const T" {
6462 var x1: anyerror![]const u8 = "hello";
6463 var x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
6472 const x1: anyerror![]const u8 = "hello";
6473 const x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
64646474 try expect(std.mem.eql(u8, try x1, try x2));
64656475
6466 var y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 };
6476 const y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 };
64676477 try expect((try y)[0] == 1.2);
64686478}
64696479
64706480// Likewise, it works when the destination type is an optional.
64716481test "*const [N]T to ?[]const T" {
6472 var x1: ?[]const u8 = "hello";
6473 var x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
6482 const x1: ?[]const u8 = "hello";
6483 const x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 };
64746484 try expect(std.mem.eql(u8, x1.?, x2.?));
64756485
6476 var y: ?[]const f32 = &[2]f32{ 1.2, 3.4 };
6486 const y: ?[]const f32 = &[2]f32{ 1.2, 3.4 };
64776487 try expect(y.?[0] == 1.2);
64786488}
64796489
......@@ -6609,18 +6619,18 @@ const U2 = union(enum) {
66096619};
66106620
66116621test "coercion between unions and enums" {
6612 var u = U{ .two = 12.34 };
6613 var e: E = u; // coerce union to enum
6622 const u = U{ .two = 12.34 };
6623 const e: E = u; // coerce union to enum
66146624 try expect(e == E.two);
66156625
66166626 const three = E.three;
6617 var u_2: U = three; // coerce enum to union
6627 const u_2: U = three; // coerce enum to union
66186628 try expect(u_2 == E.three);
66196629
6620 var u_3: U = .three; // coerce enum literal to union
6630 const u_3: U = .three; // coerce enum literal to union
66216631 try expect(u_3 == E.three);
66226632
6623 var u_4: U2 = .a; // coerce enum literal to union with inferred enum tag type.
6633 const u_4: U2 = .a; // coerce enum literal to union with inferred enum tag type.
66246634 try expect(u_4.tag() == 1);
66256635
66266636 // The following example is invalid.
......@@ -6698,9 +6708,9 @@ const expect = std.testing.expect;
66986708const mem = std.mem;
66996709
67006710test "peer resolve int widening" {
6701 var a: i8 = 12;
6702 var b: i16 = 34;
6703 var c = a + b;
6711 const a: i8 = 12;
6712 const b: i16 = 34;
6713 const c = a + b;
67046714 try expect(c == 46);
67056715 try expect(@TypeOf(c) == i16);
67066716}
......@@ -6809,6 +6819,7 @@ export fn entry() void {
68096819 var x: void = {};
68106820 var y: void = {};
68116821 x = y;
6822 y = x;
68126823}
68136824 {#code_end#}
68146825 <p>When this turns into machine code, there is no code generated in the
......@@ -7121,6 +7132,7 @@ fn performFn(start_value: i32) i32 {
71217132// expect(performFn('w', 99) == 99);
71227133fn performFn(start_value: i32) i32 {
71237134 var result: i32 = start_value;
7135 _ = &result;
71247136 return result;
71257137}
71267138 {#end_syntax_block#}
......@@ -8664,8 +8676,9 @@ test "@hasDecl" {
86648676 </p>
86658677 {#code_begin|test_err|test_intCast_builtin|cast truncated bits#}
86668678test "integer cast panic" {
8667 var a: u16 = 0xabcd;
8668 var b: u8 = @intCast(a);
8679 var a: u16 = 0xabcd; // runtime-known
8680 _ = &a;
8681 const b: u8 = @intCast(a);
86698682 _ = b;
86708683}
86718684 {#code_end#}
......@@ -8825,7 +8838,7 @@ const expect = std.testing.expect;
88258838test "@wasmMemoryGrow" {
88268839 if (native_arch != .wasm32) return error.SkipZigTest;
88278840
8828 var prev = @wasmMemorySize(0);
8841 const prev = @wasmMemorySize(0);
88298842 try expect(prev == @wasmMemoryGrow(0, 1));
88308843 try expect(prev + 1 == @wasmMemorySize(0));
88318844}
......@@ -9560,8 +9573,8 @@ const std = @import("std");
95609573const expect = std.testing.expect;
95619574
95629575test "integer truncation" {
9563 var a: u16 = 0xabcd;
9564 var b: u8 = @truncate(a);
9576 const a: u16 = 0xabcd;
9577 const b: u8 = @truncate(a);
95659578 try expect(b == 0xcd);
95669579}
95679580 {#code_end#}
......@@ -9845,7 +9858,7 @@ comptime {
98459858 <p>At runtime:</p>
98469859 {#code_begin|exe_err|runtime_index_out_of_bounds#}
98479860pub fn main() void {
9848 var x = foo("hello");
9861 const x = foo("hello");
98499862 _ = x;
98509863}
98519864
......@@ -9858,7 +9871,7 @@ fn foo(x: []const u8) u8 {
98589871 <p>At compile-time:</p>
98599872 {#code_begin|test_err|test_comptime_invalid_cast|type 'u32' cannot represent integer value '-1'#}
98609873comptime {
9861 var value: i32 = -1;
9874 const value: i32 = -1;
98629875 const unsigned: u32 = @intCast(value);
98639876 _ = unsigned;
98649877}
......@@ -9868,8 +9881,9 @@ comptime {
98689881const std = @import("std");
98699882
98709883pub fn main() void {
9871 var value: i32 = -1;
9872 var unsigned: u32 = @intCast(value);
9884 var value: i32 = -1; // runtime-known
9885 _ = &value;
9886 const unsigned: u32 = @intCast(value);
98739887 std.debug.print("value: {}\n", .{unsigned});
98749888}
98759889 {#code_end#}
......@@ -9891,7 +9905,8 @@ comptime {
98919905const std = @import("std");
98929906
98939907pub fn main() void {
9894 var spartan_count: u16 = 300;
9908 var spartan_count: u16 = 300; // runtime-known
9909 _ = &spartan_count;
98959910 const byte: u8 = @intCast(spartan_count);
98969911 std.debug.print("value: {}\n", .{byte});
98979912}
......@@ -9975,7 +9990,7 @@ pub fn main() !void {
99759990 {#code_begin|exe|addWithOverflow_builtin#}
99769991const print = @import("std").debug.print;
99779992pub fn main() void {
9978 var byte: u8 = 255;
9993 const byte: u8 = 255;
99799994
99809995 const ov = @addWithOverflow(byte, 10);
99819996 if (ov[1] != 0) {
......@@ -10025,8 +10040,9 @@ comptime {
1002510040const std = @import("std");
1002610041
1002710042pub fn main() void {
10028 var x: u8 = 0b01010101;
10029 var y = @shlExact(x, 2);
10043 var x: u8 = 0b01010101; // runtime-known
10044 _ = &x;
10045 const y = @shlExact(x, 2);
1003010046 std.debug.print("value: {}\n", .{y});
1003110047}
1003210048 {#code_end#}
......@@ -10044,8 +10060,9 @@ comptime {
1004410060const std = @import("std");
1004510061
1004610062pub fn main() void {
10047 var x: u8 = 0b10101010;
10048 var y = @shrExact(x, 2);
10063 var x: u8 = 0b10101010; // runtime-known
10064 _ = &x;
10065 const y = @shrExact(x, 2);
1004910066 std.debug.print("value: {}\n", .{y});
1005010067}
1005110068 {#code_end#}
......@@ -10067,7 +10084,8 @@ const std = @import("std");
1006710084pub fn main() void {
1006810085 var a: u32 = 1;
1006910086 var b: u32 = 0;
10070 var c = a / b;
10087 _ = .{ &a, &b };
10088 const c = a / b;
1007110089 std.debug.print("value: {}\n", .{c});
1007210090}
1007310091 {#code_end#}
......@@ -10089,7 +10107,8 @@ const std = @import("std");
1008910107pub fn main() void {
1009010108 var a: u32 = 10;
1009110109 var b: u32 = 0;
10092 var c = a % b;
10110 _ = .{ &a, &b };
10111 const c = a % b;
1009310112 std.debug.print("value: {}\n", .{c});
1009410113}
1009510114 {#code_end#}
......@@ -10111,7 +10130,8 @@ const std = @import("std");
1011110130pub fn main() void {
1011210131 var a: u32 = 10;
1011310132 var b: u32 = 3;
10114 var c = @divExact(a, b);
10133 _ = .{ &a, &b };
10134 const c = @divExact(a, b);
1011510135 std.debug.print("value: {}\n", .{c});
1011610136}
1011710137 {#code_end#}
......@@ -10131,7 +10151,8 @@ const std = @import("std");
1013110151
1013210152pub fn main() void {
1013310153 var optional_number: ?i32 = null;
10134 var number = optional_number.?;
10154 _ = &optional_number;
10155 const number = optional_number.?;
1013510156 std.debug.print("value: {}\n", .{number});
1013610157}
1013710158 {#code_end#}
......@@ -10212,9 +10233,10 @@ comptime {
1021210233const std = @import("std");
1021310234
1021410235pub fn main() void {
10215 var err = error.AnError;
10236 const err = error.AnError;
1021610237 var number = @intFromError(err) + 500;
10217 var invalid_err = @errorFromInt(number);
10238 _ = &number;
10239 const invalid_err = @errorFromInt(number);
1021810240 std.debug.print("value: {}\n", .{invalid_err});
1021910241}
1022010242 {#code_end#}
......@@ -10245,7 +10267,8 @@ const Foo = enum {
1024510267
1024610268pub fn main() void {
1024710269 var a: u2 = 3;
10248 var b: Foo = @enumFromInt(a);
10270 _ = &a;
10271 const b: Foo = @enumFromInt(a);
1024910272 std.debug.print("value: {s}\n", .{@tagName(b)});
1025010273}
1025110274 {#code_end#}
......@@ -10402,17 +10425,18 @@ fn bar(f: *Foo) void {
1040210425 <p>At compile-time:</p>
1040310426 {#code_begin|test_err|test_comptime_out_of_bounds_float_to_integer_cast|float value '4294967296' cannot be stored in integer type 'i32'#}
1040410427comptime {
10405 const float: f32 = 4294967296;
10406 const int: i32 = @intFromFloat(float);
10407 _ = int;
10428 const float: f32 = 4294967296;
10429 const int: i32 = @intFromFloat(float);
10430 _ = int;
1040810431}
1040910432 {#code_end#}
1041010433 <p>At runtime:</p>
1041110434 {#code_begin|exe_err|runtime_out_of_bounds_float_to_integer_cast#}
1041210435pub fn main() void {
10413 var float: f32 = 4294967296;
10414 var int: i32 = @intFromFloat(float);
10415 _ = int;
10436 var float: f32 = 4294967296; // runtime-known
10437 _ = &float;
10438 const int: i32 = @intFromFloat(float);
10439 _ = int;
1041610440}
1041710441 {#code_end#}
1041810442 {#header_close#}
......@@ -10435,7 +10459,8 @@ comptime {
1043510459 {#code_begin|exe_err|runtime_invalid_null_pointer_cast#}
1043610460pub fn main() void {
1043710461 var opt_ptr: ?*i32 = null;
10438 var ptr: *i32 = @ptrCast(opt_ptr);
10462 _ = &opt_ptr;
10463 const ptr: *i32 = @ptrCast(opt_ptr);
1043910464 _ = ptr;
1044010465}
1044110466 {#code_end#}
......@@ -11120,7 +11145,9 @@ int foo(void) {
1112011145 {#code_begin|syntax|macro#}
1112111146pub export fn foo() c_int {
1112211147 var a: c_int = 1;
11148 _ = &a;
1112311149 var b: c_int = 2;
11150 _ = &b;
1112411151 return a + b;
1112511152}
1112611153pub const MAKELOCAL = @compileError("unable to translate C expr: unexpected token .Equal"); // macro.c:1:9