Skip to content

Commit 70c6fb9

Browse files
committed
Change the unused parens lint to operate on the AST
1 parent 76856e1 commit 70c6fb9

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

src/librustc_lint/builtin.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use middle::const_eval::{eval_const_expr_partial, ConstVal};
3838
use middle::const_eval::EvalHint::ExprTypeChecked;
3939
use rustc::front::map as hir_map;
4040
use util::nodemap::{FnvHashMap, FnvHashSet, NodeSet};
41-
use lint::{Level, LateContext, LintContext, LintPass, LintArray, Lint};
41+
use lint::{Level, LateContext, EarlyContext, LintContext, LintPass, LintArray, Lint};
4242

4343
use std::collections::HashSet;
4444
use std::collections::hash_map::Entry::{Occupied, Vacant};
@@ -1390,9 +1390,9 @@ declare_lint! {
13901390
pub struct UnusedParens;
13911391

13921392
impl UnusedParens {
1393-
fn check_unused_parens_core(&self, cx: &LateContext, value: &hir::Expr, msg: &str,
1393+
fn check_unused_parens_core(&self, cx: &EarlyContext, value: &ast::Expr, msg: &str,
13941394
struct_lit_needs_parens: bool) {
1395-
if let hir::ExprParen(ref inner) = value.node {
1395+
if let ast::ExprParen(ref inner) = value.node {
13961396
let necessary = struct_lit_needs_parens && contains_exterior_struct_lit(&**inner);
13971397
if !necessary {
13981398
cx.span_lint(UNUSED_PARENS, value.span,
@@ -1405,27 +1405,27 @@ impl UnusedParens {
14051405
/// delimiters, e.g. `X { y: 1 }`, `X { y: 1 }.method()`, `foo
14061406
/// == X { y: 1 }` and `X { y: 1 } == foo` all do, but `(X {
14071407
/// y: 1 }) == foo` does not.
1408-
fn contains_exterior_struct_lit(value: &hir::Expr) -> bool {
1408+
fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
14091409
match value.node {
1410-
hir::ExprStruct(..) => true,
1410+
ast::ExprStruct(..) => true,
14111411

1412-
hir::ExprAssign(ref lhs, ref rhs) |
1413-
hir::ExprAssignOp(_, ref lhs, ref rhs) |
1414-
hir::ExprBinary(_, ref lhs, ref rhs) => {
1412+
ast::ExprAssign(ref lhs, ref rhs) |
1413+
ast::ExprAssignOp(_, ref lhs, ref rhs) |
1414+
ast::ExprBinary(_, ref lhs, ref rhs) => {
14151415
// X { y: 1 } + X { y: 2 }
14161416
contains_exterior_struct_lit(&**lhs) ||
14171417
contains_exterior_struct_lit(&**rhs)
14181418
}
1419-
hir::ExprUnary(_, ref x) |
1420-
hir::ExprCast(ref x, _) |
1421-
hir::ExprField(ref x, _) |
1422-
hir::ExprTupField(ref x, _) |
1423-
hir::ExprIndex(ref x, _) => {
1419+
ast::ExprUnary(_, ref x) |
1420+
ast::ExprCast(ref x, _) |
1421+
ast::ExprField(ref x, _) |
1422+
ast::ExprTupField(ref x, _) |
1423+
ast::ExprIndex(ref x, _) => {
14241424
// &X { y: 1 }, X { y: 1 }.y
14251425
contains_exterior_struct_lit(&**x)
14261426
}
14271427

1428-
hir::ExprMethodCall(_, _, ref exprs) => {
1428+
ast::ExprMethodCall(_, _, ref exprs) => {
14291429
// X { y: 1 }.bar(...)
14301430
contains_exterior_struct_lit(&*exprs[0])
14311431
}
@@ -1441,28 +1441,28 @@ impl LintPass for UnusedParens {
14411441
lint_array!(UNUSED_PARENS)
14421442
}
14431443

1444-
fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
1444+
fn check_ast_expr(&mut self, cx: &EarlyContext, e: &ast::Expr) {
14451445
let (value, msg, struct_lit_needs_parens) = match e.node {
1446-
hir::ExprIf(ref cond, _, _) => (cond, "`if` condition", true),
1447-
hir::ExprWhile(ref cond, _, _) => (cond, "`while` condition", true),
1448-
hir::ExprMatch(ref head, _, source) => match source {
1449-
hir::MatchSource::Normal => (head, "`match` head expression", true),
1450-
hir::MatchSource::IfLetDesugar { .. } => (head, "`if let` head expression", true),
1451-
hir::MatchSource::WhileLetDesugar => (head, "`while let` head expression", true),
1452-
hir::MatchSource::ForLoopDesugar => (head, "`for` head expression", true),
1446+
ast::ExprIf(ref cond, _, _) => (cond, "`if` condition", true),
1447+
ast::ExprWhile(ref cond, _, _) => (cond, "`while` condition", true),
1448+
ast::ExprMatch(ref head, _, source) => match source {
1449+
ast::MatchSource::Normal => (head, "`match` head expression", true),
1450+
ast::MatchSource::IfLetDesugar { .. } => (head, "`if let` head expression", true),
1451+
ast::MatchSource::WhileLetDesugar => (head, "`while let` head expression", true),
1452+
ast::MatchSource::ForLoopDesugar => (head, "`for` head expression", true),
14531453
},
1454-
hir::ExprRet(Some(ref value)) => (value, "`return` value", false),
1455-
hir::ExprAssign(_, ref value) => (value, "assigned value", false),
1456-
hir::ExprAssignOp(_, _, ref value) => (value, "assigned value", false),
1454+
ast::ExprRet(Some(ref value)) => (value, "`return` value", false),
1455+
ast::ExprAssign(_, ref value) => (value, "assigned value", false),
1456+
ast::ExprAssignOp(_, _, ref value) => (value, "assigned value", false),
14571457
_ => return
14581458
};
14591459
self.check_unused_parens_core(cx, &**value, msg, struct_lit_needs_parens);
14601460
}
14611461

1462-
fn check_stmt(&mut self, cx: &LateContext, s: &hir::Stmt) {
1462+
fn check_ast_stmt(&mut self, cx: &EarlyContext, s: &ast::Stmt) {
14631463
let (value, msg) = match s.node {
1464-
hir::StmtDecl(ref decl, _) => match decl.node {
1465-
hir::DeclLocal(ref local) => match local.init {
1464+
ast::StmtDecl(ref decl, _) => match decl.node {
1465+
ast::DeclLocal(ref local) => match local.init {
14661466
Some(ref value) => (value, "assigned value"),
14671467
None => return
14681468
},

0 commit comments

Comments
 (0)