diff options
Diffstat (limited to 'src/librustc_parse/parser')
| -rw-r--r-- | src/librustc_parse/parser/item.rs | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index ab915802395..9b7728f27d0 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -546,6 +546,7 @@ impl<'a> Parser<'a> { 1, &[ kw::Impl, + kw::Static, kw::Const, kw::Async, kw::Fn, @@ -670,8 +671,14 @@ impl<'a> Parser<'a> { } else if self.check_fn_front_matter() { let (ident, sig, generics, body) = self.parse_fn(at_end, &mut attrs, req_name)?; (ident, AssocItemKind::Fn(sig, generics, body)) + } else if self.is_static_global() { + self.bump(); // `static` + let mutbl = self.parse_mutability(); + let (ident, ty, expr) = self.parse_item_const_common(Some(mutbl))?; + (ident, AssocItemKind::Static(ty, mutbl, expr)) } else if self.eat_keyword(kw::Const) { - self.parse_assoc_const()? + let (ident, ty, expr) = self.parse_item_const_common(None)?; + (ident, AssocItemKind::Const(ty, expr)) } else if self.isnt_macro_invocation() { return Err(self.missing_assoc_item_kind_err("associated", self.prev_span)); } else if self.token.is_path_start() { @@ -688,15 +695,6 @@ impl<'a> Parser<'a> { Ok(AssocItem { id, span, ident, attrs, vis, defaultness, kind, tokens: None }) } - /// This parses the grammar: - /// - /// AssocConst = "const" Ident ":" Ty "=" Expr ";" - fn parse_assoc_const(&mut self) -> PResult<'a, (Ident, AssocItemKind)> { - self.expect_keyword(kw::Const)?; - let (ident, ty, expr) = self.parse_item_const_common(None)?; - Ok((ident, AssocItemKind::Const(ty, expr))) - } - /// Parses the following grammar: /// /// AssocTy = Ident ["<"...">"] [":" [GenericBounds]] ["where" ...] ["=" Ty] |
