Skip to content

Commit b694d1b

Browse files
committed
Auto merge of #30487 - jonas-schievink:more-attrs-lint-fixes, r=alexcrichton
`LateContext` already does this, looks like this was just forgotten in #29850. Found while investigating #30326 (but doesn't fix it)
2 parents 4b61585 + 5133b26 commit b694d1b

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/librustc/lint/context.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ impl<'a> LintContext for EarlyContext<'a> {
735735
}
736736

737737
fn enter_attrs(&mut self, attrs: &[ast::Attribute]) {
738-
debug!("early context: exit_attrs({:?})", attrs);
738+
debug!("early context: enter_attrs({:?})", attrs);
739739
run_lints!(self, enter_lint_attrs, early_passes, attrs);
740740
}
741741

@@ -934,8 +934,10 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> {
934934
}
935935

936936
fn visit_expr(&mut self, e: &ast::Expr) {
937-
run_lints!(self, check_expr, early_passes, e);
938-
ast_visit::walk_expr(self, e);
937+
self.with_lint_attrs(e.attrs.as_attr_slice(), |cx| {
938+
run_lints!(cx, check_expr, early_passes, e);
939+
ast_visit::walk_expr(cx, e);
940+
})
939941
}
940942

941943
fn visit_stmt(&mut self, s: &ast::Stmt) {
@@ -990,8 +992,10 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> {
990992
}
991993

992994
fn visit_local(&mut self, l: &ast::Local) {
993-
run_lints!(self, check_local, early_passes, l);
994-
ast_visit::walk_local(self, l);
995+
self.with_lint_attrs(l.attrs.as_attr_slice(), |cx| {
996+
run_lints!(cx, check_local, early_passes, l);
997+
ast_visit::walk_local(cx, l);
998+
})
995999
}
9961000

9971001
fn visit_block(&mut self, b: &ast::Block) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(stmt_expr_attributes)]
12+
#![deny(unused_parens)]
13+
14+
// Tests that lint attributes on statements/expressions are
15+
// correctly applied to non-builtin early (AST) lints
16+
17+
fn main() {
18+
#[allow(unused_parens)]
19+
{
20+
let _ = (9);
21+
}
22+
}

0 commit comments

Comments
 (0)