Skip to content

Commit

Permalink
Auto merge of #13285 - alex-semenyuk:ignore_todo_for_diverging_sub_ex…
Browse files Browse the repository at this point in the history
…pression, r=xFrednet

Diverging subexpression lint should not fire on todo!()

As per #10243  it is not that helpful to point out that a subexpression diverges, so do not fire on todo

changelog: [`diverging_sub_expression`]: do not trigger on todo
  • Loading branch information
bors committed Aug 25, 2024
2 parents 0f8eabd + 9732128 commit 40bca0d
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 40bca0d

Please sign in to comment.