From c2d6f8cf7b91a45d6004e751797ecb5ee09776a3 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Sat, 14 Jul 2018 16:31:23 +0800 Subject: [PATCH 1/2] Check proc_macro on stmt --- src/librustc/hir/check_attr.rs | 6 +++++- .../proc-macro/issue-52329.rs | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail-fulldeps/proc-macro/issue-52329.rs diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index 2d83c158fe08f..4cd06f258909b 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -269,7 +269,11 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> { if attr.check_name("inline") { self.check_inline(attr, &stmt.span, Target::Statement); } - if attr.check_name("repr") { + if attr.check_name("repr") + || attr.check_name("proc_macro") + || attr.check_name("proc_macro_attribute") + || attr.check_name("proc_macro_derive") + { self.emit_repr_error( attr.span, stmt.span, diff --git a/src/test/compile-fail-fulldeps/proc-macro/issue-52329.rs b/src/test/compile-fail-fulldeps/proc-macro/issue-52329.rs new file mode 100644 index 0000000000000..ca2e171eab728 --- /dev/null +++ b/src/test/compile-fail-fulldeps/proc-macro/issue-52329.rs @@ -0,0 +1,20 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(proc_macro)] + +fn main() { + #[proc_macro] //~ ERROR: attribute should not be applied to a statement + let x = 10; + #[proc_macro_attribute] //~ ERROR: attribute should not be applied to a statement + let x = 11; + #[proc_macro_derive] //~ ERROR: attribute should not be applied to a statement + let x = 12; +} \ No newline at end of file From bfa33a90af61e1679b81c486797ed83d0ee53d19 Mon Sep 17 00:00:00 2001 From: csmoe <35686186+csmoe@users.noreply.github.com> Date: Sat, 14 Jul 2018 16:49:52 +0800 Subject: [PATCH 2/2] Fix tidy --- src/test/compile-fail-fulldeps/proc-macro/issue-52329.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/compile-fail-fulldeps/proc-macro/issue-52329.rs b/src/test/compile-fail-fulldeps/proc-macro/issue-52329.rs index ca2e171eab728..22cbe28061860 100644 --- a/src/test/compile-fail-fulldeps/proc-macro/issue-52329.rs +++ b/src/test/compile-fail-fulldeps/proc-macro/issue-52329.rs @@ -17,4 +17,5 @@ fn main() { let x = 11; #[proc_macro_derive] //~ ERROR: attribute should not be applied to a statement let x = 12; -} \ No newline at end of file +} +