Commit 18c1007a34

Jacob G-W <jacoblevgw@gmail.com>
2021-06-12 20:48:13
stage2 tests: remove unused vars
1 parent f8b8f50
Changed files (6)
lib/std/zig/parse.zig
@@ -1005,7 +1005,7 @@ const Parser = struct {
                 },
             });
         };
-        const else_payload = try p.parsePayload();
+        _ = try p.parsePayload();
         const else_expr = try p.expectStatement();
         return p.addNode(.{
             .tag = .@"if",
@@ -1189,7 +1189,7 @@ const Parser = struct {
                 });
             }
         };
-        const else_payload = try p.parsePayload();
+        _ = try p.parsePayload();
         const else_expr = try p.expectStatement();
         return p.addNode(.{
             .tag = .@"while",
lib/std/debug.zig
@@ -896,7 +896,6 @@ fn printLineFromFileAnyOs(out_stream: anytype, line_info: LineInfo) !void {
     var buf: [mem.page_size]u8 = undefined;
     var line: usize = 1;
     var column: usize = 1;
-    var abs_index: usize = 0;
     while (true) {
         const amt_read = try f.read(buf[0..]);
         const slice = buf[0..amt_read];
lib/std/pdb.zig
@@ -590,7 +590,8 @@ pub const Pdb = struct {
 
         var sect_cont_offset: usize = 0;
         if (section_contrib_size != 0) {
-            const version = reader.readEnum(SectionContrSubstreamVersion, .Little) catch |err| switch (err) {
+            // the version
+            _ = reader.readEnum(SectionContrSubstreamVersion, .Little) catch |err| switch (err) {
                 error.InvalidValue => return error.InvalidDebugInfo,
                 else => |e| return e,
             };
@@ -616,7 +617,8 @@ pub const Pdb = struct {
 
         // Parse the InfoStreamHeader.
         const version = try reader.readIntLittle(u32);
-        const signature = try reader.readIntLittle(u32);
+        // The signature
+        _ = try reader.readIntLittle(u32);
         const age = try reader.readIntLittle(u32);
         const guid = try reader.readBytesNoEof(16);
 
test/stage2/cbe.zig
@@ -93,16 +93,16 @@ pub fn addCases(ctx: *TestContext) !void {
         , "");
         case.addError(
             \\pub export fn main() c_int {
-            \\    const c = @intToError(0);
+            \\    _ = @intToError(0);
             \\    return 0;
             \\}
-        , &.{":2:27: error: integer value 0 represents no error"});
+        , &.{":2:21: error: integer value 0 represents no error"});
         case.addError(
             \\pub export fn main() c_int {
-            \\    const c = @intToError(3);
+            \\    _ = @intToError(3);
             \\    return 0;
             \\}
-        , &.{":2:27: error: integer value 3 represents no error"});
+        , &.{":2:21: error: integer value 3 represents no error"});
     }
 
     {
@@ -383,6 +383,7 @@ pub fn addCases(ctx: *TestContext) !void {
             \\        true => 2,
             \\        false => 3,
             \\    };
+            \\    _  = b;
             \\}
         , &.{
             ":6:9: error: duplicate switch value",
@@ -398,6 +399,7 @@ pub fn addCases(ctx: *TestContext) !void {
             \\        f64, i32 => 3,
             \\        else => 4,
             \\    };
+            \\    _ = b;
             \\}
         , &.{
             ":6:14: error: duplicate switch value",
@@ -414,6 +416,7 @@ pub fn addCases(ctx: *TestContext) !void {
             \\        f16...f64 => 3,
             \\        else => 4,
             \\    };
+            \\    _ = b;
             \\}
         , &.{
             ":3:30: error: ranges not allowed when switching on type 'type'",
@@ -431,6 +434,7 @@ pub fn addCases(ctx: *TestContext) !void {
             \\        3 => 40,
             \\        else => 50,
             \\    };
+            \\    _ = b;
             \\}
         , &.{
             ":8:14: error: unreachable else prong; all cases already handled",
@@ -556,10 +560,10 @@ pub fn addCases(ctx: *TestContext) !void {
             \\const E1 = packed enum { a, b, c };
             \\const E2 = extern enum { a, b, c };
             \\export fn foo() void {
-            \\    const x = E1.a;
+            \\    _ = E1.a;
             \\}
             \\export fn bar() void {
-            \\    const x = E2.a;
+            \\    _ = E2.a;
             \\}
         , &.{
             ":1:12: error: enums do not support 'packed' or 'extern'; instead provide an explicit integer tag type",
@@ -579,10 +583,10 @@ pub fn addCases(ctx: *TestContext) !void {
             \\    c,
             \\};
             \\export fn foo() void {
-            \\    const x = E1.a;
+            \\    _ = E1.a;
             \\}
             \\export fn bar() void {
-            \\    const x = E2.a;
+            \\    _ = E2.a;
             \\}
         , &.{
             ":3:5: error: enum fields cannot be marked comptime",
@@ -621,7 +625,7 @@ pub fn addCases(ctx: *TestContext) !void {
             \\    c,
             \\};
             \\export fn foo() void {
-            \\    const x = E1.a;
+            \\    _ = E1.a;
             \\}
         , &.{
             ":3:7: error: expected ',', found 'align'",
@@ -638,7 +642,7 @@ pub fn addCases(ctx: *TestContext) !void {
             \\    _,
             \\};
             \\export fn foo() void {
-            \\    const x = E1.a;
+            \\    _ = E1.a;
             \\}
         , &.{
             ":6:5: error: redundant non-exhaustive enum mark",
@@ -653,7 +657,7 @@ pub fn addCases(ctx: *TestContext) !void {
             \\    _ = 10,
             \\};
             \\export fn foo() void {
-            \\    const x = E1.a;
+            \\    _ = E1.a;
             \\}
         , &.{
             ":5:9: error: '_' is used to mark an enum as non-exhaustive and cannot be assigned a value",
@@ -662,7 +666,7 @@ pub fn addCases(ctx: *TestContext) !void {
         case.addError(
             \\const E1 = enum {};
             \\export fn foo() void {
-            \\    const x = E1.a;
+            \\    _ = E1.a;
             \\}
         , &.{
             ":1:12: error: enum declarations must have at least one tag",
@@ -671,7 +675,7 @@ pub fn addCases(ctx: *TestContext) !void {
         case.addError(
             \\const E1 = enum { a, b, _ };
             \\export fn foo() void {
-            \\    const x = E1.a;
+            \\    _ = E1.a;
             \\}
         , &.{
             ":1:12: error: non-exhaustive enum missing integer tag type",
@@ -681,7 +685,7 @@ pub fn addCases(ctx: *TestContext) !void {
         case.addError(
             \\const E1 = enum { a, b, c, b, d };
             \\pub export fn main() c_int {
-            \\    const x = E1.a;
+            \\    _ = E1.a;
             \\}
         , &.{
             ":1:28: error: duplicate enum tag",
@@ -691,28 +695,28 @@ pub fn addCases(ctx: *TestContext) !void {
         case.addError(
             \\pub export fn main() c_int {
             \\    const a = true;
-            \\    const b = @enumToInt(a);
+            \\    _ = @enumToInt(a);
             \\}
         , &.{
-            ":3:26: error: expected enum or tagged union, found bool",
+            ":3:20: error: expected enum or tagged union, found bool",
         });
 
         case.addError(
             \\pub export fn main() c_int {
             \\    const a = 1;
-            \\    const b = @intToEnum(bool, a);
+            \\    _ = @intToEnum(bool, a);
             \\}
         , &.{
-            ":3:26: error: expected enum, found bool",
+            ":3:20: error: expected enum, found bool",
         });
 
         case.addError(
             \\const E = enum { a, b, c };
             \\pub export fn main() c_int {
-            \\    const b = @intToEnum(E, 3);
+            \\    _ = @intToEnum(E, 3);
             \\}
         , &.{
-            ":3:15: error: enum 'test_case.E' has no tag with value 3",
+            ":3:9: error: enum 'test_case.E' has no tag with value 3",
             ":1:11: note: enum declared here",
         });
 
@@ -780,10 +784,10 @@ pub fn addCases(ctx: *TestContext) !void {
         case.addError(
             \\const E = enum { a, b, c };
             \\pub export fn main() c_int {
-            \\    var x = E.d;
+            \\    _ = E.d;
             \\}
         , &.{
-            ":3:14: error: enum 'test_case.E' has no member named 'd'",
+            ":3:10: error: enum 'test_case.E' has no member named 'd'",
             ":1:11: note: enum declared here",
         });
 
@@ -791,6 +795,7 @@ pub fn addCases(ctx: *TestContext) !void {
             \\const E = enum { a, b, c };
             \\pub export fn main() c_int {
             \\    var x: E = .d;
+            \\    _ = x;
             \\}
         , &.{
             ":3:17: error: enum 'test_case.E' has no field named 'd'",
test/stage2/test.zig
@@ -259,6 +259,7 @@ pub fn addCases(ctx: *TestContext) !void {
         case.addCompareOutput(
             \\pub fn main() void {
             \\    var x: usize = 0;
+            \\    _ = x;
             \\    const z = @TypeOf(x, @as(u128, 5));
             \\    assert(z == u128);
             \\}
@@ -283,9 +284,9 @@ pub fn addCases(ctx: *TestContext) !void {
         );
         case.addError(
             \\pub fn main() void {
-            \\    const z = @TypeOf(true, 1);
+            \\    _ = @TypeOf(true, 1);
             \\}
-        , &[_][]const u8{":2:15: error: incompatible types: 'bool' and 'comptime_int'"});
+        , &[_][]const u8{":2:9: error: incompatible types: 'bool' and 'comptime_int'"});
     }
 
     {
@@ -746,6 +747,7 @@ pub fn addCases(ctx: *TestContext) !void {
             \\        \\ cool thx
             \\        \\
             \\    ;
+            \\    _ = ignore;
             \\    add('ぁ', '\x03');
             \\}
             \\
@@ -987,6 +989,7 @@ pub fn addCases(ctx: *TestContext) !void {
         \\            return bar;
         \\        }
         \\    };
+        \\    _ = S;
         \\}
     , &.{
         ":5:20: error: 'bar' not accessible from inner function",
@@ -1072,6 +1075,7 @@ pub fn addCases(ctx: *TestContext) !void {
             \\    @compileLog(b, 20, f, x);
             \\    @compileLog(1000);
             \\    var bruh: usize = true;
+            \\    _ = bruh;
             \\    unreachable;
             \\}
             \\export fn other() void {
@@ -1217,6 +1221,7 @@ pub fn addCases(ctx: *TestContext) !void {
         case.addError(
             \\pub fn main() void {
             \\    var x = null;
+            \\    _ = x;
             \\}
         , &[_][]const u8{
             ":2:9: error: variable of type '@Type(.Null)' must be const or comptime",
@@ -1456,14 +1461,14 @@ pub fn addCases(ctx: *TestContext) !void {
         case.addCompareOutput(
             \\pub fn main() void {
             \\    const E = error{ A, B, D } || error { A, B, C };
-            \\    const a = E.A;
-            \\    const b = E.B;
-            \\    const c = E.C;
-            \\    const d = E.D;
+            \\    E.A catch {};
+            \\    E.B catch {};
+            \\    E.C catch {};
+            \\    E.D catch {};
             \\    const E2 = error { X, Y } || @TypeOf(error.Z);
-            \\    const x = E2.X;
-            \\    const y = E2.Y;
-            \\    const z = E2.Z;
+            \\    E2.X catch {};
+            \\    E2.Y catch {};
+            \\    E2.Z catch {};
             \\    assert(anyerror || error { Z } == anyerror);
             \\}
             \\fn assert(b: bool) void {
@@ -1485,6 +1490,7 @@ pub fn addCases(ctx: *TestContext) !void {
             \\          [arg1] "{rdi}" (code)
             \\        : "rcx", "r11", "memory"
             \\    );
+            \\    _ = x;
             \\}
         , &[_][]const u8{":4:27: error: expected type, found comptime_int"});
     }
test/stage2/wasm.zig
@@ -76,6 +76,10 @@ pub fn addCases(ctx: *TestContext) !void {
             \\    var i: u32 = 5;
             \\    var y: f32 = 42.0;
             \\    var x: u32 = 10;
+            \\    if (false) {
+            \\      y;
+            \\      x;
+            \\    }
             \\    return i;
             \\}
         , "5\n");
@@ -84,6 +88,7 @@ pub fn addCases(ctx: *TestContext) !void {
             \\pub export fn _start() u32 {
             \\    var i: u32 = 5;
             \\    var y: f32 = 42.0;
+            \\    _ = y;
             \\    var x: u32 = 10;
             \\    foo(i, x);
             \\    i = x;
@@ -388,6 +393,10 @@ pub fn addCases(ctx: *TestContext) !void {
             \\pub export fn _start() i32 {
             \\    var number1 = Number.One;
             \\    var number2: Number = .Two;
+            \\    if (false) {
+            \\        number1;
+            \\        number2;
+            \\    }
             \\    const number3 = @intToEnum(Number, 2);
             \\
             \\    return @enumToInt(number3);