Skip to content

Commit 9306e9a

Browse files
Dany Marcouxkyoto7250
authored andcommitted
Ignore bodies containing todo!() in clippy::if_same_then_else
1 parent 844c06a commit 9306e9a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

clippy_lints/src/copies.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_lint::{LateContext, LateLintPass};
1212
use rustc_session::{declare_lint_pass, declare_tool_lint};
1313
use rustc_span::hygiene::walk_chain;
1414
use rustc_span::source_map::SourceMap;
15-
use rustc_span::{BytePos, Span, Symbol};
15+
use rustc_span::{sym, BytePos, Span, Symbol};
1616
use std::borrow::Cow;
1717

1818
declare_clippy_lint! {
@@ -365,6 +365,21 @@ fn eq_stmts(
365365
.all(|b| get_stmt(b).map_or(false, |s| eq.eq_stmt(s, stmt)))
366366
}
367367

368+
fn block_contains_todo_macro(cx: &LateContext<'_>, block: &Block<'_>) -> bool {
369+
dbg!(block);
370+
if let Some(macro_def_id) = block.span.ctxt().outer_expn_data().macro_def_id {
371+
dbg!(macro_def_id);
372+
if let Some(diagnostic_name) = cx.tcx.get_diagnostic_name(macro_def_id) {
373+
dbg!(diagnostic_name);
374+
diagnostic_name == sym::todo_macro
375+
} else {
376+
false
377+
}
378+
} else {
379+
false
380+
}
381+
}
382+
368383
fn scan_block_for_eq(cx: &LateContext<'_>, _conds: &[&Expr<'_>], block: &Block<'_>, blocks: &[&Block<'_>]) -> BlockEq {
369384
let mut eq = SpanlessEq::new(cx);
370385
let mut eq = eq.inter_expr();
@@ -398,6 +413,7 @@ fn scan_block_for_eq(cx: &LateContext<'_>, _conds: &[&Expr<'_>], block: &Block<'
398413
moved_locals,
399414
};
400415
}
416+
401417
let end_search_start = block.stmts[start_end_eq..]
402418
.iter()
403419
.rev()

tests/ui/if_same_then_else.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ fn if_same_then_else() {
126126
_ => 4,
127127
};
128128
}
129+
130+
// Issue #8836
131+
if true { todo!() } else { todo!() }
129132
}
130133

131134
// Issue #2423. This was causing an ICE.

0 commit comments

Comments
 (0)