diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-15 02:23:10 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-15 20:57:12 +0100 |
| commit | 35884fe16889b39d4be43cf8effc3bdf843c6f12 (patch) | |
| tree | c9d96a9b030337918d88626ee48bb3c7bebb3060 /src/librustc_parse | |
| parent | f8d2264463162291f5cb3391c98d7bc95ec17d87 (diff) | |
parse extern consts
Diffstat (limited to 'src/librustc_parse')
| -rw-r--r-- | src/librustc_parse/parser/item.rs | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index 9b7728f27d0..5fcd72090ec 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -880,19 +880,12 @@ impl<'a> Parser<'a> { } else if self.is_static_global() { // FOREIGN STATIC ITEM self.bump(); // `static` - self.parse_item_foreign_static()? - } else if self.token.is_keyword(kw::Const) { - // Treat `const` as `static` for error recovery, but don't add it to expected tokens. - self.bump(); // `const` - self.struct_span_err(self.prev_span, "extern items cannot be `const`") - .span_suggestion( - self.prev_span, - "try using a static value", - "static".to_owned(), - Applicability::MachineApplicable, - ) - .emit(); - self.parse_item_foreign_static()? + let mutbl = self.parse_mutability(); + let (ident, ty, expr) = self.parse_item_const_common(Some(mutbl))?; + (ident, ForeignItemKind::Static(ty, mutbl, expr)) + } else if self.eat_keyword(kw::Const) { + let (ident, ty, expr) = self.parse_item_const_common(None)?; + (ident, ForeignItemKind::Const(ty, expr)) } else if self.isnt_macro_invocation() { return Err(self.missing_assoc_item_kind_err("extern", self.prev_span)); } else if self.token.is_path_start() { @@ -906,14 +899,6 @@ impl<'a> Parser<'a> { Ok(P(self.mk_item(lo, ident, kind, vis, attrs))) } - /// Parses a static item from a foreign module. - /// Assumes that the `static` keyword is already parsed. - fn parse_item_foreign_static(&mut self) -> PResult<'a, (Ident, ForeignItemKind)> { - let mutbl = self.parse_mutability(); - let (ident, ty, expr) = self.parse_item_const_common(Some(mutbl))?; - Ok((ident, ForeignItemKind::Static(ty, mutbl, expr))) - } - /// Parses a type from a foreign module. fn parse_item_foreign_type(&mut self) -> PResult<'a, (Ident, ForeignItemKind)> { let (ident, kind) = self.parse_assoc_ty()?; |
