about summary refs log tree commit diff
path: root/src/librustc_parse
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-03-26 12:33:18 +0000
committerbors <bors@rust-lang.org>2020-03-26 12:33:18 +0000
commit2fbb07525e2f07a815e780a4268b11916248b5a9 (patch)
tree45d6837d752b3628506e97f0ac317a258fa3619a /src/librustc_parse
parent3b1d7351186a073c72e4be3c7d7b7ab8f1f10c58 (diff)
parent608715bbd10ec9a088d46f03db9afa689bfb3c90 (diff)
downloadrust-2fbb07525e2f07a815e780a4268b11916248b5a9.tar.gz
rust-2fbb07525e2f07a815e780a4268b11916248b5a9.zip
Auto merge of #70427 - Centril:rollup-lrcad2c, r=Centril
Rollup of 5 pull requests

Successful merges:

 - #68004 (permit negative impls for non-auto traits)
 - #70385 (Miri nits: comment and var name improvement)
 - #70411 (Fix for #62691: use the largest niche across all fields)
 - #70417 (parser: recover on `...` as a pattern, suggesting `..`)
 - #70424 (simplify match stmt)

Failed merges:

r? @ghost
Diffstat (limited to 'src/librustc_parse')
-rw-r--r--src/librustc_parse/parser/pat.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/librustc_parse/parser/pat.rs b/src/librustc_parse/parser/pat.rs
index f7f7ac89a18..983aa43916f 100644
--- a/src/librustc_parse/parser/pat.rs
+++ b/src/librustc_parse/parser/pat.rs
@@ -295,6 +295,8 @@ impl<'a> Parser<'a> {
             // A rest pattern `..`.
             self.bump(); // `..`
             PatKind::Rest
+        } else if self.check(&token::DotDotDot) && !self.is_pat_range_end_start(1) {
+            self.recover_dotdotdot_rest_pat(lo)
         } else if let Some(form) = self.parse_range_end() {
             self.parse_pat_range_to(form)? // `..=X`, `...X`, or `..X`.
         } else if self.eat_keyword(kw::Underscore) {
@@ -362,6 +364,25 @@ impl<'a> Parser<'a> {
         Ok(pat)
     }
 
+    /// Recover from a typoed `...` pattern that was encountered
+    /// Ref: Issue #70388
+    fn recover_dotdotdot_rest_pat(&mut self, lo: Span) -> PatKind {
+        // A typoed rest pattern `...`.
+        self.bump(); // `...`
+
+        // The user probably mistook `...` for a rest pattern `..`.
+        self.struct_span_err(lo, "unexpected `...`")
+            .span_label(lo, "not a valid pattern")
+            .span_suggestion_short(
+                lo,
+                "for a rest pattern, use `..` instead of `...`",
+                "..".to_owned(),
+                Applicability::MachineApplicable,
+            )
+            .emit();
+        PatKind::Rest
+    }
+
     /// Try to recover the more general form `intersect ::= $pat_lhs @ $pat_rhs`.
     ///
     /// Allowed binding patterns generated by `binding ::= ref? mut? $ident @ $pat_rhs`