about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-07-09 12:34:03 +0000
committerbors <bors@rust-lang.org>2022-07-09 12:34:03 +0000
commit3468294b58f0afc0c4241aa94c5c8bfa85ceb9fc (patch)
treec995763485c1b4728c098b7d58fe06bd314baa25
parent526f02ef053b8e249cea814bf603ced24dd9c48d (diff)
parent95b78799c38ee7e9b7489f265963b69405686e06 (diff)
downloadrust-3468294b58f0afc0c4241aa94c5c8bfa85ceb9fc.tar.gz
rust-3468294b58f0afc0c4241aa94c5c8bfa85ceb9fc.zip
Auto merge of #9140 - Jarcho:sig_drop, r=flip1995
Ignore `into_iter` in `significant_drop_in_scrutinee`

fixes #9135
changelog: Ignore the `IntoIterator::into_iter` call from for loops in `significant_drop_in_scrutinee`
-rw-r--r--clippy_lints/src/matches/significant_drop_in_scrutinee.rs4
-rw-r--r--tests/ui/significant_drop_in_scrutinee.rs7
2 files changed, 11 insertions, 0 deletions
diff --git a/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/clippy_lints/src/matches/significant_drop_in_scrutinee.rs
index 0704a5af525..b0b15b3f54c 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<FoundSigDrop>, &'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 185e5009b60..84ecf1ea53e 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() {}