Skip to content

Commit 8c6bd23

Browse files
authored
Auto merge of #34199 - jseyfried:visit_all_attrs, r=nrc
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
2 parents a267d6c + 8475a4b commit 8c6bd23

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/libsyntax/visit.rs

+6
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod) {
185185
}
186186

187187
pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local) {
188+
for attr in local.attrs.as_attr_slice() {
189+
visitor.visit_attribute(attr);
190+
}
188191
visitor.visit_pat(&local.pat);
189192
walk_list!(visitor, visit_ty, &local.ty);
190193
walk_list!(visitor, visit_expr, &local.init);
@@ -635,6 +638,9 @@ pub fn walk_mac<'v, V: Visitor<'v>>(_: &mut V, _: &'v Mac) {
635638
}
636639

637640
pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) {
641+
for attr in expression.attrs.as_attr_slice() {
642+
visitor.visit_attribute(attr);
643+
}
638644
match expression.node {
639645
ExprKind::Box(ref subexpression) => {
640646
visitor.visit_expr(subexpression)

src/test/compile-fail/custom_attribute.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(stmt_expr_attributes)]
12+
1113
#[foo] //~ ERROR The attribute `foo`
1214
fn main() {
13-
15+
#[foo] //~ ERROR The attribute `foo`
16+
let x = ();
17+
#[foo] //~ ERROR The attribute `foo`
18+
x
1419
}

0 commit comments

Comments
 (0)