From 38a3462037cd578ae5099d4aca8b18e83bc8d86f Mon Sep 17 00:00:00 2001 From: shenyifu <406708433@qq.com> Date: Mon, 29 Jul 2024 14:48:47 +0800 Subject: [PATCH] Fix fix under loop may dropping loop label when applying fix. --- clippy_lints/src/loops/explicit_counter_loop.rs | 8 +++++--- clippy_lints/src/loops/mod.rs | 8 ++++++-- clippy_utils/src/higher.rs | 5 ++++- tests/ui/explicit_counter_loop.rs | 13 +++++++++++++ tests/ui/explicit_counter_loop.stderr | 8 +++++++- tests/ui/for_kv_map.fixed | 10 ++++++++++ tests/ui/for_kv_map.rs | 10 ++++++++++ tests/ui/for_kv_map.stderr | 13 ++++++++++++- 8 files changed, 67 insertions(+), 8 deletions(-) diff --git a/clippy_lints/src/loops/explicit_counter_loop.rs b/clippy_lints/src/loops/explicit_counter_loop.rs index f0ee64d714e..73a23615c2d 100644 --- a/clippy_lints/src/loops/explicit_counter_loop.rs +++ b/clippy_lints/src/loops/explicit_counter_loop.rs @@ -2,6 +2,7 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then}; use clippy_utils::source::snippet_with_applicability; use clippy_utils::{get_enclosing_block, is_integer_const}; +use rustc_ast::Label; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_block, walk_expr}; use rustc_hir::{Expr, Pat}; @@ -17,6 +18,7 @@ pub(super) fn check<'tcx>( arg: &'tcx Expr<'_>, body: &'tcx Expr<'_>, expr: &'tcx Expr<'_>, + label: Option