about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-08-25 09:51:40 +0000
committerbors <bors@rust-lang.org>2024-08-25 09:51:40 +0000
commit40bca0d944c6356dfd3a65e2466f3a05ee2dbb83 (patch)
treeb0d867a8652e1198f18bc986073dc172697f9766
parent0f8eabd6231366bfc1bb1464601297c2d48f8f68 (diff)
parent9732128e831b3870b48d95280317f55b9619feb1 (diff)
downloadrust-40bca0d944c6356dfd3a65e2466f3a05ee2dbb83.tar.gz
rust-40bca0d944c6356dfd3a65e2466f3a05ee2dbb83.zip
Auto merge of #13285 - alex-semenyuk:ignore_todo_for_diverging_sub_expression, 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
-rw-r--r--clippy_lints/src/mixed_read_write_in_expression.rs6
-rw-r--r--tests/ui/diverging_sub_expression.rs6
2 files changed, 12 insertions, 0 deletions
diff --git a/clippy_lints/src/mixed_read_write_in_expression.rs b/clippy_lints/src/mixed_read_write_in_expression.rs
index 0b3769ecb7c..0b7d97c32c5 100644
--- a/clippy_lints/src/mixed_read_write_in_expression.rs
+++ b/clippy_lints/src/mixed_read_write_in_expression.rs
@@ -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};
@@ -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");
     }
 }
diff --git a/tests/ui/diverging_sub_expression.rs b/tests/ui/diverging_sub_expression.rs
index e0acf050949..1abba60fd34 100644
--- a/tests/ui/diverging_sub_expression.rs
+++ b/tests/ui/diverging_sub_expression.rs
@@ -67,3 +67,9 @@ fn foobar() {
         };
     }
 }
+
+#[allow(unused)]
+fn ignore_todo() {
+    let x: u32 = todo!();
+    println!("{x}");
+}