From 38774aaf7ff14755e9606ed699ade2bbcbc74757 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 10 Sep 2018 17:10:11 -0400 Subject: [PATCH 1/4] make `add_pre_expansion_builtin` add a pre-expansion lint Copy-and-paste error. --- src/librustc_lint/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 2c32cbdd00f36..681cf0d5fc9de 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -90,7 +90,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { macro_rules! add_pre_expansion_builtin { ($sess:ident, $($name:ident),*,) => ( {$( - store.register_early_pass($sess, false, box $name); + store.register_pre_expansion_pass($sess, box $name); )*} ) } From b1a9f9eae8477042baffe24f560c0ce8fe08e70d Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 10 Sep 2018 17:12:55 -0400 Subject: [PATCH 2/4] visit the paths in pre-expansion macros --- src/librustc/lint/context.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index b823545aa9114..e22792305a053 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -1117,6 +1117,13 @@ impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> { } fn visit_mac(&mut self, mac: &'a ast::Mac) { + // FIXME(#54110): So, this setup isn't really right. I think + // that (a) the libsyntax visitor ought to be doing this as + // part of `walk_mac`, and (b) we should be calling + // `visit_path`, *but* that would require a `NodeId`, and I + // want to get #53686 fixed quickly. -nmatsakis + ast_visit::walk_path(self, &mac.node.path); + run_lints!(self, check_mac, mac); } } From 5adbdf82f3dd345b31d097c42639b88e96f84ed8 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 10 Sep 2018 17:14:30 -0400 Subject: [PATCH 3/4] add test case --- src/test/ui/rust-2018/try-macro.fixed | 16 ++++++++++++++++ src/test/ui/rust-2018/try-macro.rs | 16 ++++++++++++++++ src/test/ui/rust-2018/try-macro.stderr | 15 +++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 src/test/ui/rust-2018/try-macro.fixed create mode 100644 src/test/ui/rust-2018/try-macro.rs create mode 100644 src/test/ui/rust-2018/try-macro.stderr diff --git a/src/test/ui/rust-2018/try-macro.fixed b/src/test/ui/rust-2018/try-macro.fixed new file mode 100644 index 0000000000000..c65f0fc30ef0a --- /dev/null +++ b/src/test/ui/rust-2018/try-macro.fixed @@ -0,0 +1,16 @@ +// Test that `try!` macros are rewritten. + +// run-rustfix +// compile-pass + +#![warn(rust_2018_compatibility)] +#![allow(unused_variables)] +#![allow(dead_code)] + +fn foo() -> Result { + let x: Result = Ok(22); + r#try!(x); + Ok(44) +} + +fn main() { } diff --git a/src/test/ui/rust-2018/try-macro.rs b/src/test/ui/rust-2018/try-macro.rs new file mode 100644 index 0000000000000..f435890a61dcb --- /dev/null +++ b/src/test/ui/rust-2018/try-macro.rs @@ -0,0 +1,16 @@ +// Test that `try!` macros are rewritten. + +// run-rustfix +// compile-pass + +#![warn(rust_2018_compatibility)] +#![allow(unused_variables)] +#![allow(dead_code)] + +fn foo() -> Result { + let x: Result = Ok(22); + try!(x); + Ok(44) +} + +fn main() { } diff --git a/src/test/ui/rust-2018/try-macro.stderr b/src/test/ui/rust-2018/try-macro.stderr new file mode 100644 index 0000000000000..40a4564cc3d6d --- /dev/null +++ b/src/test/ui/rust-2018/try-macro.stderr @@ -0,0 +1,15 @@ +warning: `try` is a keyword in the 2018 edition + --> $DIR/try-macro.rs:12:5 + | +LL | try!(x); + | ^^^ help: you can use a raw identifier to stay compatible: `r#try` + | +note: lint level defined here + --> $DIR/try-macro.rs:6:9 + | +LL | #![warn(rust_2018_compatibility)] + | ^^^^^^^^^^^^^^^^^^^^^^^ + = note: #[warn(keyword_idents)] implied by #[warn(rust_2018_compatibility)] + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition! + = note: for more information, see issue #49716 + From 0cd8e0d03edcdc3fc7d74bdb149e91a4d0b0cbd1 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 11 Sep 2018 08:56:59 -0400 Subject: [PATCH 4/4] we now successfully warn about `async` in macro invocations --- src/test/ui/rust-2018/async-ident.fixed | 4 ++- src/test/ui/rust-2018/async-ident.rs | 2 ++ src/test/ui/rust-2018/async-ident.stderr | 33 +++++++++++++++--------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/test/ui/rust-2018/async-ident.fixed b/src/test/ui/rust-2018/async-ident.fixed index ef88f835fc83d..125e7c3773ae5 100644 --- a/src/test/ui/rust-2018/async-ident.fixed +++ b/src/test/ui/rust-2018/async-ident.fixed @@ -26,7 +26,9 @@ macro_rules! foo { //~| WARN hard error in the 2018 edition } -foo!(async); +foo!(r#async); + //~^ ERROR async + //~| WARN hard error in the 2018 edition mod dont_lint_raw { fn r#async() {} diff --git a/src/test/ui/rust-2018/async-ident.rs b/src/test/ui/rust-2018/async-ident.rs index 069da7ffcdd4d..01b974bcbfb0b 100644 --- a/src/test/ui/rust-2018/async-ident.rs +++ b/src/test/ui/rust-2018/async-ident.rs @@ -27,6 +27,8 @@ macro_rules! foo { } foo!(async); + //~^ ERROR async + //~| WARN hard error in the 2018 edition mod dont_lint_raw { fn r#async() {} diff --git a/src/test/ui/rust-2018/async-ident.stderr b/src/test/ui/rust-2018/async-ident.stderr index b9bb2e254b44e..46e6af84ab814 100644 --- a/src/test/ui/rust-2018/async-ident.stderr +++ b/src/test/ui/rust-2018/async-ident.stderr @@ -31,7 +31,16 @@ LL | ($async:expr, async) => {}; = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:36:11 + --> $DIR/async-ident.rs:29:6 + | +LL | foo!(async); + | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition! + = note: for more information, see issue #49716 + +error: `async` is a keyword in the 2018 edition + --> $DIR/async-ident.rs:38:11 | LL | trait async {} | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -40,7 +49,7 @@ LL | trait async {} = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:40:10 + --> $DIR/async-ident.rs:42:10 | LL | impl async for MyStruct {} | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -49,7 +58,7 @@ LL | impl async for MyStruct {} = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:46:12 + --> $DIR/async-ident.rs:48:12 | LL | static async: u32 = 0; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -58,7 +67,7 @@ LL | static async: u32 = 0; = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:52:11 + --> $DIR/async-ident.rs:54:11 | LL | const async: u32 = 0; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -67,7 +76,7 @@ LL | const async: u32 = 0; = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:58:15 + --> $DIR/async-ident.rs:60:15 | LL | impl Foo { fn async() {} } | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -76,7 +85,7 @@ LL | impl Foo { fn async() {} } = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:63:12 + --> $DIR/async-ident.rs:65:12 | LL | struct async {} | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -85,7 +94,7 @@ LL | struct async {} = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:66:9 + --> $DIR/async-ident.rs:68:9 | LL | let async: async = async {}; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -94,7 +103,7 @@ LL | let async: async = async {}; = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:66:16 + --> $DIR/async-ident.rs:68:16 | LL | let async: async = async {}; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -103,7 +112,7 @@ LL | let async: async = async {}; = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:66:24 + --> $DIR/async-ident.rs:68:24 | LL | let async: async = async {}; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -112,7 +121,7 @@ LL | let async: async = async {}; = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:77:19 + --> $DIR/async-ident.rs:79:19 | LL | () => (pub fn async() {}) | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -121,7 +130,7 @@ LL | () => (pub fn async() {}) = note: for more information, see issue #49716 error: `async` is a keyword in the 2018 edition - --> $DIR/async-ident.rs:84:6 + --> $DIR/async-ident.rs:86:6 | LL | (async) => (1) | ^^^^^ help: you can use a raw identifier to stay compatible: `r#async` @@ -129,5 +138,5 @@ LL | (async) => (1) = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition! = note: for more information, see issue #49716 -error: aborting due to 14 previous errors +error: aborting due to 15 previous errors