Skip to content

Commit 39ffda0

Browse files
committed
check macro in HitEqInterExpr
1 parent 46d056e commit 39ffda0

File tree

1 file changed

+36
-35
lines changed

1 file changed

+36
-35
lines changed

clippy_utils/src/hir_utils.rs

+36-35
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
6666
}
6767

6868
pub fn eq_block(&mut self, left: &Block<'_>, right: &Block<'_>) -> bool {
69-
!self.cannot_be_compared_block(left)
70-
&& !self.cannot_be_compared_block(right)
71-
&& self.inter_expr().eq_block(left, right)
69+
self.inter_expr().eq_block(left, right)
7270
}
7371

7472
pub fn eq_expr(&mut self, left: &Expr<'_>, right: &Expr<'_>) -> bool {
@@ -86,38 +84,6 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
8684
pub fn eq_path_segments(&mut self, left: &[PathSegment<'_>], right: &[PathSegment<'_>]) -> bool {
8785
self.inter_expr().eq_path_segments(left, right)
8886
}
89-
90-
fn cannot_be_compared_block(&mut self, block: &Block<'_>) -> bool {
91-
if block.stmts.last().map_or(false, |stmt| {
92-
matches!(
93-
stmt.kind,
94-
StmtKind::Semi(semi_expr) if self.should_ignore(semi_expr)
95-
)
96-
}) {
97-
return true;
98-
}
99-
100-
if let Some(block_expr) = block.expr
101-
&& self.should_ignore(block_expr)
102-
{
103-
return true
104-
}
105-
106-
false
107-
}
108-
109-
fn should_ignore(&mut self, expr: &Expr<'_>) -> bool {
110-
if macro_backtrace(expr.span).last().map_or(false, |macro_call| {
111-
matches!(
112-
&self.cx.tcx.get_diagnostic_name(macro_call.def_id),
113-
Some(sym::todo_macro | sym::unimplemented_macro)
114-
)
115-
}) {
116-
return true;
117-
}
118-
119-
false
120-
}
12187
}
12288

12389
pub struct HirEqInterExpr<'a, 'b, 'tcx> {
@@ -156,6 +122,9 @@ impl HirEqInterExpr<'_, '_, '_> {
156122

157123
/// Checks whether two blocks are the same.
158124
fn eq_block(&mut self, left: &Block<'_>, right: &Block<'_>) -> bool {
125+
if self.cannot_be_compared_block(left) || self.cannot_be_compared_block(right) {
126+
return false;
127+
}
159128
match (left.stmts, left.expr, right.stmts, right.expr) {
160129
([], None, [], None) => {
161130
// 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<'_, '_, '_> {
206175
}
207176
}
208177

178+
fn cannot_be_compared_block(&mut self, block: &Block<'_>) -> bool {
179+
if block.stmts.last().map_or(false, |stmt| {
180+
matches!(
181+
stmt.kind,
182+
StmtKind::Semi(semi_expr) if self.should_ignore(semi_expr)
183+
)
184+
}) {
185+
return true;
186+
}
187+
188+
if let Some(block_expr) = block.expr
189+
&& self.should_ignore(block_expr)
190+
{
191+
return true
192+
}
193+
194+
false
195+
}
196+
197+
fn should_ignore(&mut self, expr: &Expr<'_>) -> bool {
198+
if macro_backtrace(expr.span).last().map_or(false, |macro_call| {
199+
matches!(
200+
&self.inner.cx.tcx.get_diagnostic_name(macro_call.def_id),
201+
Some(sym::todo_macro | sym::unimplemented_macro)
202+
)
203+
}) {
204+
return true;
205+
}
206+
207+
false
208+
}
209+
209210
pub fn eq_array_length(&mut self, left: ArrayLen, right: ArrayLen) -> bool {
210211
match (left, right) {
211212
(ArrayLen::Infer(..), ArrayLen::Infer(..)) => true,

0 commit comments

Comments
 (0)