diff options
| author | kyoto7250 <50972773+kyoto7250@users.noreply.github.com> | 2022-06-20 11:14:52 +0900 |
|---|---|---|
| committer | kyoto7250 <50972773+kyoto7250@users.noreply.github.com> | 2022-06-20 11:14:52 +0900 |
| commit | 39ffda014debd9d1d4126a8996d39af934fe8d94 (patch) | |
| tree | 30aa6dd103806502dd05d7bc096408bb5e090fff | |
| parent | 46d056e2eb7c5cab767c91383cf7ef1828809fd9 (diff) | |
| download | rust-39ffda014debd9d1d4126a8996d39af934fe8d94.tar.gz rust-39ffda014debd9d1d4126a8996d39af934fe8d94.zip | |
check macro in HitEqInterExpr
| -rw-r--r-- | clippy_utils/src/hir_utils.rs | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/clippy_utils/src/hir_utils.rs b/clippy_utils/src/hir_utils.rs index 3eb01bf75a6..46b615c04f3 100644 --- a/clippy_utils/src/hir_utils.rs +++ b/clippy_utils/src/hir_utils.rs @@ -66,9 +66,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { } pub fn eq_block(&mut self, left: &Block<'_>, right: &Block<'_>) -> bool { - !self.cannot_be_compared_block(left) - && !self.cannot_be_compared_block(right) - && self.inter_expr().eq_block(left, right) + self.inter_expr().eq_block(left, right) } pub fn eq_expr(&mut self, left: &Expr<'_>, right: &Expr<'_>) -> bool { @@ -86,38 +84,6 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> { pub fn eq_path_segments(&mut self, left: &[PathSegment<'_>], right: &[PathSegment<'_>]) -> bool { self.inter_expr().eq_path_segments(left, right) } - - fn cannot_be_compared_block(&mut self, block: &Block<'_>) -> bool { - if block.stmts.last().map_or(false, |stmt| { - matches!( - stmt.kind, - StmtKind::Semi(semi_expr) if self.should_ignore(semi_expr) - ) - }) { - return true; - } - - if let Some(block_expr) = block.expr - && self.should_ignore(block_expr) - { - return true - } - - false - } - - fn should_ignore(&mut self, expr: &Expr<'_>) -> bool { - if macro_backtrace(expr.span).last().map_or(false, |macro_call| { - matches!( - &self.cx.tcx.get_diagnostic_name(macro_call.def_id), - Some(sym::todo_macro | sym::unimplemented_macro) - ) - }) { - return true; - } - - false - } } pub struct HirEqInterExpr<'a, 'b, 'tcx> { @@ -156,6 +122,9 @@ impl HirEqInterExpr<'_, '_, '_> { /// Checks whether two blocks are the same. fn eq_block(&mut self, left: &Block<'_>, right: &Block<'_>) -> bool { + if self.cannot_be_compared_block(left) || self.cannot_be_compared_block(right) { + return false; + } match (left.stmts, left.expr, right.stmts, right.expr) { ([], None, [], None) => { // For empty blocks, check to see if the tokens are equal. This will catch the case where a macro @@ -206,6 +175,38 @@ impl HirEqInterExpr<'_, '_, '_> { } } + fn cannot_be_compared_block(&mut self, block: &Block<'_>) -> bool { + if block.stmts.last().map_or(false, |stmt| { + matches!( + stmt.kind, + StmtKind::Semi(semi_expr) if self.should_ignore(semi_expr) + ) + }) { + return true; + } + + if let Some(block_expr) = block.expr + && self.should_ignore(block_expr) + { + return true + } + + false + } + + fn should_ignore(&mut self, expr: &Expr<'_>) -> bool { + if macro_backtrace(expr.span).last().map_or(false, |macro_call| { + matches!( + &self.inner.cx.tcx.get_diagnostic_name(macro_call.def_id), + Some(sym::todo_macro | sym::unimplemented_macro) + ) + }) { + return true; + } + + false + } + pub fn eq_array_length(&mut self, left: ArrayLen, right: ArrayLen) -> bool { match (left, right) { (ArrayLen::Infer(..), ArrayLen::Infer(..)) => true, |
