Skip to content

Commit 095de44

Browse files
committed
std: remove unused variables
1 parent 79fecd5 commit 095de44

Some content is hidden

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

47 files changed

+68
-133
lines changed

lib/std/Thread.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,8 @@ pub fn cpuCount() CpuCountError!usize {
518518
},
519519
.haiku => {
520520
var count: u32 = undefined;
521-
var system_info: os.system_info = undefined;
522-
const rc = os.system.get_system_info(&system_info);
521+
// var system_info: os.system_info = undefined;
522+
// const rc = os.system.get_system_info(&system_info);
523523
count = system_info.cpu_count;
524524
return @intCast(usize, count);
525525
},

lib/std/base64.zig

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,6 @@ pub const Base64Encoder = struct {
112112
const out_len = encoder.calcSize(source.len);
113113
assert(dest.len >= out_len);
114114

115-
const nibbles = source.len / 3;
116-
const leftover = source.len - 3 * nibbles;
117-
118115
var acc: u12 = 0;
119116
var acc_len: u4 = 0;
120117
var out_idx: usize = 0;
@@ -223,7 +220,6 @@ pub const Base64Decoder = struct {
223220
if (decoder.pad_char) |pad_char| {
224221
const padding_len = acc_len / 2;
225222
var padding_chars: usize = 0;
226-
var i: usize = 0;
227223
for (leftover) |c| {
228224
if (c != pad_char) {
229225
return if (c == Base64Decoder.invalid_char) error.InvalidCharacter else error.InvalidPadding;
@@ -302,7 +298,6 @@ pub const Base64DecoderWithIgnore = struct {
302298
var leftover = source[leftover_idx.?..];
303299
if (decoder.pad_char) |pad_char| {
304300
var padding_chars: usize = 0;
305-
var i: usize = 0;
306301
for (leftover) |c| {
307302
if (decoder_with_ignore.char_is_ignored[c]) continue;
308303
if (c != pad_char) {

lib/std/c/tokenizer.zig

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ pub const Tokenizer = struct {
351351
pp_directive: bool = false,
352352

353353
pub fn next(self: *Tokenizer) Token {
354-
const start_index = self.index;
355354
var result = Token{
356355
.id = .Eof,
357356
.start = self.index,
@@ -1380,12 +1379,12 @@ test "operators" {
13801379

13811380
test "keywords" {
13821381
try expectTokens(
1383-
\\auto break case char const continue default do
1384-
\\double else enum extern float for goto if int
1385-
\\long register return short signed sizeof static
1386-
\\struct switch typedef union unsigned void volatile
1387-
\\while _Bool _Complex _Imaginary inline restrict _Alignas
1388-
\\_Alignof _Atomic _Generic _Noreturn _Static_assert _Thread_local
1382+
\\auto break case char const continue default do
1383+
\\double else enum extern float for goto if int
1384+
\\long register return short signed sizeof static
1385+
\\struct switch typedef union unsigned void volatile
1386+
\\while _Bool _Complex _Imaginary inline restrict _Alignas
1387+
\\_Alignof _Atomic _Generic _Noreturn _Static_assert _Thread_local
13891388
\\
13901389
, &[_]Token.Id{
13911390
.Keyword_auto,

lib/std/compress/gzip.zig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ pub fn GzipStream(comptime ReaderType: type) type {
5858
// Modification time, as a Unix timestamp.
5959
// If zero there's no timestamp available.
6060
const MTIME = mem.readIntLittle(u32, header[4..8]);
61-
// Extra flags
62-
const XFL = header[8];
63-
// Operating system where the compression took place
64-
const OS = header[9];
6561

6662
if (FLG & FEXTRA != 0) {
6763
// Skip the extra data, we could read and expose it to the user

lib/std/compress/zlib.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ pub fn ZlibStream(comptime ReaderType: type) type {
3434

3535
const CM = @truncate(u4, header[0]);
3636
const CINFO = @truncate(u4, header[0] >> 4);
37-
const FCHECK = @truncate(u5, header[1]);
3837
const FDICT = @truncate(u1, header[1] >> 5);
3938

4039
if ((@as(u16, header[0]) << 8 | header[1]) % 31 != 0)

lib/std/crypto/25519/scalar.zig

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,10 @@ pub const Scalar = struct {
330330
const carry9 = z02 >> 56;
331331
const c01 = carry9;
332332
const carry10 = (z12 + c01) >> 56;
333-
const t21 = @truncate(u64, z12 + c01) & 0xffffffffffffff;
334333
const c11 = carry10;
335334
const carry11 = (z22 + c11) >> 56;
336-
const t22 = @truncate(u64, z22 + c11) & 0xffffffffffffff;
337335
const c21 = carry11;
338336
const carry12 = (z32 + c21) >> 56;
339-
const t23 = @truncate(u64, z32 + c21) & 0xffffffffffffff;
340337
const c31 = carry12;
341338
const carry13 = (z42 + c31) >> 56;
342339
const t24 = @truncate(u64, z42 + c31) & 0xffffffffffffff;
@@ -605,13 +602,10 @@ const ScalarDouble = struct {
605602
const carry0 = z01 >> 56;
606603
const c00 = carry0;
607604
const carry1 = (z11 + c00) >> 56;
608-
const t100 = @as(u64, @truncate(u64, z11 + c00)) & 0xffffffffffffff;
609605
const c10 = carry1;
610606
const carry2 = (z21 + c10) >> 56;
611-
const t101 = @as(u64, @truncate(u64, z21 + c10)) & 0xffffffffffffff;
612607
const c20 = carry2;
613608
const carry3 = (z31 + c20) >> 56;
614-
const t102 = @as(u64, @truncate(u64, z31 + c20)) & 0xffffffffffffff;
615609
const c30 = carry3;
616610
const carry4 = (z41 + c30) >> 56;
617611
const t103 = @as(u64, @truncate(u64, z41 + c30)) & 0xffffffffffffff;

lib/std/crypto/aes.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ test "expand 128-bit key" {
118118
"d014f9a8c9ee2589e13f0cc8b6630ca6", "0c7b5a631319eafeb0398890664cfbb4", "df7d925a1f62b09da320626ed6757324", "12c07647c01f22c7bc42d2f37555114a", "6efcd876d2df54807c5df034c917c3b9", "6ea30afcbc238cf6ae82a4b4b54a338d", "90884413d280860a12a128421bc89739", "7c1f13f74208c219c021ae480969bf7b", "cc7505eb3e17d1ee82296c51c9481133", "2b3708a7f262d405bc3ebdbf4b617d62", "2b7e151628aed2a6abf7158809cf4f3c",
119119
};
120120
const enc = Aes128.initEnc(key);
121-
const dec = Aes128.initDec(key);
122121
var exp: [16]u8 = undefined;
123122

124123
for (enc.key_schedule.round_keys) |round_key, i| {

lib/std/crypto/aes/soft.zig

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ pub const Block = struct {
4949

5050
/// Encrypt a block with a round key.
5151
pub inline fn encrypt(block: Block, round_key: Block) Block {
52-
const src = &block.repr;
53-
5452
const s0 = block.repr[0];
5553
const s1 = block.repr[1];
5654
const s2 = block.repr[2];
@@ -66,8 +64,6 @@ pub const Block = struct {
6664

6765
/// Encrypt a block with the last round key.
6866
pub inline fn encryptLast(block: Block, round_key: Block) Block {
69-
const src = &block.repr;
70-
7167
const t0 = block.repr[0];
7268
const t1 = block.repr[1];
7369
const t2 = block.repr[2];
@@ -88,8 +84,6 @@ pub const Block = struct {
8884

8985
/// Decrypt a block with a round key.
9086
pub inline fn decrypt(block: Block, round_key: Block) Block {
91-
const src = &block.repr;
92-
9387
const s0 = block.repr[0];
9488
const s1 = block.repr[1];
9589
const s2 = block.repr[2];
@@ -105,8 +99,6 @@ pub const Block = struct {
10599

106100
/// Decrypt a block with the last round key.
107101
pub inline fn decryptLast(block: Block, round_key: Block) Block {
108-
const src = &block.repr;
109-
110102
const t0 = block.repr[0];
111103
const t1 = block.repr[1];
112104
const t2 = block.repr[2];

lib/std/crypto/aes_gcm.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ test "Aes256Gcm - Empty message and no associated data" {
114114
const ad = "";
115115
const m = "";
116116
var c: [m.len]u8 = undefined;
117-
var m2: [m.len]u8 = undefined;
118117
var tag: [Aes256Gcm.tag_length]u8 = undefined;
119118

120119
Aes256Gcm.encrypt(&c, &tag, m, ad, nonce, key);

lib/std/crypto/aes_ocb.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ test "AesOcb test vector 1" {
271271
var c: [0]u8 = undefined;
272272
Aes128Ocb.encrypt(&c, &tag, "", "", nonce, k);
273273

274-
var expected_c: [c.len]u8 = undefined;
275274
var expected_tag: [tag.len]u8 = undefined;
276275
_ = try hexToBytes(&expected_tag, "785407BFFFC8AD9EDCC5520AC9111EE6");
277276

lib/std/crypto/bcrypt.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ const State = struct {
4848
fn expand0(state: *State, key: []const u8) void {
4949
var i: usize = 0;
5050
var j: usize = 0;
51-
var t: u32 = undefined;
5251
while (i < state.subkeys.len) : (i += 1) {
5352
state.subkeys[i] ^= toWord(key, &j);
5453
}
@@ -75,7 +74,6 @@ const State = struct {
7574
fn expand(state: *State, data: []const u8, key: []const u8) void {
7675
var i: usize = 0;
7776
var j: usize = 0;
78-
var t: u32 = undefined;
7977
while (i < state.subkeys.len) : (i += 1) {
8078
state.subkeys[i] ^= toWord(key, &j);
8179
}

lib/std/crypto/chacha20.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,6 @@ fn ChaChaWith64BitNonce(comptime rounds_nb: usize) type {
444444
if (comptime @sizeOf(usize) > 4) {
445445
// A big block is giant: 256 GiB, but we can avoid this limitation
446446
var remaining_blocks: u32 = @intCast(u32, (in.len / big_block));
447-
var i: u32 = 0;
448447
while (remaining_blocks > 0) : (remaining_blocks -= 1) {
449448
ChaChaImpl(rounds_nb).chacha20Xor(out[cursor .. cursor + big_block], in[cursor .. cursor + big_block], k, c);
450449
c[1] += 1; // upper 32-bit of counter, generic chacha20Xor() doesn't know about this.

lib/std/dynamic_library.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ test "dynamic_library" {
407407
else => return error.SkipZigTest,
408408
};
409409

410-
const dynlib = DynLib.open(libname) catch |err| {
410+
_ = DynLib.open(libname) catch |err| {
411411
try testing.expect(err == error.FileNotFound);
412412
return;
413413
};

lib/std/event/channel.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ test "std.event.Channel wraparound" {
308308

309309
// add items to channel and pull them out until
310310
// the buffer wraps around, make sure it doesn't crash.
311-
var result: i32 = undefined;
312311
channel.put(5);
313312
try testing.expectEqual(@as(i32, 5), channel.get());
314313
channel.put(6);

lib/std/event/group.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ test "std.event.Group" {
130130
// TODO this file has bit-rotted. repair it
131131
if (true) return error.SkipZigTest;
132132

133-
const handle = async testGroup(std.heap.page_allocator);
133+
_ = async testGroup(std.heap.page_allocator);
134134
}
135135
fn testGroup(allocator: *Allocator) callconv(.Async) void {
136136
var count: usize = 0;

lib/std/event/loop.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ pub const Loop = struct {
676676
fn run(func_args: Args, loop: *Loop, allocator: *mem.Allocator) void {
677677
loop.beginOneEvent();
678678
loop.yield();
679-
const result = @call(.{}, func, func_args);
679+
@call(.{}, func, func_args); // compile error when called with non-void ret type
680680
suspend {
681681
loop.finishOneEvent();
682682
allocator.destroy(@frame());

lib/std/event/rwlock.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ test "std.event.RwLock" {
225225
var lock = RwLock.init();
226226
defer lock.deinit();
227227

228-
const handle = testLock(std.heap.page_allocator, &lock);
228+
_ = testLock(std.heap.page_allocator, &lock);
229229

230230
const expected_result = [1]i32{shared_it_count * @intCast(i32, shared_test_data.len)} ** shared_test_data.len;
231231
try testing.expectEqualSlices(i32, expected_result, shared_test_data);

lib/std/fmt.zig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ pub fn formatFloatHexadecimal(
11351135

11361136
// +1 for the decimal part.
11371137
var buf: [1 + mantissa_digits]u8 = undefined;
1138-
const N = formatIntBuf(&buf, mantissa, 16, .lower, .{ .fill = '0', .width = 1 + mantissa_digits });
1138+
_ = formatIntBuf(&buf, mantissa, 16, .lower, .{ .fill = '0', .width = 1 + mantissa_digits });
11391139

11401140
try writer.writeAll("0x");
11411141
try writer.writeByte(buf[0]);
@@ -2157,7 +2157,6 @@ test "custom" {
21572157
}
21582158
};
21592159

2160-
var buf1: [32]u8 = undefined;
21612160
var value = Vec2{
21622161
.x = 10.2,
21632162
.y = 2.22,
@@ -2215,7 +2214,7 @@ test "union" {
22152214
try std.testing.expect(mem.eql(u8, uu_result[0..3], "UU@"));
22162215

22172216
const eu_result = try bufPrint(buf[0..], "{}", .{eu_inst});
2218-
try std.testing.expect(mem.eql(u8, uu_result[0..3], "EU@"));
2217+
try std.testing.expect(mem.eql(u8, eu_result[0..3], "EU@"));
22192218
}
22202219

22212220
test "enum" {

lib/std/fmt/parse_float.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ const ParseResult = enum {
200200

201201
fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
202202
var digit_index: usize = 0;
203-
var negative = false;
204203
var negative_exp = false;
205204
var exponent: i32 = 0;
206205

lib/std/fs.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ pub const Dir = struct {
473473
}
474474

475475
var stat_info: os.libc_stat = undefined;
476-
const rc2 = os.system._kern_read_stat(
476+
_ = os.system._kern_read_stat(
477477
self.dir.fd,
478478
&haiku_entry.d_name,
479479
false,
@@ -2434,7 +2434,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
24342434
}) catch continue;
24352435

24362436
var real_path_buf: [MAX_PATH_BYTES]u8 = undefined;
2437-
if (os.realpathZ(&resolved_path_buf, &real_path_buf)) |real_path| {
2437+
if (os.realpathZ(resolved_path, &real_path_buf)) |real_path| {
24382438
// found a file, and hope it is the right file
24392439
if (real_path.len > out_buffer.len)
24402440
return error.NameTooLong;

lib/std/hash/auto_hash.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub fn hash(hasher: anytype, key: anytype, comptime strat: HashStrategy) void {
146146
.Union => |info| {
147147
if (info.tag_type) |tag_type| {
148148
const tag = meta.activeTag(key);
149-
const s = hash(hasher, tag, strat);
149+
hash(hasher, tag, strat);
150150
inline for (info.fields) |field| {
151151
if (@field(tag_type, field.name) == tag) {
152152
hash(hasher, @field(key, field.name), strat);

lib/std/hash/cityhash.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ fn SMHasherTest(comptime hash_fn: anytype) u32 {
353353

354354
var key: [256]u8 = undefined;
355355
var hashes_bytes: [256 * @sizeOf(HashResult)]u8 = undefined;
356-
var final: HashResult = 0;
357356

358357
std.mem.set(u8, &key, 0);
359358
std.mem.set(u8, &hashes_bytes, 0);

lib/std/hash/wyhash.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,6 @@ pub const Wyhash = struct {
166166
}
167167

168168
pub fn final(self: *Wyhash) u64 {
169-
const seed = self.state.seed;
170-
const rem_len = @intCast(u5, self.buf_len);
171169
const rem_key = self.buf[0..self.buf_len];
172170

173171
return self.state.final(rem_key);

lib/std/hash_map.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1809,7 +1809,7 @@ test "std.hash_map getOrPut" {
18091809

18101810
i = 0;
18111811
while (i < 20) : (i += 1) {
1812-
var n = try map.getOrPutValue(i, 1);
1812+
_ = try map.getOrPutValue(i, 1);
18131813
}
18141814

18151815
i = 0;

lib/std/leb128.zig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,15 @@ fn test_read_ileb128_seq(comptime T: type, comptime N: usize, encoded: []const u
198198
var reader = std.io.fixedBufferStream(encoded);
199199
var i: usize = 0;
200200
while (i < N) : (i += 1) {
201-
const v1 = try readILEB128(T, reader.reader());
201+
_ = try readILEB128(T, reader.reader());
202202
}
203203
}
204204

205205
fn test_read_uleb128_seq(comptime T: type, comptime N: usize, encoded: []const u8) !void {
206206
var reader = std.io.fixedBufferStream(encoded);
207207
var i: usize = 0;
208208
while (i < N) : (i += 1) {
209-
const v1 = try readULEB128(T, reader.reader());
209+
_ = try readULEB128(T, reader.reader());
210210
}
211211
}
212212

@@ -309,7 +309,6 @@ fn test_write_leb128(value: anytype) !void {
309309
const B = std.meta.Int(signedness, larger_type_bits);
310310

311311
const bytes_needed = bn: {
312-
const S = std.meta.Int(signedness, @sizeOf(T) * 8);
313312
if (@typeInfo(T).Int.bits <= 7) break :bn @as(u16, 1);
314313

315314
const unused_bits = if (value < 0) @clz(T, ~value) else @clz(T, value);

lib/std/linked_list.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ test "basic TailQueue test" {
359359
}
360360
}
361361

362-
var first = list.popFirst(); // {2, 3, 4, 5}
363-
var last = list.pop(); // {2, 3, 4}
362+
_ = list.popFirst(); // {2, 3, 4, 5}
363+
_ = list.pop(); // {2, 3, 4}
364364
list.remove(&three); // {2, 4}
365365

366366
try testing.expect(list.first.?.data == 2);

lib/std/math/big/int.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,8 +2000,6 @@ fn llmulacc_karatsuba(allocator: *Allocator, r: []Limb, x: []const Limb, y: []co
20002000
} else {
20012001
llsub(j1, y0[0..y0_len], y1[0..y1_len]);
20022002
}
2003-
const j0_len = llnormalize(j0);
2004-
const j1_len = llnormalize(j1);
20052003
if (x_cmp == y_cmp) {
20062004
mem.set(Limb, tmp[0..length], 0);
20072005
llmulacc(allocator, tmp, j0, j1);

lib/std/math/big/rational.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ pub const Rational = struct {
204204
const esize = math.floatExponentBits(T);
205205
const ebias = (1 << (esize - 1)) - 1;
206206
const emin = 1 - ebias;
207-
const emax = ebias;
208207

209208
if (self.p.eqZero()) {
210209
return 0;

lib/std/math/complex/ldexp.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
const std = @import("../../std.zig");
1313
const debug = std.debug;
1414
const math = std.math;
15+
const testing = std.testing;
1516
const cmath = math.complex;
1617
const testing = std.testing;
1718
const Complex = cmath.Complex;
@@ -27,6 +28,11 @@ pub fn ldexp_cexp(z: anytype, expt: i32) @TypeOf(z) {
2728
};
2829
}
2930

31+
test "ldexp_cexp" {
32+
try std.testing.expectEqual(ldexp_cexp(Complex(f32).init(0.01, 10), 1), Complex(f32).init(-5.44588740e+32, -3.53089629e+32));
33+
try std.testing.expectEqual(ldexp_cexp(Complex(f32).init(18.2, 10), 20), Complex(f32).init(-2.85521341e+38, -1.85120655e+38));
34+
}
35+
3036
fn frexp_exp32(x: f32, expt: *i32) f32 {
3137
const k = 235; // reduction constant
3238
const kln2 = 162.88958740; // k * ln2

0 commit comments

Comments
 (0)