Skip to content

Commit f17c230

Browse files
committed
Auto merge of #54111 - nikomatsakis:issue-53686-keywords-and-macros, r=alexcrichton
warn about keywords in macro invocations Fixes #53686 r? @alexcrichton
2 parents 7ee7207 + 0cd8e0d commit f17c230

File tree

8 files changed

+81
-14
lines changed

8 files changed

+81
-14
lines changed

src/librustc/lint/context.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,13 @@ impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> {
11171117
}
11181118

11191119
fn visit_mac(&mut self, mac: &'a ast::Mac) {
1120+
// FIXME(#54110): So, this setup isn't really right. I think
1121+
// that (a) the libsyntax visitor ought to be doing this as
1122+
// part of `walk_mac`, and (b) we should be calling
1123+
// `visit_path`, *but* that would require a `NodeId`, and I
1124+
// want to get #53686 fixed quickly. -nmatsakis
1125+
ast_visit::walk_path(self, &mac.node.path);
1126+
11201127
run_lints!(self, check_mac, mac);
11211128
}
11221129
}

src/librustc_lint/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
9090
macro_rules! add_pre_expansion_builtin {
9191
($sess:ident, $($name:ident),*,) => (
9292
{$(
93-
store.register_early_pass($sess, false, box $name);
93+
store.register_pre_expansion_pass($sess, box $name);
9494
)*}
9595
)
9696
}

src/test/ui/rust-2018/async-ident.fixed

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ macro_rules! foo {
2626
//~| WARN hard error in the 2018 edition
2727
}
2828

29-
foo!(async);
29+
foo!(r#async);
30+
//~^ ERROR async
31+
//~| WARN hard error in the 2018 edition
3032

3133
mod dont_lint_raw {
3234
fn r#async() {}

src/test/ui/rust-2018/async-ident.rs

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ macro_rules! foo {
2727
}
2828

2929
foo!(async);
30+
//~^ ERROR async
31+
//~| WARN hard error in the 2018 edition
3032

3133
mod dont_lint_raw {
3234
fn r#async() {}

src/test/ui/rust-2018/async-ident.stderr

+21-12
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ LL | ($async:expr, async) => {};
3131
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
3232

3333
error: `async` is a keyword in the 2018 edition
34-
--> $DIR/async-ident.rs:36:11
34+
--> $DIR/async-ident.rs:29:6
35+
|
36+
LL | foo!(async);
37+
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
38+
|
39+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
40+
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
41+
42+
error: `async` is a keyword in the 2018 edition
43+
--> $DIR/async-ident.rs:38:11
3544
|
3645
LL | trait async {}
3746
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
@@ -40,7 +49,7 @@ LL | trait async {}
4049
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
4150

4251
error: `async` is a keyword in the 2018 edition
43-
--> $DIR/async-ident.rs:40:10
52+
--> $DIR/async-ident.rs:42:10
4453
|
4554
LL | impl async for MyStruct {}
4655
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
@@ -49,7 +58,7 @@ LL | impl async for MyStruct {}
4958
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
5059

5160
error: `async` is a keyword in the 2018 edition
52-
--> $DIR/async-ident.rs:46:12
61+
--> $DIR/async-ident.rs:48:12
5362
|
5463
LL | static async: u32 = 0;
5564
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
@@ -58,7 +67,7 @@ LL | static async: u32 = 0;
5867
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
5968

6069
error: `async` is a keyword in the 2018 edition
61-
--> $DIR/async-ident.rs:52:11
70+
--> $DIR/async-ident.rs:54:11
6271
|
6372
LL | const async: u32 = 0;
6473
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
@@ -67,7 +76,7 @@ LL | const async: u32 = 0;
6776
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
6877

6978
error: `async` is a keyword in the 2018 edition
70-
--> $DIR/async-ident.rs:58:15
79+
--> $DIR/async-ident.rs:60:15
7180
|
7281
LL | impl Foo { fn async() {} }
7382
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
@@ -76,7 +85,7 @@ LL | impl Foo { fn async() {} }
7685
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
7786

7887
error: `async` is a keyword in the 2018 edition
79-
--> $DIR/async-ident.rs:63:12
88+
--> $DIR/async-ident.rs:65:12
8089
|
8190
LL | struct async {}
8291
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
@@ -85,7 +94,7 @@ LL | struct async {}
8594
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
8695

8796
error: `async` is a keyword in the 2018 edition
88-
--> $DIR/async-ident.rs:66:9
97+
--> $DIR/async-ident.rs:68:9
8998
|
9099
LL | let async: async = async {};
91100
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
@@ -94,7 +103,7 @@ LL | let async: async = async {};
94103
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
95104

96105
error: `async` is a keyword in the 2018 edition
97-
--> $DIR/async-ident.rs:66:16
106+
--> $DIR/async-ident.rs:68:16
98107
|
99108
LL | let async: async = async {};
100109
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
@@ -103,7 +112,7 @@ LL | let async: async = async {};
103112
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
104113

105114
error: `async` is a keyword in the 2018 edition
106-
--> $DIR/async-ident.rs:66:24
115+
--> $DIR/async-ident.rs:68:24
107116
|
108117
LL | let async: async = async {};
109118
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
@@ -112,7 +121,7 @@ LL | let async: async = async {};
112121
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
113122

114123
error: `async` is a keyword in the 2018 edition
115-
--> $DIR/async-ident.rs:77:19
124+
--> $DIR/async-ident.rs:79:19
116125
|
117126
LL | () => (pub fn async() {})
118127
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
@@ -121,13 +130,13 @@ LL | () => (pub fn async() {})
121130
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
122131

123132
error: `async` is a keyword in the 2018 edition
124-
--> $DIR/async-ident.rs:84:6
133+
--> $DIR/async-ident.rs:86:6
125134
|
126135
LL | (async) => (1)
127136
| ^^^^^ help: you can use a raw identifier to stay compatible: `r#async`
128137
|
129138
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
130139
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
131140

132-
error: aborting due to 14 previous errors
141+
error: aborting due to 15 previous errors
133142

src/test/ui/rust-2018/try-macro.fixed

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Test that `try!` macros are rewritten.
2+
3+
// run-rustfix
4+
// compile-pass
5+
6+
#![warn(rust_2018_compatibility)]
7+
#![allow(unused_variables)]
8+
#![allow(dead_code)]
9+
10+
fn foo() -> Result<usize, ()> {
11+
let x: Result<usize, ()> = Ok(22);
12+
r#try!(x);
13+
Ok(44)
14+
}
15+
16+
fn main() { }

src/test/ui/rust-2018/try-macro.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Test that `try!` macros are rewritten.
2+
3+
// run-rustfix
4+
// compile-pass
5+
6+
#![warn(rust_2018_compatibility)]
7+
#![allow(unused_variables)]
8+
#![allow(dead_code)]
9+
10+
fn foo() -> Result<usize, ()> {
11+
let x: Result<usize, ()> = Ok(22);
12+
try!(x);
13+
Ok(44)
14+
}
15+
16+
fn main() { }
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
warning: `try` is a keyword in the 2018 edition
2+
--> $DIR/try-macro.rs:12:5
3+
|
4+
LL | try!(x);
5+
| ^^^ help: you can use a raw identifier to stay compatible: `r#try`
6+
|
7+
note: lint level defined here
8+
--> $DIR/try-macro.rs:6:9
9+
|
10+
LL | #![warn(rust_2018_compatibility)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^
12+
= note: #[warn(keyword_idents)] implied by #[warn(rust_2018_compatibility)]
13+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
14+
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
15+

0 commit comments

Comments
 (0)