about summary refs log tree commit diff
path: root/src/librustc_parse/parser
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-01-11 11:36:39 +0000
committerbors <bors@rust-lang.org>2020-01-11 11:36:39 +0000
commitbfd04876b93ad5c013d90bc46937e28b6ee1a3f4 (patch)
treefc35ad7fae01337e6873d43c00087dd53c3992db /src/librustc_parse/parser
parent543b7d97d019bff882cc70cf2f8bdc317e7b840f (diff)
parent4eee796679bd13e0935c16f41a5e6e2ab0d5c018 (diff)
downloadrust-bfd04876b93ad5c013d90bc46937e28b6ee1a3f4.tar.gz
rust-bfd04876b93ad5c013d90bc46937e28b6ee1a3f4.zip
Auto merge of #68126 - Centril:rollup-cz5u7xx, r=Centril
Rollup of 8 pull requests

Successful merges:

 - #67756 (Collector tweaks)
 - #67889 (Compile some CGUs in parallel at the start of codegen)
 - #67930 (Rename Result::as_deref_ok to as_deref)
 - #68018 (feature_gate: Remove `GateStrength`)
 - #68070 (clean up E0185 explanation)
 - #68072 (Fix ICE #68058)
 - #68114 (Don't require `allow_internal_unstable` unless `staged_api` is enabled.)
 - #68120 (Ban `...X` pats, harden tests, and improve diagnostics)

Failed merges:

r? @ghost
Diffstat (limited to 'src/librustc_parse/parser')
-rw-r--r--src/librustc_parse/parser/expr.rs2
-rw-r--r--src/librustc_parse/parser/pat.rs26
2 files changed, 24 insertions, 4 deletions
diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs
index b0c78ad7e4b..dd2b6ab9971 100644
--- a/src/librustc_parse/parser/expr.rs
+++ b/src/librustc_parse/parser/expr.rs
@@ -1966,7 +1966,7 @@ impl<'a> Parser<'a> {
         limits: RangeLimits,
     ) -> PResult<'a, ExprKind> {
         if end.is_none() && limits == RangeLimits::Closed {
-            self.error_inclusive_range_with_no_end(self.token.span);
+            self.error_inclusive_range_with_no_end(self.prev_span);
             Ok(ExprKind::Err)
         } else {
             Ok(ExprKind::Range(start, end, limits))
diff --git a/src/librustc_parse/parser/pat.rs b/src/librustc_parse/parser/pat.rs
index 50756ddec9f..0c2cfc20daf 100644
--- a/src/librustc_parse/parser/pat.rs
+++ b/src/librustc_parse/parser/pat.rs
@@ -661,14 +661,34 @@ impl<'a> Parser<'a> {
     pub(super) fn error_inclusive_range_with_no_end(&self, span: Span) {
         use rustc_error_codes::E0586;
         struct_span_err!(self.sess.span_diagnostic, span, E0586, "inclusive range with no end")
-            .help("inclusive ranges must be bounded at the end (`..=b` or `a..=b`)")
+            .span_suggestion_short(
+                span,
+                "use `..` instead",
+                "..".to_string(),
+                Applicability::MachineApplicable,
+            )
+            .note("inclusive ranges must be bounded at the end (`..=b` or `a..=b`)")
             .emit();
     }
 
-    /// Parse a range-to pattern, e.g. `..X` and `..=X` where `X` remains to be parsed.
-    fn parse_pat_range_to(&mut self, re: Spanned<RangeEnd>) -> PResult<'a, PatKind> {
+    /// Parse a range-to pattern, `..X` or `..=X` where `X` remains to be parsed.
+    ///
+    /// The form `...X` is prohibited to reduce confusion with the potential
+    /// expression syntax `...expr` for splatting in expressions.
+    fn parse_pat_range_to(&mut self, mut re: Spanned<RangeEnd>) -> PResult<'a, PatKind> {
         let end = self.parse_pat_range_end()?;
         self.sess.gated_spans.gate(sym::half_open_range_patterns, re.span.to(self.prev_span));
+        if let RangeEnd::Included(ref mut syn @ RangeSyntax::DotDotDot) = &mut re.node {
+            *syn = RangeSyntax::DotDotEq;
+            self.struct_span_err(re.span, "range-to patterns with `...` are not allowed")
+                .span_suggestion_short(
+                    re.span,
+                    "use `..=` instead",
+                    "..=".to_string(),
+                    Applicability::MachineApplicable,
+                )
+                .emit();
+        }
         Ok(PatKind::Range(None, Some(end), re))
     }