]> git.lizzy.rs Git - rust.git/commitdiff
Fix suggestions for `REVERSE_RANGE_LOOP`
authormcarton <cartonmartin+git@gmail.com>
Thu, 9 Jun 2016 21:05:48 +0000 (23:05 +0200)
committermcarton <cartonmartin+git@gmail.com>
Thu, 9 Jun 2016 21:34:19 +0000 (23:34 +0200)
clippy_lints/src/loops.rs
tests/compile-fail/for_loop.rs

index 5dcea35e5a711580724ac6eebf6e53fb9da543ee..5d431e47465f0934b9a6bce74b1477cfccf17aca 100644 (file)
@@ -444,6 +444,11 @@ fn check_for_loop_reverse_range(cx: &LateContext, arg: &Expr, expr: &Expr) {
                 if sup {
                     let start_snippet = snippet(cx, start.span, "_");
                     let end_snippet = snippet(cx, end.span, "_");
+                    let dots = if limits == ast::RangeLimits::Closed {
+                        "..."
+                    } else {
+                        ".."
+                    };
 
                     span_lint_and_then(cx,
                                        REVERSE_RANGE_LOOP,
@@ -454,7 +459,10 @@ fn check_for_loop_reverse_range(cx: &LateContext, arg: &Expr, expr: &Expr) {
                                                               "consider using the following if \
                                                                you are attempting to iterate \
                                                                over this range in reverse",
-                                                              format!("({}..{}).rev()", end_snippet, start_snippet));
+                                                              format!("({end}{dots}{start}).rev()",
+                                                                      end=end_snippet,
+                                                                      dots=dots,
+                                                                      start=start_snippet));
                                        });
                 } else if eq && limits != ast::RangeLimits::Closed {
                     // if they are equal, it's also problematic - this loop
index d35beb617e05cf0fb0e21e06e47f0104f7387617..411a4b11c17a064a442461c96b694d81fd1f2987 100644 (file)
@@ -169,7 +169,7 @@ fn main() {
     for i in 10...0 {
         //~^ERROR this range is empty so this for loop will never run
         //~|HELP consider
-        //~|SUGGESTION (0..10).rev()
+        //~|SUGGESTION (0...10).rev()
         println!("{}", i);
     }