about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2018-11-10 21:27:40 +0000
committervarkor <github@varkor.com>2018-11-10 21:27:40 +0000
commitc63df7c64fbb1cd010e24ac4eb66b87aab8e650f (patch)
treefa398c3d1aeaf1063dc6266cedbb44b18c6669cd /src
parentc1487145493c54b41df16eb7ffe6fdd3b82e6a78 (diff)
downloadrust-c63df7c64fbb1cd010e24ac4eb66b87aab8e650f.tar.gz
rust-c63df7c64fbb1cd010e24ac4eb66b87aab8e650f.zip
Use non-short suggestion for parenthesised ..=
Diffstat (limited to 'src')
-rw-r--r--src/librustc_lint/builtin.rs28
-rw-r--r--src/test/ui/lint/inclusive-range-pattern-syntax.stderr2
-rw-r--r--src/test/ui/range/range-inclusive-pattern-precedence.stderr2
3 files changed, 19 insertions, 13 deletions
diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs
index 652de5dd120..696fee04273 100644
--- a/src/librustc_lint/builtin.rs
+++ b/src/librustc_lint/builtin.rs
@@ -1432,20 +1432,26 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
         if let Some((start, end, join)) = endpoints {
             let msg = "`...` range patterns are deprecated";
             let suggestion = "use `..=` for an inclusive range";
-            let (span, replacement) = if parenthesise {
+            if parenthesise {
                 *visit_subpats = false;
-                (pat.span, format!("&({}..={})", expr_to_string(&start), expr_to_string(&end)))
+                let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, pat.span, msg);
+                err.span_suggestion_with_applicability(
+                    pat.span,
+                    suggestion,
+                    format!("&({}..={})", expr_to_string(&start), expr_to_string(&end)),
+                    Applicability::MachineApplicable,
+                );
+                err.emit();
             } else {
-                (join, "..=".to_owned())
+                let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, join, msg);
+                err.span_suggestion_short_with_applicability(
+                    join,
+                    suggestion,
+                    "..=".to_owned(),
+                    Applicability::MachineApplicable,
+                );
+                err.emit();
             };
-            let mut err = cx.struct_span_lint(ELLIPSIS_INCLUSIVE_RANGE_PATTERNS, span, msg);
-            err.span_suggestion_short_with_applicability(
-                span,
-                suggestion,
-                replacement,
-                Applicability::MachineApplicable,
-            );
-            err.emit();
         }
     }
 }
diff --git a/src/test/ui/lint/inclusive-range-pattern-syntax.stderr b/src/test/ui/lint/inclusive-range-pattern-syntax.stderr
index 9226137f115..b13afdbc023 100644
--- a/src/test/ui/lint/inclusive-range-pattern-syntax.stderr
+++ b/src/test/ui/lint/inclusive-range-pattern-syntax.stderr
@@ -14,5 +14,5 @@ warning: `...` range patterns are deprecated
   --> $DIR/inclusive-range-pattern-syntax.rs:25:9
    |
 LL |         &1...2 => {}
-   |         ^^^^^^ help: use `..=` for an inclusive range
+   |         ^^^^^^ help: use `..=` for an inclusive range: `&(1..=2)`
 
diff --git a/src/test/ui/range/range-inclusive-pattern-precedence.stderr b/src/test/ui/range/range-inclusive-pattern-precedence.stderr
index 3ac6be2b8ea..6fa67a5d4fa 100644
--- a/src/test/ui/range/range-inclusive-pattern-precedence.stderr
+++ b/src/test/ui/range/range-inclusive-pattern-precedence.stderr
@@ -14,7 +14,7 @@ warning: `...` range patterns are deprecated
   --> $DIR/range-inclusive-pattern-precedence.rs:24:9
    |
 LL |         &0...9 => {}
-   |         ^^^^^^ help: use `..=` for an inclusive range
+   |         ^^^^^^ help: use `..=` for an inclusive range: `&(0..=9)`
    |
 note: lint level defined here
   --> $DIR/range-inclusive-pattern-precedence.rs:19:9