From 1fcc124de9e640d8c7e5a281cb521f6899c192ec Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sat, 19 Dec 2015 23:33:45 +0100 Subject: [PATCH 1/2] Wrap EarlyContext::visit_local/visit_expr in with_lint_attrs calls LateContext already does this, looks like this was just forgotten in #29850 --- src/librustc/lint/context.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index db22000fd9f..0d50abfe361 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -636,7 +636,7 @@ fn level_stack(&mut self) -> &mut Vec<(LintId, LevelSource)> { } 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); } @@ -834,8 +834,10 @@ fn visit_pat(&mut self, p: &ast::Pat) { } 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) { @@ -890,8 +892,10 @@ fn visit_mod(&mut self, m: &ast::Mod, s: Span, n: ast::NodeId) { } 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) { From 5133b2619e07b8d79f8894dbb9c3e47184037ce2 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 22 Dec 2015 00:56:48 +0100 Subject: [PATCH 2/2] Add a test --- .../lint-expr-stmt-attrs-for-early-lints.rs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/test/run-pass/lint-expr-stmt-attrs-for-early-lints.rs 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 or the MIT license +// , 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); + } +}