diff options
| author | bors <bors@rust-lang.org> | 2018-10-06 00:44:11 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-10-06 00:44:11 +0000 |
| commit | ac841e74502183cde08e462d98cc55752abd000a (patch) | |
| tree | 5459e65f4c6e10cc9b02b1c31150fdc337f9446c /src/libsyntax/parse | |
| parent | fddcd316af98583ebebfc40f6a25bec3f4e5fccc (diff) | |
| parent | 51334c96b3810c2a4c299715fd7fe25da84146fc (diff) | |
| download | rust-ac841e74502183cde08e462d98cc55752abd000a.tar.gz rust-ac841e74502183cde08e462d98cc55752abd000a.zip | |
Auto merge of #54859 - pietroalbini:rollup, r=pietroalbini
Rollup of 11 pull requests Successful merges: - #54078 (Expand the documentation for the `std::sync` module) - #54717 (Cleanup rustc/ty part 1) - #54781 (Add examples to `TyKind::FnDef` and `TyKind::FnPtr` docs) - #54787 (Only warn about unused `mut` in user-written code) - #54804 (add suggestion for inverted function parameters) - #54812 (Regression test for #32382.) - #54833 (make `Parser::parse_foreign_item()` return a foreign item or error) - #54834 (rustdoc: overflow:auto doesn't work nicely on small screens) - #54838 (Fix typo in src/libsyntax/parse/parser.rs) - #54851 (Fix a regression in 1.30 by reverting #53564) - #54853 (Remove unneccessary error from test, revealing NLL error.) Failed merges: r? @ghost
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 5571a18b596..d653ed819fd 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"); @@ -6718,10 +6737,9 @@ impl<'a> Parser<'a> { attrs.extend(self.parse_inner_attributes()?); let mut foreign_items = vec![]; - while let Some(item) = self.parse_foreign_item()? { - foreign_items.push(item); + while !self.eat(&token::CloseDelim(token::Brace)) { + foreign_items.push(self.parse_foreign_item()?); } - self.expect(&token::CloseDelim(token::Brace))?; let prev_span = self.prev_span; let m = ast::ForeignMod { @@ -7305,8 +7323,8 @@ impl<'a> Parser<'a> { } /// Parse a foreign item. - crate fn parse_foreign_item(&mut self) -> PResult<'a, Option<ForeignItem>> { - maybe_whole!(self, NtForeignItem, |ni| Some(ni)); + crate fn parse_foreign_item(&mut self) -> PResult<'a, ForeignItem> { + maybe_whole!(self, NtForeignItem, |ni| ni); let attrs = self.parse_outer_attributes()?; let lo = self.span; @@ -7326,20 +7344,20 @@ impl<'a> Parser<'a> { ).emit(); } self.bump(); // `static` or `const` - return Ok(Some(self.parse_item_foreign_static(visibility, lo, attrs)?)); + return Ok(self.parse_item_foreign_static(visibility, lo, attrs)?); } // FOREIGN FUNCTION ITEM if self.check_keyword(keywords::Fn) { - return Ok(Some(self.parse_item_foreign_fn(visibility, lo, attrs)?)); + return Ok(self.parse_item_foreign_fn(visibility, lo, attrs)?); } // FOREIGN TYPE ITEM if self.check_keyword(keywords::Type) { - return Ok(Some(self.parse_item_foreign_type(visibility, lo, attrs)?)); + return Ok(self.parse_item_foreign_type(visibility, lo, attrs)?); } match self.parse_assoc_macro_invoc("extern", Some(&visibility), &mut false)? { Some(mac) => { - Ok(Some( + Ok( ForeignItem { ident: keywords::Invalid.ident(), span: lo.to(self.prev_span), @@ -7348,14 +7366,14 @@ impl<'a> Parser<'a> { vis: visibility, node: ForeignItemKind::Macro(mac), } - )) + ) } None => { - if !attrs.is_empty() { + if !attrs.is_empty() { self.expected_item_err(&attrs); } - Ok(None) + self.unexpected() } } } |
