Skip to content

Commit

Permalink
stop accepting deprecated use keyword
Browse files Browse the repository at this point in the history
closes #2591
  • Loading branch information
andrewrk committed Nov 11, 2019
1 parent cd5c9c8 commit ae0a219
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 27 deletions.
10 changes: 0 additions & 10 deletions lib/std/zig/parser_test.zig
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
// TODO remove `use` keyword eventually: https://github.com/ziglang/zig/issues/2591
test "zig fmt: change use to usingnamespace" {
try testTransform(
\\use @import("std");
,
\\usingnamespace @import("std");
\\
);
}

test "zig fmt: async function" {
try testCanonical(
\\pub const Server = struct {
Expand Down
4 changes: 1 addition & 3 deletions lib/std/zig/render.zig
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ fn renderTopLevelDecl(allocator: *mem.Allocator, stream: var, tree: *ast.Tree, i
if (use_decl.visib_token) |visib_token| {
try renderToken(tree, stream, visib_token, indent, start_col, Space.Space); // pub
}
// TODO after depracating use, go back to this:
//try renderToken(tree, stream, use_decl.use_token, indent, start_col, Space.Space); // usingnamespace
try stream.write("usingnamespace ");
try renderToken(tree, stream, use_decl.use_token, indent, start_col, Space.Space); // usingnamespace
try renderExpression(allocator, stream, tree, indent, start_col, use_decl.expr, Space.None);
try renderToken(tree, stream, use_decl.semicolon_token, indent, start_col, Space.Newline); // ;
},
Expand Down
1 change: 0 additions & 1 deletion lib/std/zig/tokenizer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub const Token = struct {
Keyword{ .bytes = "undefined", .id = Id.Keyword_undefined },
Keyword{ .bytes = "union", .id = Id.Keyword_union },
Keyword{ .bytes = "unreachable", .id = Id.Keyword_unreachable },
Keyword{ .bytes = "use", .id = Id.Keyword_usingnamespace },
Keyword{ .bytes = "usingnamespace", .id = Id.Keyword_usingnamespace },
Keyword{ .bytes = "var", .id = Id.Keyword_var },
Keyword{ .bytes = "volatile", .id = Id.Keyword_volatile },
Expand Down
1 change: 0 additions & 1 deletion src/tokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ static const struct ZigKeyword zig_keywords[] = {
{"undefined", TokenIdKeywordUndefined},
{"union", TokenIdKeywordUnion},
{"unreachable", TokenIdKeywordUnreachable},
{"use", TokenIdKeywordUsingNamespace},
{"usingnamespace", TokenIdKeywordUsingNamespace},
{"var", TokenIdKeywordVar},
{"volatile", TokenIdKeywordVolatile},
Expand Down
24 changes: 12 additions & 12 deletions test/compare_output.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {

cases.addCase(x: {
var tc = cases.create("multiple files with private function",
\\use @import("std").io;
\\use @import("foo.zig");
\\usingnamespace @import("std").io;
\\usingnamespace @import("foo.zig");
\\
\\pub fn main() void {
\\ privateFunction();
Expand All @@ -29,7 +29,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
, "OK 1\nOK 2\n");

tc.addSourceFile("foo.zig",
\\use @import("std").io;
\\usingnamespace @import("std").io;
\\
\\// purposefully conflicting function with main.zig
\\// but it's private so it should be OK
Expand All @@ -48,8 +48,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {

cases.addCase(x: {
var tc = cases.create("import segregation",
\\use @import("foo.zig");
\\use @import("bar.zig");
\\usingnamespace @import("foo.zig");
\\usingnamespace @import("bar.zig");
\\
\\pub fn main() void {
\\ foo_function();
Expand All @@ -58,16 +58,16 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
, "OK\nOK\n");

tc.addSourceFile("foo.zig",
\\use @import("std").io;
\\usingnamespace @import("std").io;
\\pub fn foo_function() void {
\\ const stdout = &(getStdOut() catch unreachable).outStream().stream;
\\ stdout.print("OK\n") catch unreachable;
\\}
);

tc.addSourceFile("bar.zig",
\\use @import("other.zig");
\\use @import("std").io;
\\usingnamespace @import("other.zig");
\\usingnamespace @import("std").io;
\\
\\pub fn bar_function() void {
\\ if (foo_function()) {
Expand All @@ -88,16 +88,16 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
});

cases.addCase(x: {
var tc = cases.create("two files use import each other",
\\use @import("a.zig");
var tc = cases.create("two files usingnamespace import each other",
\\usingnamespace @import("a.zig");
\\
\\pub fn main() void {
\\ ok();
\\}
, "OK\n");

tc.addSourceFile("a.zig",
\\use @import("b.zig");
\\usingnamespace @import("b.zig");
\\const io = @import("std").io;
\\
\\pub const a_text = "OK\n";
Expand All @@ -109,7 +109,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);

tc.addSourceFile("b.zig",
\\use @import("a.zig");
\\usingnamespace @import("a.zig");
\\
\\pub const b_text = a_text;
);
Expand Down

0 comments on commit ae0a219

Please sign in to comment.