From 9306e9a4df2e6f8ed577fff3c82006c532ca51d2 Mon Sep 17 00:00:00 2001 From: Dany Marcoux Date: Wed, 18 May 2022 20:28:11 +0200 Subject: [PATCH] Ignore bodies containing `todo!()` in `clippy::if_same_then_else` --- clippy_lints/src/copies.rs | 18 +++++++++++++++++- tests/ui/if_same_then_else.rs | 3 +++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index 1deff9684..6f92caf73 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -12,7 +12,7 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::hygiene::walk_chain; use rustc_span::source_map::SourceMap; -use rustc_span::{BytePos, Span, Symbol}; +use rustc_span::{sym, BytePos, Span, Symbol}; use std::borrow::Cow; declare_clippy_lint! { @@ -365,6 +365,21 @@ fn eq_stmts( .all(|b| get_stmt(b).map_or(false, |s| eq.eq_stmt(s, stmt))) } +fn block_contains_todo_macro(cx: &LateContext<'_>, block: &Block<'_>) -> bool { + dbg!(block); + if let Some(macro_def_id) = block.span.ctxt().outer_expn_data().macro_def_id { + dbg!(macro_def_id); + if let Some(diagnostic_name) = cx.tcx.get_diagnostic_name(macro_def_id) { + dbg!(diagnostic_name); + diagnostic_name == sym::todo_macro + } else { + false + } + } else { + false + } +} + fn scan_block_for_eq(cx: &LateContext<'_>, _conds: &[&Expr<'_>], block: &Block<'_>, blocks: &[&Block<'_>]) -> BlockEq { let mut eq = SpanlessEq::new(cx); let mut eq = eq.inter_expr(); @@ -398,6 +413,7 @@ fn scan_block_for_eq(cx: &LateContext<'_>, _conds: &[&Expr<'_>], block: &Block<' moved_locals, }; } + let end_search_start = block.stmts[start_end_eq..] .iter() .rev() diff --git a/tests/ui/if_same_then_else.rs b/tests/ui/if_same_then_else.rs index ef9567455..767185c20 100644 --- a/tests/ui/if_same_then_else.rs +++ b/tests/ui/if_same_then_else.rs @@ -126,6 +126,9 @@ fn if_same_then_else() { _ => 4, }; } + + // Issue #8836 + if true { todo!() } else { todo!() } } // Issue #2423. This was causing an ICE.