Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap EarlyContext::visit_local/visit_expr in with_lint_attrs calls #30487

Merged
merged 2 commits into from
Jan 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,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);
}

Expand Down Expand Up @@ -834,8 +834,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) {
Expand Down Expand Up @@ -890,8 +892,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) {
Expand Down
22 changes: 22 additions & 0 deletions src/test/run-pass/lint-expr-stmt-attrs-for-early-lints.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}