Skip to content

Commit 40bca0d

Browse files
committed
Auto merge of rust-lang#13285 - alex-semenyuk:ignore_todo_for_diverging_sub_expression, r=xFrednet
Diverging subexpression lint should not fire on todo!() As per rust-lang#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
2 parents 0f8eabd + 9732128 commit 40bca0d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

clippy_lints/src/mixed_read_write_in_expression.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
2+
use clippy_utils::macros::root_macro_call_first_node;
23
use clippy_utils::{get_parent_expr, path_to_local, path_to_local_id};
34
use rustc_hir::intravisit::{walk_expr, Visitor};
45
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, HirId, LetStmt, Node, Stmt, StmtKind};
@@ -134,6 +135,11 @@ impl<'a, 'tcx> DivergenceVisitor<'a, 'tcx> {
134135
}
135136

136137
fn report_diverging_sub_expr(&mut self, e: &Expr<'_>) {
138+
if let Some(macro_call) = root_macro_call_first_node(self.cx, e) {
139+
if self.cx.tcx.item_name(macro_call.def_id).as_str() == "todo" {
140+
return;
141+
}
142+
}
137143
span_lint(self.cx, DIVERGING_SUB_EXPRESSION, e.span, "sub-expression diverges");
138144
}
139145
}

tests/ui/diverging_sub_expression.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,9 @@ fn foobar() {
6767
};
6868
}
6969
}
70+
71+
#[allow(unused)]
72+
fn ignore_todo() {
73+
let x: u32 = todo!();
74+
println!("{x}");
75+
}

0 commit comments

Comments
 (0)