about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPreston From <prestonfrom@gmail.com>2022-06-02 02:23:42 -0600
committerPreston From <prestonfrom@gmail.com>2022-06-02 02:38:57 -0600
commitbc5a8e9537d30858fede92347e3842d4d4f8a803 (patch)
tree29202e1d17e10cb8b198f83a24a266eb3d97d67e
parente33d87d4a0a188aa03d7d07700dbf296cf76581a (diff)
downloadrust-bc5a8e9537d30858fede92347e3842d4d4f8a803.tar.gz
rust-bc5a8e9537d30858fede92347e3842d4d4f8a803.zip
Lint message correctly identifies match vs for loop
-rw-r--r--clippy_lints/src/significant_drop_in_scrutinee.rs23
-rw-r--r--tests/ui/significant_drop_in_scrutinee.stderr2
2 files changed, 14 insertions, 11 deletions
diff --git a/clippy_lints/src/significant_drop_in_scrutinee.rs b/clippy_lints/src/significant_drop_in_scrutinee.rs
index 6b45b6d4452..2f7819cb470 100644
--- a/clippy_lints/src/significant_drop_in_scrutinee.rs
+++ b/clippy_lints/src/significant_drop_in_scrutinee.rs
@@ -91,15 +91,11 @@ declare_lint_pass!(SignificantDropInScrutinee => [SIGNIFICANT_DROP_IN_SCRUTINEE]
 
 impl<'tcx> LateLintPass<'tcx> for SignificantDropInScrutinee {
     fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
-        if let Some(suggestions) = has_significant_drop_in_scrutinee(cx, expr) {
+        if let Some((suggestions, message)) = has_significant_drop_in_scrutinee(cx, expr) {
             for found in suggestions {
-                span_lint_and_then(
-                    cx,
-                    SIGNIFICANT_DROP_IN_SCRUTINEE,
-                    found.found_span,
-                    "temporary with significant drop in match scrutinee",
-                    |diag| set_diagnostic(diag, cx, expr, found),
-                );
+                span_lint_and_then(cx, SIGNIFICANT_DROP_IN_SCRUTINEE, found.found_span, message, |diag| {
+                    set_diagnostic(diag, cx, expr, found);
+                });
             }
         }
     }
@@ -153,13 +149,20 @@ fn set_diagnostic<'tcx>(diag: &mut Diagnostic, cx: &LateContext<'tcx>, expr: &'t
 fn has_significant_drop_in_scrutinee<'tcx, 'a>(
     cx: &'a LateContext<'tcx>,
     expr: &'tcx Expr<'tcx>,
-) -> Option<Vec<FoundSigDrop>> {
+) -> Option<(Vec<FoundSigDrop>, &'static str)> {
     match expr.kind {
         ExprKind::Match(match_expr, _, source) => {
             match source {
                 MatchSource::Normal | MatchSource::ForLoopDesugar => {
                     let mut helper = SigDropHelper::new(cx);
-                    helper.find_sig_drop(match_expr)
+                    helper.find_sig_drop(match_expr).map(|drops| {
+                        let message = if source == MatchSource::Normal {
+                            "temporary with significant drop in match scrutinee"
+                        } else {
+                            "temporary with significant drop in for loop"
+                        };
+                        (drops, message)
+                    })
                 },
                 // MatchSource of TryDesugar or AwaitDesugar is out of scope for this lint
                 MatchSource::TryDesugar | MatchSource::AwaitDesugar => None,
diff --git a/tests/ui/significant_drop_in_scrutinee.stderr b/tests/ui/significant_drop_in_scrutinee.stderr
index 77942325244..303f3c1df03 100644
--- a/tests/ui/significant_drop_in_scrutinee.stderr
+++ b/tests/ui/significant_drop_in_scrutinee.stderr
@@ -285,7 +285,7 @@ error: temporary with significant drop in match scrutinee
 LL |     match rwlock.read().unwrap().to_number() {
    |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: temporary with significant drop in match scrutinee
+error: temporary with significant drop in for loop
   --> $DIR/significant_drop_in_scrutinee.rs:589:14
    |
 LL |     for s in rwlock.read().unwrap().iter() {