Skip to content

Commit 1c13ca5

Browse files
LemonBoyandrewrk
authored andcommitted
stage2: Use {s} instead of {} when formatting strings
1 parent dd973fb commit 1c13ca5

27 files changed

+503
-360
lines changed

lib/std/meta/trait.zig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,20 @@ pub fn isNumber(comptime T: type) bool {
298298
};
299299
}
300300

301+
pub fn isIntegerNumber(comptime T: type) bool {
302+
return switch (@typeInfo(T)) {
303+
.Int, .ComptimeInt => true,
304+
else => false,
305+
};
306+
}
307+
308+
pub fn isFloatingNumber(comptime T: type) bool {
309+
return switch (@typeInfo(T)) {
310+
.Float, .ComptimeFloat => true,
311+
else => false,
312+
};
313+
}
314+
301315
test "std.meta.trait.isNumber" {
302316
const NotANumber = struct {
303317
number: u8,

src/Cache.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ pub const Manifest = struct {
549549
.target, .target_must_resolve, .prereq => {},
550550
else => |err| {
551551
try err.printError(error_buf.writer());
552-
std.log.err("failed parsing {}: {}", .{ dep_file_basename, error_buf.items });
552+
std.log.err("failed parsing {s}: {s}", .{ dep_file_basename, error_buf.items });
553553
return error.InvalidDepFile;
554554
},
555555
}
@@ -561,7 +561,7 @@ pub const Manifest = struct {
561561
.prereq => |bytes| try self.addFilePost(bytes),
562562
else => |err| {
563563
try err.printError(error_buf.writer());
564-
std.log.err("failed parsing {}: {}", .{ dep_file_basename, error_buf.items });
564+
std.log.err("failed parsing {s}: {s}", .{ dep_file_basename, error_buf.items });
565565
return error.InvalidDepFile;
566566
},
567567
}

src/Compilation.zig

Lines changed: 47 additions & 47 deletions
Large diffs are not rendered by default.

src/DepTokenizer.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ pub const Token = union(enum) {
366366
.incomplete_quoted_prerequisite,
367367
.incomplete_target,
368368
=> |index_and_bytes| {
369-
try writer.print("{} '", .{self.errStr()});
369+
try writer.print("{s} '", .{self.errStr()});
370370
if (self == .incomplete_target) {
371371
const tmp = Token{ .target_must_resolve = index_and_bytes.bytes };
372372
try tmp.resolve(writer);
@@ -383,7 +383,7 @@ pub const Token = union(enum) {
383383
=> |index_and_char| {
384384
try writer.writeAll("illegal char ");
385385
try printUnderstandableChar(writer, index_and_char.char);
386-
try writer.print(" at position {}: {}", .{ index_and_char.index, self.errStr() });
386+
try writer.print(" at position {}: {s}", .{ index_and_char.index, self.errStr() });
387387
},
388388
}
389389
}
@@ -943,7 +943,7 @@ fn printSection(out: anytype, label: []const u8, bytes: []const u8) !void {
943943

944944
fn printLabel(out: anytype, label: []const u8, bytes: []const u8) !void {
945945
var buf: [80]u8 = undefined;
946-
var text = try std.fmt.bufPrint(buf[0..], "{} {} bytes ", .{ label, bytes.len });
946+
var text = try std.fmt.bufPrint(buf[0..], "{s} {} bytes ", .{ label, bytes.len });
947947
try out.writeAll(text);
948948
var i: usize = text.len;
949949
const end = 79;

src/Module.zig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ pub fn ensureDeclAnalyzed(self: *Module, decl: *Decl) InnerError!void {
953953
self.failed_decls.putAssumeCapacityNoClobber(decl, try Compilation.ErrorMsg.create(
954954
self.gpa,
955955
decl.src(),
956-
"unable to analyze: {}",
956+
"unable to analyze: {s}",
957957
.{@errorName(err)},
958958
));
959959
decl.analysis = .sema_failure_retryable;
@@ -1475,7 +1475,7 @@ fn getSrcModule(self: *Module, root_scope: *Scope.ZIRModule) !*zir.Module {
14751475
if (zir_module.error_msg) |src_err_msg| {
14761476
self.failed_files.putAssumeCapacityNoClobber(
14771477
&root_scope.base,
1478-
try Compilation.ErrorMsg.create(self.gpa, src_err_msg.byte_offset, "{}", .{src_err_msg.msg}),
1478+
try Compilation.ErrorMsg.create(self.gpa, src_err_msg.byte_offset, "{s}", .{src_err_msg.msg}),
14791479
);
14801480
root_scope.status = .unloaded_parse_failure;
14811481
return error.AnalysisFail;
@@ -1581,7 +1581,7 @@ pub fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void
15811581
decl.src_index = decl_i;
15821582
if (deleted_decls.remove(decl) == null) {
15831583
decl.analysis = .sema_failure;
1584-
const err_msg = try Compilation.ErrorMsg.create(self.gpa, tree.token_locs[name_tok].start, "redefinition of '{}'", .{decl.name});
1584+
const err_msg = try Compilation.ErrorMsg.create(self.gpa, tree.token_locs[name_tok].start, "redefinition of '{s}'", .{decl.name});
15851585
errdefer err_msg.destroy(self.gpa);
15861586
try self.failed_decls.putNoClobber(self.gpa, decl, err_msg);
15871587
} else {
@@ -1623,7 +1623,7 @@ pub fn analyzeContainer(self: *Module, container_scope: *Scope.Container) !void
16231623
decl.src_index = decl_i;
16241624
if (deleted_decls.remove(decl) == null) {
16251625
decl.analysis = .sema_failure;
1626-
const err_msg = try Compilation.ErrorMsg.create(self.gpa, name_loc.start, "redefinition of '{}'", .{decl.name});
1626+
const err_msg = try Compilation.ErrorMsg.create(self.gpa, name_loc.start, "redefinition of '{s}'", .{decl.name});
16271627
errdefer err_msg.destroy(self.gpa);
16281628
try self.failed_decls.putNoClobber(self.gpa, decl, err_msg);
16291629
} else if (!srcHashEql(decl.contents_hash, contents_hash)) {
@@ -1991,7 +1991,7 @@ pub fn analyzeExport(
19911991
self.failed_exports.putAssumeCapacityNoClobber(new_export, try Compilation.ErrorMsg.create(
19921992
self.gpa,
19931993
src,
1994-
"exported symbol collision: {}",
1994+
"exported symbol collision: {s}",
19951995
.{symbol_name},
19961996
));
19971997
// TODO: add a note
@@ -2007,7 +2007,7 @@ pub fn analyzeExport(
20072007
self.failed_exports.putAssumeCapacityNoClobber(new_export, try Compilation.ErrorMsg.create(
20082008
self.gpa,
20092009
src,
2010-
"unable to export: {}",
2010+
"unable to export: {s}",
20112011
.{@errorName(err)},
20122012
));
20132013
new_export.status = .failed_retryable;
@@ -2277,7 +2277,7 @@ pub fn createAnonymousDecl(
22772277
) !*Decl {
22782278
const name_index = self.getNextAnonNameIndex();
22792279
const scope_decl = scope.decl().?;
2280-
const name = try std.fmt.allocPrint(self.gpa, "{}__anon_{}", .{ scope_decl.name, name_index });
2280+
const name = try std.fmt.allocPrint(self.gpa, "{s}__anon_{}", .{ scope_decl.name, name_index });
22812281
defer self.gpa.free(name);
22822282
const name_hash = scope.namespace().fullyQualifiedNameHash(name);
22832283
const src_hash: std.zig.SrcHash = undefined;
@@ -2384,7 +2384,7 @@ pub fn analyzeDeref(self: *Module, scope: *Scope, src: usize, ptr: *Inst, ptr_sr
23842384

23852385
pub fn analyzeDeclRefByName(self: *Module, scope: *Scope, src: usize, decl_name: []const u8) InnerError!*Inst {
23862386
const decl = self.lookupDeclName(scope, decl_name) orelse
2387-
return self.fail(scope, src, "decl '{}' not found", .{decl_name});
2387+
return self.fail(scope, src, "decl '{s}' not found", .{decl_name});
23882388
return self.analyzeDeclRef(scope, src, decl);
23892389
}
23902390

src/astgen.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,7 @@ fn identifier(mod: *Module, scope: *Scope, rl: ResultLoc, ident: *ast.Node.OneTo
19551955
error.Overflow => return mod.failNode(
19561956
scope,
19571957
&ident.base,
1958-
"primitive integer type '{}' exceeds maximum bit width of 65535",
1958+
"primitive integer type '{s}' exceeds maximum bit width of 65535",
19591959
.{ident_name},
19601960
),
19611961
error.InvalidCharacter => break :integer,
@@ -2010,7 +2010,7 @@ fn identifier(mod: *Module, scope: *Scope, rl: ResultLoc, ident: *ast.Node.OneTo
20102010
return rlWrapPtr(mod, scope, rl, try addZIRInst(mod, scope, src, zir.Inst.DeclValInModule, .{ .decl = decl }, .{}));
20112011
}
20122012

2013-
return mod.failNode(scope, &ident.base, "use of undeclared identifier '{}'", .{ident_name});
2013+
return mod.failNode(scope, &ident.base, "use of undeclared identifier '{s}'", .{ident_name});
20142014
}
20152015

20162016
fn stringLiteral(mod: *Module, scope: *Scope, str_lit: *ast.Node.OneToken) InnerError!*zir.Inst {
@@ -2204,7 +2204,7 @@ fn ensureBuiltinParamCount(mod: *Module, scope: *Scope, call: *ast.Node.BuiltinC
22042204
return;
22052205

22062206
const s = if (count == 1) "" else "s";
2207-
return mod.failTok(scope, call.builtin_token, "expected {} parameter{}, found {}", .{ count, s, call.params_len });
2207+
return mod.failTok(scope, call.builtin_token, "expected {} parameter{s}, found {}", .{ count, s, call.params_len });
22082208
}
22092209

22102210
fn simpleCast(
@@ -2383,7 +2383,7 @@ fn builtinCall(mod: *Module, scope: *Scope, rl: ResultLoc, call: *ast.Node.Built
23832383
} else if (mem.eql(u8, builtin_name, "@compileError")) {
23842384
return compileError(mod, scope, call);
23852385
} else {
2386-
return mod.failTok(scope, call.builtin_token, "invalid builtin function: '{}'", .{builtin_name});
2386+
return mod.failTok(scope, call.builtin_token, "invalid builtin function: '{s}'", .{builtin_name});
23872387
}
23882388
}
23892389

src/codegen.zig

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ pub fn generateSymbol(
228228
.fail = try ErrorMsg.create(
229229
bin_file.allocator,
230230
src,
231-
"TODO implement generateSymbol for type '{}'",
231+
"TODO implement generateSymbol for type '{s}'",
232232
.{@tagName(t)},
233233
),
234234
};
@@ -2029,7 +2029,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
20292029
});
20302030
break :blk 0x84;
20312031
},
2032-
else => return self.fail(inst.base.src, "TODO implement condbr {} when condition is {}", .{ self.target.cpu.arch, @tagName(cond) }),
2032+
else => return self.fail(inst.base.src, "TODO implement condbr {s} when condition is {s}", .{ self.target.cpu.arch, @tagName(cond) }),
20332033
};
20342034
self.code.appendSliceAssumeCapacity(&[_]u8{ 0x0f, opcode });
20352035
const reloc = Reloc{ .rel32 = self.code.items.len };
@@ -2376,11 +2376,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
23762376
.arm, .armeb => {
23772377
for (inst.inputs) |input, i| {
23782378
if (input.len < 3 or input[0] != '{' or input[input.len - 1] != '}') {
2379-
return self.fail(inst.base.src, "unrecognized asm input constraint: '{}'", .{input});
2379+
return self.fail(inst.base.src, "unrecognized asm input constraint: '{s}'", .{input});
23802380
}
23812381
const reg_name = input[1 .. input.len - 1];
23822382
const reg = parseRegName(reg_name) orelse
2383-
return self.fail(inst.base.src, "unrecognized register: '{}'", .{reg_name});
2383+
return self.fail(inst.base.src, "unrecognized register: '{s}'", .{reg_name});
23842384
const arg = try self.resolveInst(inst.args[i]);
23852385
try self.genSetReg(inst.base.src, reg, arg);
23862386
}
@@ -2393,11 +2393,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
23932393

23942394
if (inst.output) |output| {
23952395
if (output.len < 4 or output[0] != '=' or output[1] != '{' or output[output.len - 1] != '}') {
2396-
return self.fail(inst.base.src, "unrecognized asm output constraint: '{}'", .{output});
2396+
return self.fail(inst.base.src, "unrecognized asm output constraint: '{s}'", .{output});
23972397
}
23982398
const reg_name = output[2 .. output.len - 1];
23992399
const reg = parseRegName(reg_name) orelse
2400-
return self.fail(inst.base.src, "unrecognized register: '{}'", .{reg_name});
2400+
return self.fail(inst.base.src, "unrecognized register: '{s}'", .{reg_name});
24012401
return MCValue{ .register = reg };
24022402
} else {
24032403
return MCValue.none;
@@ -2406,11 +2406,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
24062406
.aarch64 => {
24072407
for (inst.inputs) |input, i| {
24082408
if (input.len < 3 or input[0] != '{' or input[input.len - 1] != '}') {
2409-
return self.fail(inst.base.src, "unrecognized asm input constraint: '{}'", .{input});
2409+
return self.fail(inst.base.src, "unrecognized asm input constraint: '{s}'", .{input});
24102410
}
24112411
const reg_name = input[1 .. input.len - 1];
24122412
const reg = parseRegName(reg_name) orelse
2413-
return self.fail(inst.base.src, "unrecognized register: '{}'", .{reg_name});
2413+
return self.fail(inst.base.src, "unrecognized register: '{s}'", .{reg_name});
24142414
const arg = try self.resolveInst(inst.args[i]);
24152415
try self.genSetReg(inst.base.src, reg, arg);
24162416
}
@@ -2425,11 +2425,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
24252425

24262426
if (inst.output) |output| {
24272427
if (output.len < 4 or output[0] != '=' or output[1] != '{' or output[output.len - 1] != '}') {
2428-
return self.fail(inst.base.src, "unrecognized asm output constraint: '{}'", .{output});
2428+
return self.fail(inst.base.src, "unrecognized asm output constraint: '{s}'", .{output});
24292429
}
24302430
const reg_name = output[2 .. output.len - 1];
24312431
const reg = parseRegName(reg_name) orelse
2432-
return self.fail(inst.base.src, "unrecognized register: '{}'", .{reg_name});
2432+
return self.fail(inst.base.src, "unrecognized register: '{s}'", .{reg_name});
24332433
return MCValue{ .register = reg };
24342434
} else {
24352435
return MCValue.none;
@@ -2438,11 +2438,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
24382438
.riscv64 => {
24392439
for (inst.inputs) |input, i| {
24402440
if (input.len < 3 or input[0] != '{' or input[input.len - 1] != '}') {
2441-
return self.fail(inst.base.src, "unrecognized asm input constraint: '{}'", .{input});
2441+
return self.fail(inst.base.src, "unrecognized asm input constraint: '{s}'", .{input});
24422442
}
24432443
const reg_name = input[1 .. input.len - 1];
24442444
const reg = parseRegName(reg_name) orelse
2445-
return self.fail(inst.base.src, "unrecognized register: '{}'", .{reg_name});
2445+
return self.fail(inst.base.src, "unrecognized register: '{s}'", .{reg_name});
24462446
const arg = try self.resolveInst(inst.args[i]);
24472447
try self.genSetReg(inst.base.src, reg, arg);
24482448
}
@@ -2455,11 +2455,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
24552455

24562456
if (inst.output) |output| {
24572457
if (output.len < 4 or output[0] != '=' or output[1] != '{' or output[output.len - 1] != '}') {
2458-
return self.fail(inst.base.src, "unrecognized asm output constraint: '{}'", .{output});
2458+
return self.fail(inst.base.src, "unrecognized asm output constraint: '{s}'", .{output});
24592459
}
24602460
const reg_name = output[2 .. output.len - 1];
24612461
const reg = parseRegName(reg_name) orelse
2462-
return self.fail(inst.base.src, "unrecognized register: '{}'", .{reg_name});
2462+
return self.fail(inst.base.src, "unrecognized register: '{s}'", .{reg_name});
24632463
return MCValue{ .register = reg };
24642464
} else {
24652465
return MCValue.none;
@@ -2468,11 +2468,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
24682468
.x86_64, .i386 => {
24692469
for (inst.inputs) |input, i| {
24702470
if (input.len < 3 or input[0] != '{' or input[input.len - 1] != '}') {
2471-
return self.fail(inst.base.src, "unrecognized asm input constraint: '{}'", .{input});
2471+
return self.fail(inst.base.src, "unrecognized asm input constraint: '{s}'", .{input});
24722472
}
24732473
const reg_name = input[1 .. input.len - 1];
24742474
const reg = parseRegName(reg_name) orelse
2475-
return self.fail(inst.base.src, "unrecognized register: '{}'", .{reg_name});
2475+
return self.fail(inst.base.src, "unrecognized register: '{s}'", .{reg_name});
24762476
const arg = try self.resolveInst(inst.args[i]);
24772477
try self.genSetReg(inst.base.src, reg, arg);
24782478
}
@@ -2485,11 +2485,11 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
24852485

24862486
if (inst.output) |output| {
24872487
if (output.len < 4 or output[0] != '=' or output[1] != '{' or output[output.len - 1] != '}') {
2488-
return self.fail(inst.base.src, "unrecognized asm output constraint: '{}'", .{output});
2488+
return self.fail(inst.base.src, "unrecognized asm output constraint: '{s}'", .{output});
24892489
}
24902490
const reg_name = output[2 .. output.len - 1];
24912491
const reg = parseRegName(reg_name) orelse
2492-
return self.fail(inst.base.src, "unrecognized register: '{}'", .{reg_name});
2492+
return self.fail(inst.base.src, "unrecognized register: '{s}'", .{reg_name});
24932493
return MCValue{ .register = reg };
24942494
} else {
24952495
return MCValue.none;
@@ -3417,7 +3417,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
34173417
next_int_reg += 1;
34183418
}
34193419
},
3420-
else => return self.fail(src, "TODO implement function parameters of type {}", .{@tagName(ty.zigTypeTag())}),
3420+
else => return self.fail(src, "TODO implement function parameters of type {s}", .{@tagName(ty.zigTypeTag())}),
34213421
}
34223422
}
34233423
result.stack_byte_count = next_stack_offset;

0 commit comments

Comments
 (0)