From 95b78799c38ee7e9b7489f265963b69405686e06 Mon Sep 17 00:00:00 2001 From: Jason Newcomb Date: Sat, 9 Jul 2022 08:15:13 -0400 Subject: [PATCH] Ignore the `IntoIterator::into_iter` call from for loops in `significant_drop_in_scrutinee` --- clippy_lints/src/matches/significant_drop_in_scrutinee.rs | 4 ++++ tests/ui/significant_drop_in_scrutinee.rs | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs index 0704a5af5..b0b15b3f5 100644 --- a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs +++ b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs @@ -89,6 +89,10 @@ fn has_significant_drop_in_scrutinee<'tcx, 'a>( source: MatchSource, ) -> Option<(Vec, &'static str)> { let mut helper = SigDropHelper::new(cx); + let scrutinee = match (source, &scrutinee.kind) { + (MatchSource::ForLoopDesugar, ExprKind::Call(_, [e])) => e, + _ => scrutinee, + }; helper.find_sig_drop(scrutinee).map(|drops| { let message = if source == MatchSource::Normal { "temporary with significant `Drop` in `match` scrutinee will live until the end of the `match` expression" diff --git a/tests/ui/significant_drop_in_scrutinee.rs b/tests/ui/significant_drop_in_scrutinee.rs index 185e5009b..84ecf1ea5 100644 --- a/tests/ui/significant_drop_in_scrutinee.rs +++ b/tests/ui/significant_drop_in_scrutinee.rs @@ -620,4 +620,11 @@ fn should_trigger_lint_without_significant_drop_in_arm() { }; } +fn should_not_trigger_on_significant_iterator_drop() { + let lines = std::io::stdin().lines(); + for line in lines { + println!("foo: {}", line.unwrap()); + } +} + fn main() {}