Skip to content

Commit 7c8e1bf

Browse files
committed
Auto merge of rust-lang#9207 - Jarcho:todo_arm, r=giraffate
Check for `todo!` on every expression in `SpanlessEq` fixes rust-lang#9204 changelog: [`match_same_arms`](https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms): Don't lint on arms with `todo!`
2 parents e98b3ca + 95c7591 commit 7c8e1bf

File tree

2 files changed

+13
-30
lines changed

2 files changed

+13
-30
lines changed

clippy_utils/src/hir_utils.rs

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,6 @@ impl HirEqInterExpr<'_, '_, '_> {
127127

128128
/// Checks whether two blocks are the same.
129129
fn eq_block(&mut self, left: &Block<'_>, right: &Block<'_>) -> bool {
130-
if self.cannot_be_compared_block(left) || self.cannot_be_compared_block(right) {
131-
return false;
132-
}
133130
match (left.stmts, left.expr, right.stmts, right.expr) {
134131
([], None, [], None) => {
135132
// For empty blocks, check to see if the tokens are equal. This will catch the case where a macro
@@ -180,36 +177,13 @@ impl HirEqInterExpr<'_, '_, '_> {
180177
}
181178
}
182179

183-
fn cannot_be_compared_block(&mut self, block: &Block<'_>) -> bool {
184-
if block.stmts.last().map_or(false, |stmt| {
185-
matches!(
186-
stmt.kind,
187-
StmtKind::Semi(semi_expr) if self.should_ignore(semi_expr)
188-
)
189-
}) {
190-
return true;
191-
}
192-
193-
if let Some(block_expr) = block.expr
194-
&& self.should_ignore(block_expr)
195-
{
196-
return true
197-
}
198-
199-
false
200-
}
201-
202180
fn should_ignore(&mut self, expr: &Expr<'_>) -> bool {
203-
if macro_backtrace(expr.span).last().map_or(false, |macro_call| {
181+
macro_backtrace(expr.span).last().map_or(false, |macro_call| {
204182
matches!(
205183
&self.inner.cx.tcx.get_diagnostic_name(macro_call.def_id),
206184
Some(sym::todo_macro | sym::unimplemented_macro)
207185
)
208-
}) {
209-
return true;
210-
}
211-
212-
false
186+
})
213187
}
214188

215189
pub fn eq_array_length(&mut self, left: ArrayLen, right: ArrayLen) -> bool {
@@ -327,7 +301,8 @@ impl HirEqInterExpr<'_, '_, '_> {
327301
(&ExprKind::DropTemps(le), &ExprKind::DropTemps(re)) => self.eq_expr(le, re),
328302
_ => false,
329303
};
330-
is_eq || self.inner.expr_fallback.as_mut().map_or(false, |f| f(left, right))
304+
(is_eq && (!self.should_ignore(left) || !self.should_ignore(right)))
305+
|| self.inner.expr_fallback.as_mut().map_or(false, |f| f(left, right))
331306
}
332307

333308
fn eq_exprs(&mut self, left: &[Expr<'_>], right: &[Expr<'_>]) -> bool {

tests/ui/match_same_arms2.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![warn(clippy::match_same_arms)]
2-
#![allow(clippy::blacklisted_name)]
2+
#![allow(clippy::blacklisted_name, clippy::diverging_sub_expression)]
33

44
fn bar<T>(_: T) {}
55
fn foo() -> bool {
@@ -227,4 +227,12 @@ fn main() {
227227
Some(Bar { y: 0, x: 5, .. }) => 1,
228228
_ => 200,
229229
};
230+
231+
let _ = match 0 {
232+
0 => todo!(),
233+
1 => todo!(),
234+
2 => core::convert::identity::<u32>(todo!()),
235+
3 => core::convert::identity::<u32>(todo!()),
236+
_ => 5,
237+
};
230238
}

0 commit comments

Comments
 (0)