Skip to content

Commit

Permalink
Diverging subexpression lint should not fire on todo!()
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-semenyuk committed Aug 18, 2024
1 parent 5da97d0 commit 9732128
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions clippy_lints/src/mixed_read_write_in_expression.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
use clippy_utils::macros::root_macro_call_first_node;
use clippy_utils::{get_parent_expr, path_to_local, path_to_local_id};
use rustc_hir::intravisit::{walk_expr, Visitor};
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, HirId, LetStmt, Node, Stmt, StmtKind};
Expand Down Expand Up @@ -134,6 +135,11 @@ impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> {
}

fn report_diverging_sub_expr(&mut self, e: &Expr<'_>) {
if let Some(macro_call) = root_macro_call_first_node(self.cx, e) {
if self.cx.tcx.item_name(macro_call.def_id).as_str() == "todo" {
return;
}
}
span_lint(self.cx, DIVERGING_SUB_EXPRESSION, e.span, "sub-expression diverges");
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/diverging_sub_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,9 @@ fn foobar() {
};
}
}

#[allow(unused)]
fn ignore_todo() {
let x: u32 = todo!();
println!("{x}");
}

0 comments on commit 9732128

Please sign in to comment.