about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorPietro Albini <pietro@pietroalbini.org>2018-10-05 22:33:15 +0200
committerGitHub <noreply@github.com>2018-10-05 22:33:15 +0200
commitee745d6abfe1b5cb3f03505800db2cb94b6d42f9 (patch)
tree84195d420eb09e90d109f3b9576195a843decacf /src/libsyntax/parse
parent3810657ae3712e7714e3eb16b4102af318bef3b6 (diff)
parentf5db4114102861acd004c8104dde7372010b156e (diff)
downloadrust-ee745d6abfe1b5cb3f03505800db2cb94b6d42f9.tar.gz
rust-ee745d6abfe1b5cb3f03505800db2cb94b6d42f9.zip
Rollup merge of #54804 - euclio:inverted-parameters, r=estebank
add suggestion for inverted function parameters

Fixes #54065.
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/parser.rs21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 5571a18b596..1825ee6eab8 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -1777,7 +1777,26 @@ impl<'a> Parser<'a> {
                    require_name);
             let pat = self.parse_pat()?;
 
-            self.expect(&token::Colon)?;
+            if let Err(mut err) = self.expect(&token::Colon) {
+                // If we find a pattern followed by an identifier, it could be an (incorrect)
+                // C-style parameter declaration.
+                if self.check_ident() && self.look_ahead(1, |t| {
+                    *t == token::Comma || *t == token::CloseDelim(token::Paren)
+                }) {
+                    let ident = self.parse_ident().unwrap();
+                    let span = pat.span.with_hi(ident.span.hi());
+
+                    err.span_suggestion_with_applicability(
+                        span,
+                        "declare the type after the parameter binding",
+                        String::from("<identifier>: <type>"),
+                        Applicability::HasPlaceholders,
+                    );
+                }
+
+                return Err(err);
+            }
+
             (pat, self.parse_ty()?)
         } else {
             debug!("parse_arg_general ident_to_pat");