diff options
| author | Andy Russell <arussell123@gmail.com> | 2018-10-03 22:21:05 -0400 |
|---|---|---|
| committer | Andy Russell <arussell123@gmail.com> | 2018-10-05 10:33:19 -0400 |
| commit | f5db4114102861acd004c8104dde7372010b156e (patch) | |
| tree | d172d69f72e0f9fca4a2323a5b840c281e01f57f /src/libsyntax/parse | |
| parent | 6ddab3e078bc25bd101d6885427b8a1032f8f60c (diff) | |
| download | rust-f5db4114102861acd004c8104dde7372010b156e.tar.gz rust-f5db4114102861acd004c8104dde7372010b156e.zip | |
add suggestion for inverted function parameters
Fixes #54065.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 21 |
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"); |
