]> git.lizzy.rs Git - rust.git/commitdiff
structured suggestion and rewording for `...` expression syntax error
authorZack M. Davis <code@zackmdavis.net>
Sat, 23 Jun 2018 23:49:09 +0000 (16:49 -0700)
committerZack M. Davis <code@zackmdavis.net>
Sun, 24 Jun 2018 05:57:37 +0000 (22:57 -0700)
Now that `..=` inclusive ranges are stabilized, people probably
shouldn't be using `...` even in patterns, even if it's still legal
there (see #51043). To avoid drawing attention to `...` being a real
thing, let's reword this message to just say "unexpected token" rather
"cannot be used in expressions".

src/libsyntax/parse/parser.rs
src/test/parse-fail/range_inclusive_dotdotdot.rs
src/test/ui/suggestions/dotdotdot-expr.rs [new file with mode: 0644]
src/test/ui/suggestions/dotdotdot-expr.stderr [new file with mode: 0644]

index 5970f94b97d52f12f4cfc9737033c8703900875a..955bdbdcf917765d8620b4a730070b1da4812d2e 100644 (file)
@@ -4800,12 +4800,14 @@ fn warn_missing_semicolon(&self) {
 
     fn err_dotdotdot_syntax(&self, span: Span) {
         self.diagnostic().struct_span_err(span, {
-            "`...` syntax cannot be used in expressions"
-        }).help({
-            "Use `..` if you need an exclusive range (a < b)"
-        }).help({
-            "or `..=` if you need an inclusive range (a <= b)"
-        }).emit();
+            "unexpected token: `...`"
+        }).span_suggestion_with_applicability(
+            span, "use `..` for an exclusive range", "..".to_owned(),
+            Applicability::MaybeIncorrect
+        ).span_suggestion_with_applicability(
+            span, "or `..=` for an inclusive range", "..=".to_owned(),
+            Applicability::MaybeIncorrect
+        ).emit();
     }
 
     // Parse bounds of a type parameter `BOUND + BOUND + BOUND`, possibly with trailing `+`.
index fa6474717d3f0320afbcb2663fdc1d2b2580b9b6..34b96a59c2dde784b5f7b4bc39beb0cfa63f10e2 100644 (file)
 use std::ops::RangeToInclusive;
 
 fn return_range_to() -> RangeToInclusive<i32> {
-    return ...1; //~ERROR `...` syntax cannot be used in expressions
-                 //~^HELP  Use `..` if you need an exclusive range (a < b)
-                 //~^^HELP or `..=` if you need an inclusive range (a <= b)
+    return ...1; //~ERROR unexpected token: `...`
+                 //~^HELP  use `..` for an exclusive range
+                 //~^^HELP or `..=` for an inclusive range
 }
 
 pub fn main() {
-    let x = ...0;    //~ERROR `...` syntax cannot be used in expressions
-                     //~^HELP  Use `..` if you need an exclusive range (a < b)
-                     //~^^HELP or `..=` if you need an inclusive range (a <= b)
+    let x = ...0;    //~ERROR unexpected token: `...`
+                     //~^HELP  use `..` for an exclusive range
+                     //~^^HELP or `..=` for an inclusive range
 
-    let x = 5...5;   //~ERROR `...` syntax cannot be used in expressions
-                     //~^HELP  Use `..` if you need an exclusive range (a < b)
-                     //~^^HELP or `..=` if you need an inclusive range (a <= b)
+    let x = 5...5;   //~ERROR unexpected token: `...`
+                     //~^HELP  use `..` for an exclusive range
+                     //~^^HELP or `..=` for an inclusive range
 
-    for _ in 0...1 {} //~ERROR `...` syntax cannot be used in expressions
-                     //~^HELP  Use `..` if you need an exclusive range (a < b)
-                     //~^^HELP or `..=` if you need an inclusive range (a <= b)
+    for _ in 0...1 {} //~ERROR unexpected token: `...`
+                     //~^HELP  use `..` for an exclusive range
+                     //~^^HELP or `..=` for an inclusive range
 }
-
diff --git a/src/test/ui/suggestions/dotdotdot-expr.rs b/src/test/ui/suggestions/dotdotdot-expr.rs
new file mode 100644 (file)
index 0000000..afb73a5
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+fn main() {
+    let _redemptive = 1...21;
+    //~^ ERROR unexpected token
+}
diff --git a/src/test/ui/suggestions/dotdotdot-expr.stderr b/src/test/ui/suggestions/dotdotdot-expr.stderr
new file mode 100644 (file)
index 0000000..3315538
--- /dev/null
@@ -0,0 +1,16 @@
+error: unexpected token: `...`
+  --> $DIR/dotdotdot-expr.rs:12:24
+   |
+LL |     let _redemptive = 1...21;
+   |                        ^^^
+help: use `..` for an exclusive range
+   |
+LL |     let _redemptive = 1..21;
+   |                        ^^
+help: or `..=` for an inclusive range
+   |
+LL |     let _redemptive = 1..=21;
+   |                        ^^^
+
+error: aborting due to previous error
+