diff options
| author | Jason Newcomb <jsnewcomb@pm.me> | 2022-07-09 08:15:13 -0400 |
|---|---|---|
| committer | Jason Newcomb <jsnewcomb@pm.me> | 2022-07-09 08:15:13 -0400 |
| commit | 95b78799c38ee7e9b7489f265963b69405686e06 (patch) | |
| tree | c995763485c1b4728c098b7d58fe06bd314baa25 | |
| parent | 526f02ef053b8e249cea814bf603ced24dd9c48d (diff) | |
| download | rust-95b78799c38ee7e9b7489f265963b69405686e06.tar.gz rust-95b78799c38ee7e9b7489f265963b69405686e06.zip | |
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.rs | 4 | ||||
| -rw-r--r-- | tests/ui/significant_drop_in_scrutinee.rs | 7 |
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() {} |
