diff options
| author | leonardo.yvens <leoyvens@gmail.com> | 2017-10-12 09:51:31 -0300 |
|---|---|---|
| committer | leonardo.yvens <leoyvens@gmail.com> | 2017-11-03 16:13:20 -0200 |
| commit | 1f4b63089927f05d2171f2b3197d74ff26e42387 (patch) | |
| tree | 6bcb85457d9083864757f91f407546a3ec863f59 /src/libsyntax/parse/parser.rs | |
| parent | 06506bb751ae952b67d76a2ebe21edb8ec96acb9 (diff) | |
| download | rust-1f4b63089927f05d2171f2b3197d74ff26e42387.tar.gz rust-1f4b63089927f05d2171f2b3197d74ff26e42387.zip | |
add `auto` keyword, parse `auto trait`, lower to HIR
Adds an `IsAuto` field to `ItemTrait` which flags if the trait was declared as an `auto trait`. Auto traits cannot have generics nor super traits.
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index fa6a3b669fa..c94fcf461c7 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -16,12 +16,13 @@ use ast::{Mod, Arg, Arm, Attribute, BindingMode, TraitItemKind}; use ast::Block; use ast::{BlockCheckMode, CaptureBy}; use ast::{Constness, Crate}; +use ast::Generics; use ast::Defaultness; use ast::EnumDef; use ast::{Expr, ExprKind, RangeLimits}; use ast::{Field, FnDecl}; use ast::{ForeignItem, ForeignItemKind, FunctionRetTy}; -use ast::{Ident, ImplItem, Item, ItemKind}; +use ast::{Ident, ImplItem, IsAuto, Item, ItemKind}; use ast::{Lifetime, LifetimeDef, Lit, LitKind, UintTy}; use ast::Local; use ast::MacStmtStyle; @@ -5078,7 +5079,17 @@ impl<'a> Parser<'a> { } } } - Ok((ident, ItemKind::Trait(unsafety, tps, bounds, trait_items), None)) + Ok((ident, ItemKind::Trait(IsAuto::No, unsafety, tps, bounds, trait_items), None)) + } + + fn parse_item_auto_trait(&mut self, unsafety: Unsafety) -> PResult<'a, ItemInfo> { + let ident = self.parse_ident()?; + self.expect(&token::OpenDelim(token::Brace))?; + self.expect(&token::CloseDelim(token::Brace))?; + // Auto traits cannot have generics, super traits nor contain items. + Ok((ident, + ItemKind::Trait(IsAuto::Yes, unsafety, Generics::default(), Vec::new(), Vec::new()), + None)) } /// Parses items implementations variants @@ -6127,6 +6138,37 @@ impl<'a> Parser<'a> { maybe_append(attrs, extra_attrs)); return Ok(Some(item)); } + if self.eat_keyword(keywords::Auto) { + self.expect_keyword(keywords::Trait)?; + // AUTO TRAIT ITEM + let (ident, + item_, + extra_attrs) = self.parse_item_auto_trait(ast::Unsafety::Normal)?; + let prev_span = self.prev_span; + let item = self.mk_item(lo.to(prev_span), + ident, + item_, + visibility, + maybe_append(attrs, extra_attrs)); + return Ok(Some(item)); + } + if self.check_keyword(keywords::Unsafe) && + self.look_ahead(1, |t| t.is_keyword(keywords::Auto)) { + self.expect_keyword(keywords::Unsafe)?; + self.expect_keyword(keywords::Auto)?; + self.expect_keyword(keywords::Trait)?; + // UNSAFE AUTO TRAIT ITEM + let (ident, + item_, + extra_attrs) = self.parse_item_auto_trait(ast::Unsafety::Unsafe)?; + let prev_span = self.prev_span; + let item = self.mk_item(lo.to(prev_span), + ident, + item_, + visibility, + maybe_append(attrs, extra_attrs)); + return Ok(Some(item)); + } if self.eat_keyword(keywords::Struct) { // STRUCT ITEM let (ident, item_, extra_attrs) = self.parse_item_struct()?; |
