Skip to content

Commit

Permalink
Auto merge of #34199 - jseyfried:visit_all_attrs, r=nrc
Browse files Browse the repository at this point in the history
Visit statement and expression attributes in the AST visitor

Currently, these attributes are not visited, so they are not gated feature checked in the post expansion visitor. This only affects crates using `#![feature(stmt_expr_attributes)]`.
r? @nrc
  • Loading branch information
bors authored Jun 10, 2016
2 parents a267d6c + 8475a4b commit 8c6bd23
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/libsyntax/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion src/test/compile-fail/custom_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 8c6bd23

Please sign in to comment.