about summary refs log tree commit diff
diff options
context:
space:
mode:
authorShotaro Yamada <sinkuu@sinkuu.xyz>2020-04-19 22:56:47 +0900
committerShotaro Yamada <sinkuu@sinkuu.xyz>2020-04-19 22:56:47 +0900
commit554f47bb48273fd91a1f2cb605667e0505da91ac (patch)
tree5ce974373fe3946cf2a78f250bdda667829af77a
parentf6b07db3859650b8189af7cce566c93716d97cdc (diff)
downloadrust-554f47bb48273fd91a1f2cb605667e0505da91ac.tar.gz
rust-554f47bb48273fd91a1f2cb605667e0505da91ac.zip
Don't trigger toplevel_ref_arg for `for` loops
-rw-r--r--clippy_lints/src/misc.rs3
-rw-r--r--tests/ui/toplevel_ref_arg.fixed3
-rw-r--r--tests/ui/toplevel_ref_arg.rs3
3 files changed, 8 insertions, 1 deletions
diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs
index e6f4be333e7..c49d3ba5dec 100644
--- a/clippy_lints/src/misc.rs
+++ b/clippy_lints/src/misc.rs
@@ -14,7 +14,7 @@ use rustc_span::source_map::{ExpnKind, Span};
 use crate::consts::{constant, Constant};
 use crate::utils::sugg::Sugg;
 use crate::utils::{
-    get_item_name, get_parent_expr, implements_trait, in_constant, is_integer_const, iter_input_pats,
+    get_item_name, get_parent_expr, higher, implements_trait, in_constant, is_integer_const, iter_input_pats,
     last_path_segment, match_qpath, match_trait_method, paths, snippet, snippet_opt, span_lint, span_lint_and_sugg,
     span_lint_and_then, span_lint_hir_and_then, walk_ptrs_ty, SpanlessEq,
 };
@@ -267,6 +267,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MiscLints {
             if let StmtKind::Local(ref local) = stmt.kind;
             if let PatKind::Binding(an, .., name, None) = local.pat.kind;
             if let Some(ref init) = local.init;
+            if !higher::is_from_for_desugar(local);
             then {
                 if an == BindingAnnotation::Ref || an == BindingAnnotation::RefMut {
                     let sugg_init = if init.span.from_expansion() {
diff --git a/tests/ui/toplevel_ref_arg.fixed b/tests/ui/toplevel_ref_arg.fixed
index 9438abbe330..33605aca019 100644
--- a/tests/ui/toplevel_ref_arg.fixed
+++ b/tests/ui/toplevel_ref_arg.fixed
@@ -23,4 +23,7 @@ fn main() {
     // Make sure that allowing the lint works
     #[allow(clippy::toplevel_ref_arg)]
     let ref mut _x = 1_234_543;
+
+    // ok
+    for ref _x in 0..10 {}
 }
diff --git a/tests/ui/toplevel_ref_arg.rs b/tests/ui/toplevel_ref_arg.rs
index ee630f12a60..59759f11893 100644
--- a/tests/ui/toplevel_ref_arg.rs
+++ b/tests/ui/toplevel_ref_arg.rs
@@ -23,4 +23,7 @@ fn main() {
     // Make sure that allowing the lint works
     #[allow(clippy::toplevel_ref_arg)]
     let ref mut _x = 1_234_543;
+
+    // ok
+    for ref _x in 0..10 {}
 }