From 9d4561ef0082728bbba085e8a4689ccc93a37b27 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Tue, 16 Aug 2022 16:55:49 +0300 Subject: AstGen: detect declarations shadowing locals Closes #9355 --- lib/std/bounded_array.zig | 14 +++++++------- lib/std/debug.zig | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/std/bounded_array.zig b/lib/std/bounded_array.zig index 8134beb6e3..3d74e5e47f 100644 --- a/lib/std/bounded_array.zig +++ b/lib/std/bounded_array.zig @@ -15,16 +15,16 @@ const testing = std.testing; /// var slice = a.slice(); // a slice of the 64-byte array /// var a_clone = a; // creates a copy - the structure doesn't use any internal pointers /// ``` -pub fn BoundedArray(comptime T: type, comptime capacity: usize) type { +pub fn BoundedArray(comptime T: type, comptime buffer_capacity: usize) type { return struct { const Self = @This(); - buffer: [capacity]T = undefined, + buffer: [buffer_capacity]T = undefined, len: usize = 0, /// Set the actual length of the slice. /// Returns error.Overflow if it exceeds the length of the backing array. pub fn init(len: usize) error{Overflow}!Self { - if (len > capacity) return error.Overflow; + if (len > buffer_capacity) return error.Overflow; return Self{ .len = len }; } @@ -41,7 +41,7 @@ pub fn BoundedArray(comptime T: type, comptime capacity: usize) type { /// Adjust the slice's length to `len`. /// Does not initialize added items if any. pub fn resize(self: *Self, len: usize) error{Overflow}!void { - if (len > capacity) return error.Overflow; + if (len > buffer_capacity) return error.Overflow; self.len = len; } @@ -69,7 +69,7 @@ pub fn BoundedArray(comptime T: type, comptime capacity: usize) type { /// Check that the slice can hold at least `additional_count` items. pub fn ensureUnusedCapacity(self: Self, additional_count: usize) error{Overflow}!void { - if (self.len + additional_count > capacity) { + if (self.len + additional_count > buffer_capacity) { return error.Overflow; } } @@ -83,7 +83,7 @@ pub fn BoundedArray(comptime T: type, comptime capacity: usize) type { /// Increase length by 1, returning pointer to the new item. /// Asserts that there is space for the new item. pub fn addOneAssumeCapacity(self: *Self) *T { - assert(self.len < capacity); + assert(self.len < buffer_capacity); self.len += 1; return &self.slice()[self.len - 1]; } @@ -236,7 +236,7 @@ pub fn BoundedArray(comptime T: type, comptime capacity: usize) type { pub fn appendNTimesAssumeCapacity(self: *Self, value: T, n: usize) void { const old_len = self.len; self.len += n; - assert(self.len <= capacity); + assert(self.len <= buffer_capacity); mem.set(T, self.slice()[old_len..self.len], value); } diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 0738b5af0b..33b8a98d7f 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1947,7 +1947,7 @@ noinline fn showMyTrace() usize { /// For more advanced usage, see `ConfigurableTrace`. pub const Trace = ConfigurableTrace(2, 4, builtin.mode == .Debug); -pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize, comptime enabled: bool) type { +pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize, comptime is_enabled: bool) type { return struct { addrs: [actual_size][stack_frame_count]usize = undefined, notes: [actual_size][]const u8 = undefined, @@ -1956,7 +1956,7 @@ pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize const actual_size = if (enabled) size else 0; const Index = if (enabled) usize else u0; - pub const enabled = enabled; + pub const enabled = is_enabled; pub const add = if (enabled) addNoInline else addNoOp; -- cgit v1.2.3