From 909bfd3cd843a8a9fea1db1ddf52fc34744b14ac Mon Sep 17 00:00:00 2001 From: flip1995 Date: Fri, 28 Dec 2018 12:29:34 +0100 Subject: [PATCH] Match on ast/hir::ExprKind::Err --- clippy_lints/src/loops.rs | 3 ++- clippy_lints/src/utils/author.rs | 3 +++ clippy_lints/src/utils/hir_utils.rs | 1 + clippy_lints/src/utils/inspector.rs | 3 +++ clippy_lints/src/utils/sugg.rs | 6 ++++-- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 8664061fb7a..8bf509844ac 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -756,7 +756,8 @@ fn never_loop_expr(expr: &Expr, main_loop_id: NodeId) -> NeverLoopResult { | ExprKind::Closure(_, _, _, _, _) | ExprKind::InlineAsm(_, _, _) | ExprKind::Path(_) - | ExprKind::Lit(_) => NeverLoopResult::Otherwise, + | ExprKind::Lit(_) + | ExprKind::Err => NeverLoopResult::Otherwise, } } diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 7e09eae1e93..9eb543db6d4 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -504,6 +504,9 @@ fn visit_expr(&mut self, expr: &Expr) { self.current = value_pat; self.visit_expr(value); }, + ExprKind::Err => { + println!("Err = {}", current); + }, } } diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index 73169414a02..d7a57945658 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -615,6 +615,7 @@ pub fn hash_expr(&mut self, e: &Expr) { self.hash_name(l.ident.name); } }, + ExprKind::Err => {}, } } diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 93a5845ad45..b9a58c51706 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -347,6 +347,9 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr, indent: usize) { println!("{}repeat count:", ind); print_expr(cx, &cx.tcx.hir().body(anon_const.body).value, indent + 1); }, + hir::ExprKind::Err => { + println!("{}Err", ind); + }, } } diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index 66f18b51f21..f087b73bef4 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -79,7 +79,8 @@ pub fn hir_opt(cx: &LateContext<'_, '_>, expr: &hir::Expr) -> Option { | hir::ExprKind::Ret(..) | hir::ExprKind::Struct(..) | hir::ExprKind::Tup(..) - | hir::ExprKind::While(..) => Sugg::NonParen(snippet), + | hir::ExprKind::While(..) + | hir::ExprKind::Err => Sugg::NonParen(snippet), hir::ExprKind::Assign(..) => Sugg::BinOp(AssocOp::Assign, snippet), hir::ExprKind::AssignOp(op, ..) => Sugg::BinOp(hirbinop2assignop(op), snippet), hir::ExprKind::Binary(op, ..) => Sugg::BinOp(AssocOp::from_ast_binop(higher::binop(op.node)), snippet), @@ -158,7 +159,8 @@ pub fn ast(cx: &EarlyContext<'_>, expr: &ast::Expr, default: &'a str) -> Self { | ast::ExprKind::Tup(..) | ast::ExprKind::Array(..) | ast::ExprKind::While(..) - | ast::ExprKind::WhileLet(..) => Sugg::NonParen(snippet), + | ast::ExprKind::WhileLet(..) + | ast::ExprKind::Err => Sugg::NonParen(snippet), ast::ExprKind::Range(.., RangeLimits::HalfOpen) => Sugg::BinOp(AssocOp::DotDot, snippet), ast::ExprKind::Range(.., RangeLimits::Closed) => Sugg::BinOp(AssocOp::DotDotEq, snippet), ast::ExprKind::Assign(..) => Sugg::BinOp(AssocOp::Assign, snippet),