From 11b538840f62434e5d04aef3b4966a5caccbfc55 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Fri, 10 Jun 2016 10:31:45 +0000 Subject: [PATCH 1/2] Visit statement and expression attributes --- src/libsyntax/visit.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index a1d8e056b0257..07a6317706b84 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -185,6 +185,9 @@ pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod) { } pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local) { + for attr in local.attrs.as_attr_slice() { + visitor.visit_attribute(attr); + } visitor.visit_pat(&local.pat); walk_list!(visitor, visit_ty, &local.ty); walk_list!(visitor, visit_expr, &local.init); @@ -635,6 +638,9 @@ pub fn walk_mac<'v, V: Visitor<'v>>(_: &mut V, _: &'v Mac) { } pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { + for attr in expression.attrs.as_attr_slice() { + visitor.visit_attribute(attr); + } match expression.node { ExprKind::Box(ref subexpression) => { visitor.visit_expr(subexpression) From 8475a4b0c6adce70940617ea5bbb5b691d50d975 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Fri, 10 Jun 2016 10:36:21 +0000 Subject: [PATCH 2/2] Check that custom attributes are disallowed on statements and expressions --- src/test/compile-fail/custom_attribute.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/compile-fail/custom_attribute.rs b/src/test/compile-fail/custom_attribute.rs index 4e089a4e59c42..eff734230ee23 100644 --- a/src/test/compile-fail/custom_attribute.rs +++ b/src/test/compile-fail/custom_attribute.rs @@ -8,7 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(stmt_expr_attributes)] + #[foo] //~ ERROR The attribute `foo` fn main() { - + #[foo] //~ ERROR The attribute `foo` + let x = (); + #[foo] //~ ERROR The attribute `foo` + x }