diff --git a/doc/langref.html.in b/doc/langref.html.in index a30670b0c701..17792d6470ed 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -10086,8 +10086,8 @@ ContainerMembers <- TestDecl ContainerMembers / TopLevelComptime ContainerMembers / KEYWORD_pub? TopLevelDecl ContainerMembers - / KEYWORD_pub? ContainerField COMMA ContainerMembers - / KEYWORD_pub? ContainerField + / ContainerField COMMA ContainerMembers + / ContainerField / TestDecl <- KEYWORD_test STRINGLITERAL Block diff --git a/lib/std/child_process.zig b/lib/std/child_process.zig index 7fb663ac28d3..d786c3f4de35 100644 --- a/lib/std/child_process.zig +++ b/lib/std/child_process.zig @@ -17,35 +17,35 @@ const TailQueue = std.TailQueue; const maxInt = std.math.maxInt; pub const ChildProcess = struct { - pub pid: if (os.windows.is_the_target) void else i32, - pub handle: if (os.windows.is_the_target) windows.HANDLE else void, - pub thread_handle: if (os.windows.is_the_target) windows.HANDLE else void, + pid: if (os.windows.is_the_target) void else i32, + handle: if (os.windows.is_the_target) windows.HANDLE else void, + thread_handle: if (os.windows.is_the_target) windows.HANDLE else void, - pub allocator: *mem.Allocator, + allocator: *mem.Allocator, - pub stdin: ?File, - pub stdout: ?File, - pub stderr: ?File, + stdin: ?File, + stdout: ?File, + stderr: ?File, - pub term: ?(SpawnError!Term), + term: ?(SpawnError!Term), - pub argv: []const []const u8, + argv: []const []const u8, /// Leave as null to use the current env map using the supplied allocator. - pub env_map: ?*const BufMap, + env_map: ?*const BufMap, - pub stdin_behavior: StdIo, - pub stdout_behavior: StdIo, - pub stderr_behavior: StdIo, + stdin_behavior: StdIo, + stdout_behavior: StdIo, + stderr_behavior: StdIo, /// Set to change the user id when spawning the child process. - pub uid: if (os.windows.is_the_target) void else ?u32, + uid: if (os.windows.is_the_target) void else ?u32, /// Set to change the group id when spawning the child process. - pub gid: if (os.windows.is_the_target) void else ?u32, + gid: if (os.windows.is_the_target) void else ?u32, /// Set to change the current working directory when spawning the child process. - pub cwd: ?[]const u8, + cwd: ?[]const u8, err_pipe: if (os.windows.is_the_target) void else [2]os.fd_t, llnode: if (os.windows.is_the_target) void else TailQueue(*ChildProcess).Node, diff --git a/lib/std/heap.zig b/lib/std/heap.zig index b968b6242f6a..f3a0d457d2a0 100644 --- a/lib/std/heap.zig +++ b/lib/std/heap.zig @@ -338,7 +338,7 @@ pub const HeapAllocator = switch (builtin.os) { /// This allocator takes an existing allocator, wraps it, and provides an interface /// where you can allocate without freeing, and then free it all together. pub const ArenaAllocator = struct { - pub allocator: Allocator, + allocator: Allocator, child_allocator: *Allocator, buffer_list: std.SinglyLinkedList([]u8), diff --git a/lib/std/http/headers.zig b/lib/std/http/headers.zig index a8dfa686298f..7ee035ce80ce 100644 --- a/lib/std/http/headers.zig +++ b/lib/std/http/headers.zig @@ -28,9 +28,9 @@ fn never_index_default(name: []const u8) bool { const HeaderEntry = struct { allocator: *Allocator, - pub name: []const u8, - pub value: []u8, - pub never_index: bool, + name: []const u8, + value: []u8, + never_index: bool, const Self = @This(); diff --git a/lib/std/io.zig b/lib/std/io.zig index 4407e6b2b39a..f9082ee952e4 100644 --- a/lib/std/io.zig +++ b/lib/std/io.zig @@ -161,7 +161,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type) const Self = @This(); const Stream = InStream(Error); - pub stream: Stream, + stream: Stream, unbuffered_in_stream: *Stream, @@ -273,7 +273,7 @@ pub fn PeekStream(comptime buffer_size: usize, comptime InStreamError: type) typ pub const Error = InStreamError; pub const Stream = InStream(Error); - pub stream: Stream, + stream: Stream, base: *Stream, // Right now the look-ahead space is statically allocated, but a version with dynamic allocation @@ -336,7 +336,7 @@ pub const SliceInStream = struct { pub const Error = error{}; pub const Stream = InStream(Error); - pub stream: Stream, + stream: Stream, pos: usize, slice: []const u8, @@ -514,9 +514,9 @@ pub const SliceOutStream = struct { pub const Error = error{OutOfSpace}; pub const Stream = OutStream(Error); - pub stream: Stream, + stream: Stream, - pub pos: usize, + pos: usize, slice: []u8, pub fn init(slice: []u8) SliceOutStream { @@ -571,7 +571,7 @@ pub const NullOutStream = struct { pub const Error = error{}; pub const Stream = OutStream(Error); - pub stream: Stream, + stream: Stream, pub fn init() NullOutStream { return NullOutStream{ @@ -595,8 +595,8 @@ pub fn CountingOutStream(comptime OutStreamError: type) type { pub const Stream = OutStream(Error); pub const Error = OutStreamError; - pub stream: Stream, - pub bytes_written: u64, + stream: Stream, + bytes_written: u64, child_stream: *Stream, pub fn init(child_stream: *Stream) Self { @@ -635,7 +635,7 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr pub const Stream = OutStream(Error); pub const Error = OutStreamError; - pub stream: Stream, + stream: Stream, unbuffered_out_stream: *Stream, @@ -1084,7 +1084,7 @@ pub fn Deserializer(comptime endian: builtin.Endian, comptime packing: Packing, // safety. If it is bad, it will be caught anyway. const TagInt = @TagType(TagType); const tag = try self.deserializeInt(TagInt); - + inline for (info.fields) |field_info| { if (field_info.enum_field.?.value == tag) { const name = field_info.name; diff --git a/lib/std/io/seekable_stream.zig b/lib/std/io/seekable_stream.zig index 86f76d8c1431..48dc31b785cc 100644 --- a/lib/std/io/seekable_stream.zig +++ b/lib/std/io/seekable_stream.zig @@ -39,8 +39,8 @@ pub const SliceSeekableInStream = struct { pub const Stream = InStream(Error); pub const SeekableInStream = SeekableStream(SeekError, GetSeekPosError); - pub stream: Stream, - pub seekable_stream: SeekableInStream, + stream: Stream, + seekable_stream: SeekableInStream, pos: usize, slice: []const u8, diff --git a/lib/std/zig/ast.zig b/lib/std/zig/ast.zig index 79e664714492..9f32c6e54b55 100644 --- a/lib/std/zig/ast.zig +++ b/lib/std/zig/ast.zig @@ -290,7 +290,7 @@ pub const Error = union(enum) { pub const ExpectedSuffixOp = SingleTokenError("Expected pointer dereference, optional unwrap, or field access, found '{}'"); pub const ExpectedParamType = SimpleError("Expected parameter type"); - pub const ExpectedPubItem = SimpleError("Pub must be followed by fn decl, var decl, or container member"); + pub const ExpectedPubItem = SimpleError("Expected function or variable declaration after pub"); pub const UnattachedDocComment = SimpleError("Unattached documentation comment"); pub const ExtraAlignQualifier = SimpleError("Extra align qualifier"); pub const ExtraConstQualifier = SimpleError("Extra const qualifier"); @@ -757,7 +757,6 @@ pub const Node = struct { pub const ContainerField = struct { base: Node, doc_comments: ?*DocComment, - visib_token: ?TokenIndex, name_token: TokenIndex, type_expr: ?*Node, value_expr: ?*Node, @@ -780,7 +779,6 @@ pub const Node = struct { } pub fn firstToken(self: *const ContainerField) TokenIndex { - if (self.visib_token) |visib_token| return visib_token; return self.name_token; } diff --git a/lib/std/zig/parse.zig b/lib/std/zig/parse.zig index 151784284d25..71fa37636170 100644 --- a/lib/std/zig/parse.zig +++ b/lib/std/zig/parse.zig @@ -138,9 +138,15 @@ fn parseContainerMembers(arena: *Allocator, it: *TokenIterator, tree: *Tree) !No continue; } + if (visib_token != null) { + try tree.errors.push(AstError{ + .ExpectedPubItem = AstError.ExpectedPubItem{ .token = it.index }, + }); + return error.ParseError; + } + if (try parseContainerField(arena, it, tree)) |node| { const field = node.cast(Node.ContainerField).?; - field.visib_token = visib_token; field.doc_comments = doc_comments; try list.push(node); const comma = eatToken(it, .Comma) orelse break; @@ -149,13 +155,6 @@ fn parseContainerMembers(arena: *Allocator, it: *TokenIterator, tree: *Tree) !No continue; } - // Dangling pub - if (visib_token != null) { - try tree.errors.push(AstError{ - .ExpectedPubItem = AstError.ExpectedPubItem{ .token = it.index }, - }); - } - break; } @@ -407,7 +406,6 @@ fn parseContainerField(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No node.* = Node.ContainerField{ .base = Node{ .id = .ContainerField }, .doc_comments = null, - .visib_token = null, .name_token = name_token, .type_expr = type_expr, .value_expr = value_expr, diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 78f80786c5da..28bd287c8a55 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -1766,7 +1766,7 @@ test "zig fmt: struct declaration" { \\const S = struct { \\ const Self = @This(); \\ f1: u8, - \\ pub f3: u8, + \\ f3: u8, \\ \\ fn method(self: *Self) Self { \\ return self.*; @@ -1777,14 +1777,14 @@ test "zig fmt: struct declaration" { \\ \\const Ps = packed struct { \\ a: u8, - \\ pub b: u8, + \\ b: u8, \\ \\ c: u8, \\}; \\ \\const Es = extern struct { \\ a: u8, - \\ pub b: u8, + \\ b: u8, \\ \\ c: u8, \\}; diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index 1be4410f3823..e5875fd04f05 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -254,10 +254,6 @@ fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, i try renderDocComments(tree, stream, field, indent, start_col); - if (field.visib_token) |visib_token| { - try renderToken(tree, stream, visib_token, indent, start_col, Space.Space); // pub - } - if (field.type_expr == null and field.value_expr == null) { return renderToken(tree, stream, field.name_token, indent, start_col, Space.Comma); // name, } else if (field.type_expr != null and field.value_expr == null) { @@ -2206,8 +2202,8 @@ const FindByteOutStream = struct { pub const Error = error{}; pub const Stream = std.io.OutStream(Error); - pub stream: Stream, - pub byte_found: bool, + stream: Stream, + byte_found: bool, byte: u8, pub fn init(byte: u8) Self { diff --git a/src/all_types.hpp b/src/all_types.hpp index e2e1db48d498..267c5479be32 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -990,8 +990,6 @@ struct AstNodeStructField { // populated if the "align(A)" is present AstNode *align_expr; Buf doc_comments; - - VisibMod visib_mod; }; struct AstNodeStringLiteral { diff --git a/src/parser.cpp b/src/parser.cpp index 9fcf233e2d4c..b6742ef1f17f 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -518,8 +518,8 @@ static Token *ast_parse_doc_comments(ParseContext *pc, Buf *buf) { // <- TestDecl ContainerMembers // / TopLevelComptime ContainerMembers // / KEYWORD_pub? TopLevelDecl ContainerMembers -// / KEYWORD_pub? ContainerField COMMA ContainerMembers -// / KEYWORD_pub? ContainerField +// / ContainerField COMMA ContainerMembers +// / ContainerField // / static AstNodeContainerDecl ast_parse_container_members(ParseContext *pc) { AstNodeContainerDecl res = {}; @@ -548,10 +548,13 @@ static AstNodeContainerDecl ast_parse_container_members(ParseContext *pc) { continue; } + if (visib_token != nullptr) { + ast_error(pc, peek_token(pc), "expected function or variable declaration after pub"); + } + AstNode *container_field = ast_parse_container_field(pc); if (container_field != nullptr) { assert(container_field->type == NodeTypeStructField); - container_field->data.struct_field.visib_mod = visib_mod; container_field->data.struct_field.doc_comments = doc_comment_buf; res.fields.append(container_field); if (eat_token_if(pc, TokenIdComma) != nullptr) { @@ -561,12 +564,7 @@ static AstNodeContainerDecl ast_parse_container_members(ParseContext *pc) { } } - // We visib_token wasn't eaten, then we haven't consumed the first token in this rule yet. - // It is therefore safe to return and let the caller continue parsing. - if (visib_token == nullptr) - break; - - ast_invalid_token_error(pc, peek_token(pc)); + break; } return res;