Check for todo! on every expression in SpanlessEq

This commit is contained in:
Jason Newcomb 2022-07-19 09:53:00 -04:00
parent e57c6d6f21
commit 95c759157c
2 changed files with 13 additions and 30 deletions

View File

@ -127,9 +127,6 @@ pub fn eq_stmt(&mut self, left: &Stmt<'_>, right: &Stmt<'_>) -> bool {
/// 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
@ -180,36 +177,13 @@ fn eq_block(&mut self, left: &Block<'_>, right: &Block<'_>) -> bool {
}
}
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| {
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 {
@ -327,7 +301,8 @@ pub fn eq_expr(&mut self, left: &Expr<'_>, right: &Expr<'_>) -> bool {
(&ExprKind::DropTemps(le), &ExprKind::DropTemps(re)) => self.eq_expr(le, re),
_ => false,
};
is_eq || self.inner.expr_fallback.as_mut().map_or(false, |f| f(left, right))
(is_eq && (!self.should_ignore(left) || !self.should_ignore(right)))
|| self.inner.expr_fallback.as_mut().map_or(false, |f| f(left, right))
}
fn eq_exprs(&mut self, left: &[Expr<'_>], right: &[Expr<'_>]) -> bool {

View File

@ -1,5 +1,5 @@
#![warn(clippy::match_same_arms)]
#![allow(clippy::blacklisted_name)]
#![allow(clippy::blacklisted_name, clippy::diverging_sub_expression)]
fn bar<T>(_: T) {}
fn foo() -> bool {
@ -227,4 +227,12 @@ struct Bar {
Some(Bar { y: 0, x: 5, .. }) => 1,
_ => 200,
};
let _ = match 0 {
0 => todo!(),
1 => todo!(),
2 => core::convert::identity::<u32>(todo!()),
3 => core::convert::identity::<u32>(todo!()),
_ => 5,
};
}