diff --git a/lib/std/zig/Ast.zig b/lib/std/zig/Ast.zig index 0573622d6f..f312093aa3 100644 --- a/lib/std/zig/Ast.zig +++ b/lib/std/zig/Ast.zig @@ -362,6 +362,9 @@ pub fn renderError(tree: Ast, parse_error: Error, stream: anytype) !void { .wrong_equal_var_decl => { return stream.writeAll("variable initialized with '==' instead of '='"); }, + .var_const_decl => { + return stream.writeAll("use 'var' or 'const' to declare variable"); + }, .expected_token => { const found_tag = token_tags[parse_error.token + @boolToInt(parse_error.token_is_prev)]; @@ -2743,6 +2746,7 @@ pub const Error = struct { c_style_container, expected_var_const, wrong_equal_var_decl, + var_const_decl, zig_style_container, previous_field, diff --git a/lib/std/zig/parse.zig b/lib/std/zig/parse.zig index 3bb27975db..fdb122b19d 100644 --- a/lib/std/zig/parse.zig +++ b/lib/std/zig/parse.zig @@ -471,6 +471,13 @@ const Parser = struct { // There is not allowed to be a decl after a field with no comma. // Report error but recover parser. try p.warn(.expected_comma_after_field); + if (p.token_tags[p.tok_i] == .semicolon and p.token_tags[identifier] == .identifier) { + try p.warnMsg(.{ + .tag = .var_const_decl, + .is_note = true, + .token = identifier, + }); + } p.findNextContainerMember(); continue; }, diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 1b8a240642..42eb1abdde 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -5238,6 +5238,18 @@ test "zig fmt: missing const/var before local variable" { }); } +test "zig fmt: missing const/var before local variable" { + try testError( + \\std = foo, + \\std = foo; + \\*u32 = foo; + , &.{ + .expected_comma_after_field, + .var_const_decl, + .expected_comma_after_field, + }); +} + test "zig fmt: while continue expr" { try testCanonical( \\test {