stop accepting deprecated `use` keyword

closes #2591
master
Andrew Kelley 2019-11-11 11:52:50 -05:00
parent cd5c9c8998
commit ae0a219d1f
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
5 changed files with 13 additions and 27 deletions

View File

@ -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 {

View File

@ -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); // ;
},

View File

@ -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 },

View File

@ -153,7 +153,6 @@ static const struct ZigKeyword zig_keywords[] = {
{"undefined", TokenIdKeywordUndefined},
{"union", TokenIdKeywordUnion},
{"unreachable", TokenIdKeywordUnreachable},
{"use", TokenIdKeywordUsingNamespace},
{"usingnamespace", TokenIdKeywordUsingNamespace},
{"var", TokenIdKeywordVar},
{"volatile", TokenIdKeywordVolatile},

View File

@ -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();
@ -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
@ -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();
@ -58,7 +58,7 @@ 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;
@ -66,8 +66,8 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
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()) {
@ -88,8 +88,8 @@ 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();
@ -97,7 +97,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
, "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";
@ -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;
);