about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-01-27 01:30:28 +0000
committerbors <bors@rust-lang.org>2016-01-27 01:30:28 +0000
commitb694d1b1d11b5fa41f5a019b1251124a133d031d (patch)
treeec86ff617dd15371d0bb75f27be4e36742515ecb
parent4b615854f00ba17ad704155e1d3196c17a6edb62 (diff)
parent5133b2619e07b8d79f8894dbb9c3e47184037ce2 (diff)
downloadrust-b694d1b1d11b5fa41f5a019b1251124a133d031d.tar.gz
rust-b694d1b1d11b5fa41f5a019b1251124a133d031d.zip
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)
-rw-r--r--src/librustc/lint/context.rs14
-rw-r--r--src/test/run-pass/lint-expr-stmt-attrs-for-early-lints.rs22
2 files changed, 31 insertions, 5 deletions
diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs
index c41a361fcc3..55782041be6 100644
--- a/src/librustc/lint/context.rs
+++ b/src/librustc/lint/context.rs
@@ -735,7 +735,7 @@ impl<'a> LintContext for EarlyContext<'a> {
     }
 
     fn enter_attrs(&mut self, attrs: &[ast::Attribute]) {
-        debug!("early context: exit_attrs({:?})", attrs);
+        debug!("early context: enter_attrs({:?})", attrs);
         run_lints!(self, enter_lint_attrs, early_passes, attrs);
     }
 
@@ -934,8 +934,10 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> {
     }
 
     fn visit_expr(&mut self, e: &ast::Expr) {
-        run_lints!(self, check_expr, early_passes, e);
-        ast_visit::walk_expr(self, e);
+        self.with_lint_attrs(e.attrs.as_attr_slice(), |cx| {
+            run_lints!(cx, check_expr, early_passes, e);
+            ast_visit::walk_expr(cx, e);
+        })
     }
 
     fn visit_stmt(&mut self, s: &ast::Stmt) {
@@ -990,8 +992,10 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> {
     }
 
     fn visit_local(&mut self, l: &ast::Local) {
-        run_lints!(self, check_local, early_passes, l);
-        ast_visit::walk_local(self, l);
+        self.with_lint_attrs(l.attrs.as_attr_slice(), |cx| {
+            run_lints!(cx, check_local, early_passes, l);
+            ast_visit::walk_local(cx, l);
+        })
     }
 
     fn visit_block(&mut self, b: &ast::Block) {
diff --git a/src/test/run-pass/lint-expr-stmt-attrs-for-early-lints.rs b/src/test/run-pass/lint-expr-stmt-attrs-for-early-lints.rs
new file mode 100644
index 00000000000..16c7176a68d
--- /dev/null
+++ b/src/test/run-pass/lint-expr-stmt-attrs-for-early-lints.rs
@@ -0,0 +1,22 @@
+// Copyright 2015 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(stmt_expr_attributes)]
+#![deny(unused_parens)]
+
+// Tests that lint attributes on statements/expressions are
+// correctly applied to non-builtin early (AST) lints
+
+fn main() {
+    #[allow(unused_parens)]
+    {
+        let _ = (9);
+    }
+}