diff options
| author | bors <bors@rust-lang.org> | 2016-02-11 12:52:42 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-02-11 12:52:42 +0000 |
| commit | 7732c0aa9ea12262cbe46fa77c2fa636e8aecf6a (patch) | |
| tree | 8d0364921d0d70e6fdc67176297a1f1ee3e5070e /src/libsyntax | |
| parent | f5f8e0bfbeee2abc425f26a3ad36430f23010e69 (diff) | |
| parent | bafea3bf78e75c99958ef15fd3d06652cb63133c (diff) | |
| download | rust-7732c0aa9ea12262cbe46fa77c2fa636e8aecf6a.tar.gz rust-7732c0aa9ea12262cbe46fa77c2fa636e8aecf6a.zip | |
Auto merge of #31487 - oli-obk:breaking_batch/ast/unop, r=Manishearth
r? @Manishearth I just noticed they can't be rolled up (often modifying the same line(s) in imports). So once I reach the critical amount for them to be merged I'll create a PR that merges all of them.
Diffstat (limited to 'src/libsyntax')
28 files changed, 1446 insertions, 1508 deletions
diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index 0df143c45ae..c959e2108f5 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -8,27 +8,23 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -pub use self::Os::*; -pub use self::Abi::*; -pub use self::Architecture::*; -pub use self::AbiArchitecture::*; - use std::fmt; #[derive(Copy, Clone, PartialEq, Eq, Debug)] +#[allow(non_camel_case_types)] pub enum Os { - OsWindows, - OsMacos, - OsLinux, - OsAndroid, - OsFreebsd, - OsiOS, - OsDragonfly, - OsBitrig, - OsNetbsd, - OsOpenbsd, - OsNaCl, - OsSolaris, + Windows, + Macos, + Linux, + Android, + Freebsd, + iOS, + Dragonfly, + Bitrig, + Netbsd, + Openbsd, + NaCl, + Solaris, } #[derive(PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Clone, Copy, Debug)] @@ -74,9 +70,9 @@ pub struct AbiData { #[derive(Copy, Clone)] pub enum AbiArchitecture { /// Not a real ABI (e.g., intrinsic) - RustArch, + Rust, /// An ABI that specifies cross-platform defaults (e.g., "C") - AllArch, + All, /// Multiple architectures (bitset) Archs(u32) } @@ -84,23 +80,23 @@ pub enum AbiArchitecture { #[allow(non_upper_case_globals)] const AbiDatas: &'static [AbiData] = &[ // Platform-specific ABIs - AbiData {abi: Cdecl, name: "cdecl" }, - AbiData {abi: Stdcall, name: "stdcall" }, - AbiData {abi: Fastcall, name: "fastcall" }, - AbiData {abi: Vectorcall, name: "vectorcall"}, - AbiData {abi: Aapcs, name: "aapcs" }, - AbiData {abi: Win64, name: "win64" }, + AbiData {abi: Abi::Cdecl, name: "cdecl" }, + AbiData {abi: Abi::Stdcall, name: "stdcall" }, + AbiData {abi: Abi::Fastcall, name: "fastcall" }, + AbiData {abi: Abi::Vectorcall, name: "vectorcall"}, + AbiData {abi: Abi::Aapcs, name: "aapcs" }, + AbiData {abi: Abi::Win64, name: "win64" }, // Cross-platform ABIs // // NB: Do not adjust this ordering without // adjusting the indices below. - AbiData {abi: Rust, name: "Rust" }, - AbiData {abi: C, name: "C" }, - AbiData {abi: System, name: "system" }, - AbiData {abi: RustIntrinsic, name: "rust-intrinsic" }, - AbiData {abi: RustCall, name: "rust-call" }, - AbiData {abi: PlatformIntrinsic, name: "platform-intrinsic" } + AbiData {abi: Abi::Rust, name: "Rust" }, + AbiData {abi: Abi::C, name: "C" }, + AbiData {abi: Abi::System, name: "system" }, + AbiData {abi: Abi::RustIntrinsic, name: "rust-intrinsic" }, + AbiData {abi: Abi::RustCall, name: "rust-call" }, + AbiData {abi: Abi::PlatformIntrinsic, name: "platform-intrinsic" } ]; /// Returns the ABI with the given name (if any). @@ -137,18 +133,18 @@ impl fmt::Display for Abi { impl fmt::Display for Os { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - OsLinux => "linux".fmt(f), - OsWindows => "windows".fmt(f), - OsMacos => "macos".fmt(f), - OsiOS => "ios".fmt(f), - OsAndroid => "android".fmt(f), - OsFreebsd => "freebsd".fmt(f), - OsDragonfly => "dragonfly".fmt(f), - OsBitrig => "bitrig".fmt(f), - OsNetbsd => "netbsd".fmt(f), - OsOpenbsd => "openbsd".fmt(f), - OsNaCl => "nacl".fmt(f), - OsSolaris => "solaris".fmt(f), + Os::Linux => "linux".fmt(f), + Os::Windows => "windows".fmt(f), + Os::Macos => "macos".fmt(f), + Os::iOS => "ios".fmt(f), + Os::Android => "android".fmt(f), + Os::Freebsd => "freebsd".fmt(f), + Os::Dragonfly => "dragonfly".fmt(f), + Os::Bitrig => "bitrig".fmt(f), + Os::Netbsd => "netbsd".fmt(f), + Os::Openbsd => "openbsd".fmt(f), + Os::NaCl => "nacl".fmt(f), + Os::Solaris => "solaris".fmt(f), } } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 088f911ed8c..bae6d780b5e 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,38 +10,11 @@ // The Rust abstract syntax tree. -pub use self::BinOp_::*; -pub use self::BlockCheckMode::*; -pub use self::CaptureClause::*; -pub use self::Decl_::*; -pub use self::ExplicitSelf_::*; -pub use self::Expr_::*; -pub use self::FloatTy::*; -pub use self::FunctionRetTy::*; -pub use self::ForeignItem_::*; -pub use self::IntTy::*; -pub use self::Item_::*; -pub use self::KleeneOp::*; -pub use self::Lit_::*; -pub use self::LitIntType::*; -pub use self::MacStmtStyle::*; -pub use self::MetaItem_::*; -pub use self::Mutability::*; pub use self::Pat_::*; -pub use self::PathListItem_::*; -pub use self::PrimTy::*; -pub use self::Sign::*; -pub use self::Stmt_::*; -pub use self::StrStyle::*; pub use self::StructFieldKind::*; -pub use self::TraitItem_::*; -pub use self::Ty_::*; pub use self::TyParamBound::*; -pub use self::UintTy::*; -pub use self::UnOp::*; pub use self::UnsafeSource::*; pub use self::ViewPath_::*; -pub use self::Visibility::*; pub use self::PathParameters::*; use attr::ThinAttributes; @@ -497,31 +470,32 @@ pub struct Crate { pub exported_macros: Vec<MacroDef>, } -pub type MetaItem = Spanned<MetaItem_>; +pub type MetaItem = Spanned<MetaItemKind>; #[derive(Clone, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum MetaItem_ { - MetaWord(InternedString), - MetaList(InternedString, Vec<P<MetaItem>>), - MetaNameValue(InternedString, Lit), +pub enum MetaItemKind { + Word(InternedString), + List(InternedString, Vec<P<MetaItem>>), + NameValue(InternedString, Lit), } -// can't be derived because the MetaList requires an unordered comparison -impl PartialEq for MetaItem_ { - fn eq(&self, other: &MetaItem_) -> bool { +// can't be derived because the MetaItemKind::List requires an unordered comparison +impl PartialEq for MetaItemKind { + fn eq(&self, other: &MetaItemKind) -> bool { + use self::MetaItemKind::*; match *self { - MetaWord(ref ns) => match *other { - MetaWord(ref no) => (*ns) == (*no), + Word(ref ns) => match *other { + Word(ref no) => (*ns) == (*no), _ => false }, - MetaNameValue(ref ns, ref vs) => match *other { - MetaNameValue(ref no, ref vo) => { + NameValue(ref ns, ref vs) => match *other { + NameValue(ref no, ref vo) => { (*ns) == (*no) && vs.node == vo.node } _ => false }, - MetaList(ref ns, ref miss) => match *other { - MetaList(ref no, ref miso) => { + List(ref ns, ref miss) => match *other { + List(ref no, ref miso) => { ns == no && miss.iter().all(|mi| miso.iter().any(|x| x.node == mi.node)) } @@ -623,133 +597,135 @@ pub enum Pat_ { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub enum Mutability { - MutMutable, - MutImmutable, + Mutable, + Immutable, } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] -pub enum BinOp_ { +pub enum BinOpKind { /// The `+` operator (addition) - BiAdd, + Add, /// The `-` operator (subtraction) - BiSub, + Sub, /// The `*` operator (multiplication) - BiMul, + Mul, /// The `/` operator (division) - BiDiv, + Div, /// The `%` operator (modulus) - BiRem, + Rem, /// The `&&` operator (logical and) - BiAnd, + And, /// The `||` operator (logical or) - BiOr, + Or, /// The `^` operator (bitwise xor) - BiBitXor, + BitXor, /// The `&` operator (bitwise and) - BiBitAnd, + BitAnd, /// The `|` operator (bitwise or) - BiBitOr, + BitOr, /// The `<<` operator (shift left) - BiShl, + Shl, /// The `>>` operator (shift right) - BiShr, + Shr, /// The `==` operator (equality) - BiEq, + Eq, /// The `<` operator (less than) - BiLt, + Lt, /// The `<=` operator (less than or equal to) - BiLe, + Le, /// The `!=` operator (not equal to) - BiNe, + Ne, /// The `>=` operator (greater than or equal to) - BiGe, + Ge, /// The `>` operator (greater than) - BiGt, + Gt, } -impl BinOp_ { +impl BinOpKind { pub fn to_string(&self) -> &'static str { + use self::BinOpKind::*; match *self { - BiAdd => "+", - BiSub => "-", - BiMul => "*", - BiDiv => "/", - BiRem => "%", - BiAnd => "&&", - BiOr => "||", - BiBitXor => "^", - BiBitAnd => "&", - BiBitOr => "|", - BiShl => "<<", - BiShr => ">>", - BiEq => "==", - BiLt => "<", - BiLe => "<=", - BiNe => "!=", - BiGe => ">=", - BiGt => ">" + Add => "+", + Sub => "-", + Mul => "*", + Div => "/", + Rem => "%", + And => "&&", + Or => "||", + BitXor => "^", + BitAnd => "&", + BitOr => "|", + Shl => "<<", + Shr => ">>", + Eq => "==", + Lt => "<", + Le => "<=", + Ne => "!=", + Ge => ">=", + Gt => ">", } } pub fn lazy(&self) -> bool { match *self { - BiAnd | BiOr => true, + BinOpKind::And | BinOpKind::Or => true, _ => false } } pub fn is_shift(&self) -> bool { match *self { - BiShl | BiShr => true, + BinOpKind::Shl | BinOpKind::Shr => true, _ => false } } pub fn is_comparison(&self) -> bool { + use self::BinOpKind::*; match *self { - BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => + Eq | Lt | Le | Ne | Gt | Ge => true, - BiAnd | BiOr | BiAdd | BiSub | BiMul | BiDiv | BiRem | - BiBitXor | BiBitAnd | BiBitOr | BiShl | BiShr => + And | Or | Add | Sub | Mul | Div | Rem | + BitXor | BitAnd | BitOr | Shl | Shr => false, } } /// Returns `true` if the binary operator takes its arguments by value pub fn is_by_value(&self) -> bool { - !BinOp_::is_comparison(self) + !self.is_comparison() } } -pub type BinOp = Spanned<BinOp_>; +pub type BinOp = Spanned<BinOpKind>; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub enum UnOp { /// The `*` operator for dereferencing - UnDeref, + Deref, /// The `!` operator for logical inversion - UnNot, + Not, /// The `-` operator for negation - UnNeg + Neg, } impl UnOp { /// Returns `true` if the unary operator takes its argument by value pub fn is_by_value(u: UnOp) -> bool { match u { - UnNeg | UnNot => true, + UnOp::Neg | UnOp::Not => true, _ => false, } } pub fn to_string(op: UnOp) -> &'static str { match op { - UnDeref => "*", - UnNot => "!", - UnNeg => "-", + UnOp::Deref => "*", + UnOp::Not => "!", + UnOp::Neg => "-", } } } /// A statement -pub type Stmt = Spanned<Stmt_>; +pub type Stmt = Spanned<StmtKind>; impl fmt::Debug for Stmt { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -762,36 +738,36 @@ impl fmt::Debug for Stmt { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)] -pub enum Stmt_ { +pub enum StmtKind { /// Could be an item or a local (let) binding: - StmtDecl(P<Decl>, NodeId), + Decl(P<Decl>, NodeId), /// Expr without trailing semi-colon (must have unit type): - StmtExpr(P<Expr>, NodeId), + Expr(P<Expr>, NodeId), /// Expr with trailing semi-colon (may have any type): - StmtSemi(P<Expr>, NodeId), + Semi(P<Expr>, NodeId), - StmtMac(P<Mac>, MacStmtStyle, ThinAttributes), + Mac(P<Mac>, MacStmtStyle, ThinAttributes), } -impl Stmt_ { +impl StmtKind { pub fn id(&self) -> Option<NodeId> { match *self { - StmtDecl(_, id) => Some(id), - StmtExpr(_, id) => Some(id), - StmtSemi(_, id) => Some(id), - StmtMac(..) => None, + StmtKind::Decl(_, id) => Some(id), + StmtKind::Expr(_, id) => Some(id), + StmtKind::Semi(_, id) => Some(id), + StmtKind::Mac(..) => None, } } pub fn attrs(&self) -> &[Attribute] { match *self { - StmtDecl(ref d, _) => d.attrs(), - StmtExpr(ref e, _) | - StmtSemi(ref e, _) => e.attrs(), - StmtMac(_, _, Some(ref b)) => b, - StmtMac(_, _, None) => &[], + StmtKind::Decl(ref d, _) => d.attrs(), + StmtKind::Expr(ref e, _) | + StmtKind::Semi(ref e, _) => e.attrs(), + StmtKind::Mac(_, _, Some(ref b)) => b, + StmtKind::Mac(_, _, None) => &[], } } } @@ -800,13 +776,13 @@ impl Stmt_ { pub enum MacStmtStyle { /// The macro statement had a trailing semicolon, e.g. `foo! { ... };` /// `foo!(...);`, `foo![...];` - MacStmtWithSemicolon, + Semicolon, /// The macro statement had braces; e.g. foo! { ... } - MacStmtWithBraces, + Braces, /// The macro statement had parentheses or brackets and no semicolon; e.g. /// `foo!(...)`. All of these will end up being converted into macro /// expressions. - MacStmtWithoutBraces, + NoBraces, } // FIXME (pending discussion of #1697, #2178...): local should really be @@ -832,21 +808,21 @@ impl Local { } } -pub type Decl = Spanned<Decl_>; +pub type Decl = Spanned<DeclKind>; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum Decl_ { +pub enum DeclKind { /// A local (let) binding: - DeclLocal(P<Local>), + Local(P<Local>), /// An item binding: - DeclItem(P<Item>), + Item(P<Item>), } impl Decl { pub fn attrs(&self) -> &[Attribute] { match self.node { - DeclLocal(ref l) => l.attrs(), - DeclItem(ref i) => i.attrs(), + DeclKind::Local(ref l) => l.attrs(), + DeclKind::Item(ref i) => i.attrs(), } } } @@ -871,8 +847,8 @@ pub type SpannedIdent = Spanned<Ident>; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub enum BlockCheckMode { - DefaultBlock, - UnsafeBlock(UnsafeSource), + Default, + Unsafe(UnsafeSource), } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] @@ -885,7 +861,7 @@ pub enum UnsafeSource { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash,)] pub struct Expr { pub id: NodeId, - pub node: Expr_, + pub node: ExprKind, pub span: Span, pub attrs: ThinAttributes } @@ -906,18 +882,18 @@ impl fmt::Debug for Expr { } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum Expr_ { +pub enum ExprKind { /// A `box x` expression. - ExprBox(P<Expr>), + Box(P<Expr>), /// First expr is the place; second expr is the value. - ExprInPlace(P<Expr>, P<Expr>), + InPlace(P<Expr>, P<Expr>), /// An array (`[a, b, c, d]`) - ExprVec(Vec<P<Expr>>), + Vec(Vec<P<Expr>>), /// A function call /// /// The first field resolves to the function itself, /// and the second field is the list of arguments - ExprCall(P<Expr>, Vec<P<Expr>>), + Call(P<Expr>, Vec<P<Expr>>), /// A method call (`x.foo::<Bar, Baz>(a, b, c, d)`) /// /// The `SpannedIdent` is the identifier for the method name. @@ -929,109 +905,109 @@ pub enum Expr_ { /// and the remaining elements are the rest of the arguments. /// /// Thus, `x.foo::<Bar, Baz>(a, b, c, d)` is represented as - /// `ExprMethodCall(foo, [Bar, Baz], [x, a, b, c, d])`. - ExprMethodCall(SpannedIdent, Vec<P<Ty>>, Vec<P<Expr>>), + /// `ExprKind::MethodCall(foo, [Bar, Baz], [x, a, b, c, d])`. + MethodCall(SpannedIdent, Vec<P<Ty>>, Vec<P<Expr>>), /// A tuple (`(a, b, c ,d)`) - ExprTup(Vec<P<Expr>>), + Tup(Vec<P<Expr>>), /// A binary operation (For example: `a + b`, `a * b`) - ExprBinary(BinOp, P<Expr>, P<Expr>), + Binary(BinOp, P<Expr>, P<Expr>), /// A unary operation (For example: `!x`, `*x`) - ExprUnary(UnOp, P<Expr>), + Unary(UnOp, P<Expr>), /// A literal (For example: `1u8`, `"foo"`) - ExprLit(P<Lit>), + Lit(P<Lit>), /// A cast (`foo as f64`) - ExprCast(P<Expr>, P<Ty>), - ExprType(P<Expr>, P<Ty>), + Cast(P<Expr>, P<Ty>), + Type(P<Expr>, P<Ty>), /// An `if` block, with an optional else block /// /// `if expr { block } else { expr }` - ExprIf(P<Expr>, P<Block>, Option<P<Expr>>), + If(P<Expr>, P<Block>, Option<P<Expr>>), /// An `if let` expression with an optional else block /// /// `if let pat = expr { block } else { expr }` /// /// This is desugared to a `match` expression. - ExprIfLet(P<Pat>, P<Expr>, P<Block>, Option<P<Expr>>), + IfLet(P<Pat>, P<Expr>, P<Block>, Option<P<Expr>>), /// A while loop, with an optional label /// /// `'label: while expr { block }` - ExprWhile(P<Expr>, P<Block>, Option<Ident>), + While(P<Expr>, P<Block>, Option<Ident>), /// A while-let loop, with an optional label /// /// `'label: while let pat = expr { block }` /// /// This is desugared to a combination of `loop` and `match` expressions. - ExprWhileLet(P<Pat>, P<Expr>, P<Block>, Option<Ident>), + WhileLet(P<Pat>, P<Expr>, P<Block>, Option<Ident>), /// A for loop, with an optional label /// /// `'label: for pat in expr { block }` /// /// This is desugared to a combination of `loop` and `match` expressions. - ExprForLoop(P<Pat>, P<Expr>, P<Block>, Option<Ident>), + ForLoop(P<Pat>, P<Expr>, P<Block>, Option<Ident>), /// Conditionless loop (can be exited with break, continue, or return) /// /// `'label: loop { block }` - ExprLoop(P<Block>, Option<Ident>), + Loop(P<Block>, Option<Ident>), /// A `match` block. - ExprMatch(P<Expr>, Vec<Arm>), + Match(P<Expr>, Vec<Arm>), /// A closure (for example, `move |a, b, c| {a + b + c}`) - ExprClosure(CaptureClause, P<FnDecl>, P<Block>), + Closure(CaptureBy, P<FnDecl>, P<Block>), /// A block (`{ ... }`) - ExprBlock(P<Block>), + Block(P<Block>), /// An assignment (`a = foo()`) - ExprAssign(P<Expr>, P<Expr>), + Assign(P<Expr>, P<Expr>), /// An assignment with an operator /// /// For example, `a += 1`. - ExprAssignOp(BinOp, P<Expr>, P<Expr>), + AssignOp(BinOp, P<Expr>, P<Expr>), /// Access of a named struct field (`obj.foo`) - ExprField(P<Expr>, SpannedIdent), + Field(P<Expr>, SpannedIdent), /// Access of an unnamed field of a struct or tuple-struct /// /// For example, `foo.0`. - ExprTupField(P<Expr>, Spanned<usize>), + TupField(P<Expr>, Spanned<usize>), /// An indexing operation (`foo[2]`) - ExprIndex(P<Expr>, P<Expr>), + Index(P<Expr>, P<Expr>), /// A range (`1..2`, `1..`, or `..2`) - ExprRange(Option<P<Expr>>, Option<P<Expr>>), + Range(Option<P<Expr>>, Option<P<Expr>>), /// Variable reference, possibly containing `::` and/or type /// parameters, e.g. foo::bar::<baz>. /// /// Optionally "qualified", /// e.g. `<Vec<T> as SomeTrait>::SomeType`. - ExprPath(Option<QSelf>, Path), + Path(Option<QSelf>, Path), /// A referencing operation (`&a` or `&mut a`) - ExprAddrOf(Mutability, P<Expr>), + AddrOf(Mutability, P<Expr>), /// A `break`, with an optional label to break - ExprBreak(Option<SpannedIdent>), + Break(Option<SpannedIdent>), /// A `continue`, with an optional label - ExprAgain(Option<SpannedIdent>), + Again(Option<SpannedIdent>), /// A `return`, with an optional value to be returned - ExprRet(Option<P<Expr>>), + Ret(Option<P<Expr>>), /// Output of the `asm!()` macro - ExprInlineAsm(InlineAsm), + InlineAsm(InlineAsm), /// A macro invocation; pre-expansion - ExprMac(Mac), + Mac(Mac), /// A struct literal expression. /// /// For example, `Foo {x: 1, y: 2}`, or /// `Foo {x: 1, .. base}`, where `base` is the `Option<Expr>`. - ExprStruct(Path, Vec<Field>, Option<P<Expr>>), + Struct(Path, Vec<Field>, Option<P<Expr>>), /// An array literal constructed from one repeated element. /// /// For example, `[1u8; 5]`. The first expression is the element /// to be repeated; the second is the number of times to repeat it. - ExprRepeat(P<Expr>, P<Expr>), + Repeat(P<Expr>, P<Expr>), /// No-op: used solely so we can pretty-print faithfully - ExprParen(P<Expr>) + Paren(P<Expr>), } /// The explicit Self type in a "qualified path". The actual @@ -1054,10 +1030,11 @@ pub struct QSelf { pub position: usize } +/// A capture clause #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] -pub enum CaptureClause { - CaptureByValue, - CaptureByRef, +pub enum CaptureBy { + Value, + Ref, } /// A delimited sequence of token trees @@ -1267,73 +1244,48 @@ pub struct Mac_ { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub enum StrStyle { /// A regular string, like `"foo"` - CookedStr, + Cooked, /// A raw string, like `r##"foo"##` /// /// The uint is the number of `#` symbols used - RawStr(usize) + Raw(usize) } /// A literal -pub type Lit = Spanned<Lit_>; - -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] -pub enum Sign { - Minus, - Plus -} - -impl Sign { - pub fn new<T: IntSign>(n: T) -> Sign { - n.sign() - } -} - -pub trait IntSign { - fn sign(&self) -> Sign; -} -macro_rules! doit { - ($($t:ident)*) => ($(impl IntSign for $t { - #[allow(unused_comparisons)] - fn sign(&self) -> Sign { - if *self < 0 {Minus} else {Plus} - } - })*) -} -doit! { i8 i16 i32 i64 isize u8 u16 u32 u64 usize } +pub type Lit = Spanned<LitKind>; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub enum LitIntType { - SignedIntLit(IntTy, Sign), - UnsignedIntLit(UintTy), - UnsuffixedIntLit(Sign) + Signed(IntTy), + Unsigned(UintTy), + Unsuffixed, } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum Lit_ { +pub enum LitKind { /// A string literal (`"foo"`) - LitStr(InternedString, StrStyle), + Str(InternedString, StrStyle), /// A byte string (`b"foo"`) - LitByteStr(Rc<Vec<u8>>), + ByteStr(Rc<Vec<u8>>), /// A byte char (`b'f'`) - LitByte(u8), + Byte(u8), /// A character literal (`'a'`) - LitChar(char), + Char(char), /// An integer literal (`1u8`) - LitInt(u64, LitIntType), + Int(u64, LitIntType), /// A float literal (`1f64` or `1E10f64`) - LitFloat(InternedString, FloatTy), + Float(InternedString, FloatTy), /// A float literal without a suffix (`1.0 or 1.0E10`) - LitFloatUnsuffixed(InternedString), + FloatUnsuffixed(InternedString), /// A boolean literal - LitBool(bool), + Bool(bool), } -impl Lit_ { +impl LitKind { /// Returns true if this literal is a string and false otherwise. pub fn is_str(&self) -> bool { match *self { - LitStr(..) => true, + LitKind::Str(..) => true, _ => false, } } @@ -1368,15 +1320,15 @@ pub struct TraitItem { pub id: NodeId, pub ident: Ident, pub attrs: Vec<Attribute>, - pub node: TraitItem_, + pub node: TraitItemKind, pub span: Span, } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum TraitItem_ { - ConstTraitItem(P<Ty>, Option<P<Expr>>), - MethodTraitItem(MethodSig, Option<P<Block>>), - TypeTraitItem(TyParamBounds, Option<P<Ty>>), +pub enum TraitItemKind { + Const(P<Ty>, Option<P<Expr>>), + Method(MethodSig, Option<P<Block>>), + Type(TyParamBounds, Option<P<Ty>>), } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] @@ -1399,11 +1351,11 @@ pub enum ImplItemKind { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] pub enum IntTy { - TyIs, - TyI8, - TyI16, - TyI32, - TyI64, + Is, + I8, + I16, + I32, + I64, } impl fmt::Debug for IntTy { @@ -1421,11 +1373,11 @@ impl fmt::Display for IntTy { impl IntTy { pub fn ty_to_string(&self) -> &'static str { match *self { - TyIs => "isize", - TyI8 => "i8", - TyI16 => "i16", - TyI32 => "i32", - TyI64 => "i64" + IntTy::Is => "isize", + IntTy::I8 => "i8", + IntTy::I16 => "i16", + IntTy::I32 => "i32", + IntTy::I64 => "i64" } } @@ -1438,41 +1390,41 @@ impl IntTy { pub fn ty_max(&self) -> u64 { match *self { - TyI8 => 0x80, - TyI16 => 0x8000, - TyIs | TyI32 => 0x80000000, // actually ni about TyIs - TyI64 => 0x8000000000000000 + IntTy::I8 => 0x80, + IntTy::I16 => 0x8000, + IntTy::Is | IntTy::I32 => 0x80000000, // FIXME: actually ni about Is + IntTy::I64 => 0x8000000000000000 } } pub fn bit_width(&self) -> Option<usize> { Some(match *self { - TyIs => return None, - TyI8 => 8, - TyI16 => 16, - TyI32 => 32, - TyI64 => 64, + IntTy::Is => return None, + IntTy::I8 => 8, + IntTy::I16 => 16, + IntTy::I32 => 32, + IntTy::I64 => 64, }) } } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] pub enum UintTy { - TyUs, - TyU8, - TyU16, - TyU32, - TyU64, + Us, + U8, + U16, + U32, + U64, } impl UintTy { pub fn ty_to_string(&self) -> &'static str { match *self { - TyUs => "usize", - TyU8 => "u8", - TyU16 => "u16", - TyU32 => "u32", - TyU64 => "u64" + UintTy::Us => "usize", + UintTy::U8 => "u8", + UintTy::U16 => "u16", + UintTy::U32 => "u32", + UintTy::U64 => "u64" } } @@ -1482,20 +1434,20 @@ impl UintTy { pub fn ty_max(&self) -> u64 { match *self { - TyU8 => 0xff, - TyU16 => 0xffff, - TyUs | TyU32 => 0xffffffff, // actually ni about TyUs - TyU64 => 0xffffffffffffffff + UintTy::U8 => 0xff, + UintTy::U16 => 0xffff, + UintTy::Us | UintTy::U32 => 0xffffffff, // FIXME: actually ni about Us + UintTy::U64 => 0xffffffffffffffff } } pub fn bit_width(&self) -> Option<usize> { Some(match *self { - TyUs => return None, - TyU8 => 8, - TyU16 => 16, - TyU32 => 32, - TyU64 => 64, + UintTy::Us => return None, + UintTy::U8 => 8, + UintTy::U16 => 16, + UintTy::U32 => 32, + UintTy::U64 => 64, }) } } @@ -1514,8 +1466,8 @@ impl fmt::Display for UintTy { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] pub enum FloatTy { - TyF32, - TyF64, + F32, + F64, } impl fmt::Debug for FloatTy { @@ -1533,15 +1485,15 @@ impl fmt::Display for FloatTy { impl FloatTy { pub fn ty_to_string(&self) -> &'static str { match *self { - TyF32 => "f32", - TyF64 => "f64", + FloatTy::F32 => "f32", + FloatTy::F64 => "f64", } } pub fn bit_width(&self) -> usize { match *self { - TyF32 => 32, - TyF64 => 64, + FloatTy::F32 => 32, + FloatTy::F64 => 64, } } } @@ -1558,7 +1510,7 @@ pub struct TypeBinding { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)] pub struct Ty { pub id: NodeId, - pub node: Ty_, + pub node: TyKind, pub span: Span, } @@ -1568,17 +1520,6 @@ impl fmt::Debug for Ty { } } -/// Not represented directly in the AST, referred to by name through a ty_path. -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] -pub enum PrimTy { - TyInt(IntTy), - TyUint(UintTy), - TyFloat(FloatTy), - TyStr, - TyBool, - TyChar -} - #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct BareFnTy { pub unsafety: Unsafety, @@ -1589,36 +1530,36 @@ pub struct BareFnTy { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] /// The different kinds of types recognized by the compiler -pub enum Ty_ { - TyVec(P<Ty>), +pub enum TyKind { + Vec(P<Ty>), /// A fixed length array (`[T; n]`) - TyFixedLengthVec(P<Ty>, P<Expr>), + FixedLengthVec(P<Ty>, P<Expr>), /// A raw pointer (`*const T` or `*mut T`) - TyPtr(MutTy), + Ptr(MutTy), /// A reference (`&'a T` or `&'a mut T`) - TyRptr(Option<Lifetime>, MutTy), + Rptr(Option<Lifetime>, MutTy), /// A bare function (e.g. `fn(usize) -> bool`) - TyBareFn(P<BareFnTy>), + BareFn(P<BareFnTy>), /// A tuple (`(A, B, C, D,...)`) - TyTup(Vec<P<Ty>> ), + Tup(Vec<P<Ty>> ), /// A path (`module::module::...::Type`), optionally /// "qualified", e.g. `<Vec<T> as SomeTrait>::SomeType`. /// /// Type parameters are stored in the Path itself - TyPath(Option<QSelf>, Path), + Path(Option<QSelf>, Path), /// Something like `A+B`. Note that `B` must always be a path. - TyObjectSum(P<Ty>, TyParamBounds), + ObjectSum(P<Ty>, TyParamBounds), /// A type like `for<'a> Foo<&'a Bar>` - TyPolyTraitRef(TyParamBounds), + PolyTraitRef(TyParamBounds), /// No-op; kept solely so that we can pretty-print faithfully - TyParen(P<Ty>), + Paren(P<Ty>), /// Unused for now - TyTypeof(P<Expr>), - /// TyInfer means the type should be inferred instead of it having been + Typeof(P<Expr>), + /// TyKind::Infer means the type should be inferred instead of it having been /// specified. This can appear anywhere in a type. - TyInfer, + Infer, // A macro in the type position. - TyMac(Mac) + Mac(Mac), } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] @@ -1663,7 +1604,7 @@ impl Arg { // HACK(eddyb) fake type for the self argument. ty: P(Ty { id: DUMMY_NODE_ID, - node: TyInfer, + node: TyKind::Infer, span: DUMMY_SP, }), pat: P(Pat { @@ -1727,41 +1668,41 @@ impl fmt::Debug for ImplPolarity { pub enum FunctionRetTy { /// Functions with return type `!`that always /// raise an error or exit (i.e. never return to the caller) - NoReturn(Span), + None(Span), /// Return type is not specified. /// /// Functions default to `()` and /// closures default to inference. Span points to where return /// type would be inserted. - DefaultReturn(Span), + Default(Span), /// Everything else - Return(P<Ty>), + Ty(P<Ty>), } impl FunctionRetTy { pub fn span(&self) -> Span { match *self { - NoReturn(span) => span, - DefaultReturn(span) => span, - Return(ref ty) => ty.span + FunctionRetTy::None(span) => span, + FunctionRetTy::Default(span) => span, + FunctionRetTy::Ty(ref ty) => ty.span, } } } /// Represents the kind of 'self' associated with a method #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum ExplicitSelf_ { +pub enum SelfKind { /// No self - SelfStatic, + Static, /// `self` - SelfValue(Ident), + Value(Ident), /// `&'lt self`, `&'lt mut self` - SelfRegion(Option<Lifetime>, Mutability, Ident), + Region(Option<Lifetime>, Mutability, Ident), /// `self: TYPE` - SelfExplicit(P<Ty>, Ident), + Explicit(P<Ty>, Ident), } -pub type ExplicitSelf = Spanned<ExplicitSelf_>; +pub type ExplicitSelf = Spanned<SelfKind>; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Mod { @@ -1795,42 +1736,42 @@ pub struct Variant_ { pub type Variant = Spanned<Variant_>; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] -pub enum PathListItem_ { - PathListIdent { +pub enum PathListItemKind { + Ident { name: Ident, /// renamed in list, eg `use foo::{bar as baz};` rename: Option<Ident>, id: NodeId }, - PathListMod { + Mod { /// renamed in list, eg `use foo::{self as baz};` rename: Option<Ident>, id: NodeId } } -impl PathListItem_ { +impl PathListItemKind { pub fn id(&self) -> NodeId { match *self { - PathListIdent { id, .. } | PathListMod { id, .. } => id + PathListItemKind::Ident { id, .. } | PathListItemKind::Mod { id, .. } => id } } pub fn name(&self) -> Option<Ident> { match *self { - PathListIdent { name, .. } => Some(name), - PathListMod { .. } => None, + PathListItemKind::Ident { name, .. } => Some(name), + PathListItemKind::Mod { .. } => None, } } pub fn rename(&self) -> Option<Ident> { match *self { - PathListIdent { rename, .. } | PathListMod { rename, .. } => rename + PathListItemKind::Ident { rename, .. } | PathListItemKind::Mod { rename, .. } => rename } } } -pub type PathListItem = Spanned<PathListItem_>; +pub type PathListItem = Spanned<PathListItemKind>; pub type ViewPath = Spanned<ViewPath_>; @@ -1879,7 +1820,7 @@ pub struct Attribute_ { /// /// resolve maps each TraitRef's ref_id to its defining trait; that's all /// that the ref_id is for. The impl_id maps to the "self type" of this impl. -/// If this impl is an ItemImpl, the impl_id is redundant (it could be the +/// If this impl is an ItemKind::Impl, the impl_id is redundant (it could be the /// same as the impl's node id). #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct TraitRef { @@ -1907,8 +1848,8 @@ pub enum Visibility { impl Visibility { pub fn inherit_from(&self, parent_visibility: Visibility) -> Visibility { match *self { - Inherited => parent_visibility, - Public => *self + Visibility::Inherited => parent_visibility, + Visibility::Public => *self } } } @@ -2007,7 +1948,7 @@ pub struct Item { pub ident: Ident, pub attrs: Vec<Attribute>, pub id: NodeId, - pub node: Item_, + pub node: ItemKind, pub vis: Visibility, pub span: Span, } @@ -2019,32 +1960,32 @@ impl Item { } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum Item_ { +pub enum ItemKind { /// An`extern crate` item, with optional original crate name, /// /// e.g. `extern crate foo` or `extern crate foo_bar as foo` - ItemExternCrate(Option<Name>), + ExternCrate(Option<Name>), /// A `use` or `pub use` item - ItemUse(P<ViewPath>), + Use(P<ViewPath>), /// A `static` item - ItemStatic(P<Ty>, Mutability, P<Expr>), + Static(P<Ty>, Mutability, P<Expr>), /// A `const` item - ItemConst(P<Ty>, P<Expr>), + Const(P<Ty>, P<Expr>), /// A function declaration - ItemFn(P<FnDecl>, Unsafety, Constness, Abi, Generics, P<Block>), + Fn(P<FnDecl>, Unsafety, Constness, Abi, Generics, P<Block>), /// A module - ItemMod(Mod), + Mod(Mod), /// An external module - ItemForeignMod(ForeignMod), + ForeignMod(ForeignMod), /// A type alias, e.g. `type Foo = Bar<u8>` - ItemTy(P<Ty>, Generics), + Ty(P<Ty>, Generics), /// An enum definition, e.g. `enum Foo<A, B> {C<A>, D<B>}` - ItemEnum(EnumDef, Generics), + Enum(EnumDef, Generics), /// A struct definition, e.g. `struct Foo<A> {x: A}` - ItemStruct(VariantData, Generics), + Struct(VariantData, Generics), /// Represents a Trait Declaration - ItemTrait(Unsafety, + Trait(Unsafety, Generics, TyParamBounds, Vec<P<TraitItem>>), @@ -2052,35 +1993,35 @@ pub enum Item_ { // Default trait implementations /// // `impl Trait for .. {}` - ItemDefaultImpl(Unsafety, TraitRef), + DefaultImpl(Unsafety, TraitRef), /// An implementation, eg `impl<A> Trait for Foo { .. }` - ItemImpl(Unsafety, + Impl(Unsafety, ImplPolarity, Generics, Option<TraitRef>, // (optional) trait this impl implements P<Ty>, // self Vec<P<ImplItem>>), /// A macro invocation (which includes macro definition) - ItemMac(Mac), + Mac(Mac), } -impl Item_ { +impl ItemKind { pub fn descriptive_variant(&self) -> &str { match *self { - ItemExternCrate(..) => "extern crate", - ItemUse(..) => "use", - ItemStatic(..) => "static item", - ItemConst(..) => "constant item", - ItemFn(..) => "function", - ItemMod(..) => "module", - ItemForeignMod(..) => "foreign module", - ItemTy(..) => "type alias", - ItemEnum(..) => "enum", - ItemStruct(..) => "struct", - ItemTrait(..) => "trait", - ItemMac(..) | - ItemImpl(..) | - ItemDefaultImpl(..) => "item" + ItemKind::ExternCrate(..) => "extern crate", + ItemKind::Use(..) => "use", + ItemKind::Static(..) => "static item", + ItemKind::Const(..) => "constant item", + ItemKind::Fn(..) => "function", + ItemKind::Mod(..) => "module", + ItemKind::ForeignMod(..) => "foreign module", + ItemKind::Ty(..) => "type alias", + ItemKind::Enum(..) => "enum", + ItemKind::Struct(..) => "struct", + ItemKind::Trait(..) => "trait", + ItemKind::Mac(..) | + ItemKind::Impl(..) | + ItemKind::DefaultImpl(..) => "item" } } } @@ -2089,7 +2030,7 @@ impl Item_ { pub struct ForeignItem { pub ident: Ident, pub attrs: Vec<Attribute>, - pub node: ForeignItem_, + pub node: ForeignItemKind, pub id: NodeId, pub span: Span, pub vis: Visibility, @@ -2097,19 +2038,19 @@ pub struct ForeignItem { /// An item within an `extern` block #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum ForeignItem_ { +pub enum ForeignItemKind { /// A foreign function - ForeignItemFn(P<FnDecl>, Generics), + Fn(P<FnDecl>, Generics), /// A foreign static item (`static ext: u8`), with optional mutability /// (the boolean is true when mutable) - ForeignItemStatic(P<Ty>, bool), + Static(P<Ty>, bool), } -impl ForeignItem_ { +impl ForeignItemKind { pub fn descriptive_variant(&self) -> &str { match *self { - ForeignItemFn(..) => "foreign function", - ForeignItemStatic(..) => "foreign static item" + ForeignItemKind::Fn(..) => "foreign function", + ForeignItemKind::Static(..) => "foreign static item" } } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 03dc25e1b3c..e22cdab97e8 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -27,7 +27,7 @@ pub fn path_name_i(idents: &[Ident]) -> String { } pub fn is_path(e: P<Expr>) -> bool { - match e.node { ExprPath(..) => true, _ => false } + match e.node { ExprKind::Path(..) => true, _ => false } } @@ -66,9 +66,10 @@ pub fn path_to_ident(path: &Path) -> Option<Ident> { } pub fn ident_to_pat(id: NodeId, s: Span, i: Ident) -> P<Pat> { + let spanned = codemap::Spanned{ span: s, node: i }; P(Pat { id: id, - node: PatIdent(BindingMode::ByValue(MutImmutable), codemap::Spanned{span:s, node:i}, None), + node: PatIdent(BindingMode::ByValue(Mutability::Immutable), spanned, None), span: s }) } @@ -173,7 +174,7 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> { self.operation.visit_id(item.id); match item.node { - ItemUse(ref view_path) => { + ItemKind::Use(ref view_path) => { match view_path.node { ViewPathSimple(_, _) | ViewPathGlob(_) => {} diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 96d0052cf18..cc5f30e2184 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -15,8 +15,8 @@ pub use self::ReprAttr::*; pub use self::IntType::*; use ast; -use ast::{AttrId, Attribute, Attribute_, MetaItem, MetaWord, MetaNameValue, MetaList}; -use ast::{Stmt, StmtDecl, StmtExpr, StmtMac, StmtSemi, DeclItem, DeclLocal}; +use ast::{AttrId, Attribute, Attribute_, MetaItem, MetaItemKind}; +use ast::{Stmt, StmtKind, DeclKind}; use ast::{Expr, Item, Local, Decl}; use codemap::{Span, Spanned, spanned, dummy_spanned}; use codemap::BytePos; @@ -66,7 +66,7 @@ pub trait AttrMetaMethods { /// `#[foo="bar"]` and `#[foo(bar)]` fn name(&self) -> InternedString; - /// Gets the string value if self is a MetaNameValue variant + /// Gets the string value if self is a MetaItemKind::NameValue variant /// containing a string, otherwise None. fn value_str(&self) -> Option<InternedString>; /// Gets a list of inner meta items from a list MetaItem type. @@ -96,17 +96,17 @@ impl AttrMetaMethods for Attribute { impl AttrMetaMethods for MetaItem { fn name(&self) -> InternedString { match self.node { - MetaWord(ref n) => (*n).clone(), - MetaNameValue(ref n, _) => (*n).clone(), - MetaList(ref n, _) => (*n).clone(), + MetaItemKind::Word(ref n) => (*n).clone(), + MetaItemKind::NameValue(ref n, _) => (*n).clone(), + MetaItemKind::List(ref n, _) => (*n).clone(), } } fn value_str(&self) -> Option<InternedString> { match self.node { - MetaNameValue(_, ref v) => { + MetaItemKind::NameValue(_, ref v) => { match v.node { - ast::LitStr(ref s, _) => Some((*s).clone()), + ast::LitKind::Str(ref s, _) => Some((*s).clone()), _ => None, } }, @@ -116,7 +116,7 @@ impl AttrMetaMethods for MetaItem { fn meta_item_list(&self) -> Option<&[P<MetaItem>]> { match self.node { - MetaList(_, ref l) => Some(&l[..]), + MetaItemKind::List(_, ref l) => Some(&l[..]), _ => None } } @@ -173,21 +173,21 @@ impl AttributeMethods for Attribute { pub fn mk_name_value_item_str(name: InternedString, value: InternedString) -> P<MetaItem> { - let value_lit = dummy_spanned(ast::LitStr(value, ast::CookedStr)); + let value_lit = dummy_spanned(ast::LitKind::Str(value, ast::StrStyle::Cooked)); mk_name_value_item(name, value_lit) } pub fn mk_name_value_item(name: InternedString, value: ast::Lit) -> P<MetaItem> { - P(dummy_spanned(MetaNameValue(name, value))) + P(dummy_spanned(MetaItemKind::NameValue(name, value))) } pub fn mk_list_item(name: InternedString, items: Vec<P<MetaItem>>) -> P<MetaItem> { - P(dummy_spanned(MetaList(name, items))) + P(dummy_spanned(MetaItemKind::List(name, items))) } pub fn mk_word_item(name: InternedString) -> P<MetaItem> { - P(dummy_spanned(MetaWord(name))) + P(dummy_spanned(MetaItemKind::Word(name))) } thread_local! { static NEXT_ATTR_ID: Cell<usize> = Cell::new(0) } @@ -225,12 +225,11 @@ pub fn mk_sugared_doc_attr(id: AttrId, text: InternedString, lo: BytePos, hi: BytePos) -> Attribute { let style = doc_comment_style(&text); - let lit = spanned(lo, hi, ast::LitStr(text, ast::CookedStr)); + let lit = spanned(lo, hi, ast::LitKind::Str(text, ast::StrStyle::Cooked)); let attr = Attribute_ { id: id, style: style, - value: P(spanned(lo, hi, MetaNameValue(InternedString::new("doc"), - lit))), + value: P(spanned(lo, hi, MetaItemKind::NameValue(InternedString::new("doc"), lit))), is_sugared_doc: true }; spanned(lo, hi, attr) @@ -286,7 +285,7 @@ pub fn sort_meta_items(items: Vec<P<MetaItem>>) -> Vec<P<MetaItem>> { v.into_iter().map(|(_, m)| m.map(|Spanned {node, span}| { Spanned { node: match node { - MetaList(n, mis) => MetaList(n, sort_meta_items(mis)), + MetaItemKind::List(n, mis) => MetaItemKind::List(n, sort_meta_items(mis)), _ => node }, span: span @@ -329,11 +328,11 @@ pub enum InlineAttr { pub fn find_inline_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> InlineAttr { attrs.iter().fold(InlineAttr::None, |ia,attr| { match attr.node.value.node { - MetaWord(ref n) if *n == "inline" => { + MetaItemKind::Word(ref n) if *n == "inline" => { mark_used(attr); InlineAttr::Hint } - MetaList(ref n, ref items) if *n == "inline" => { + MetaItemKind::List(ref n, ref items) if *n == "inline" => { mark_used(attr); if items.len() != 1 { diagnostic.map(|d|{ d.span_err(attr.span, "expected one argument"); }); @@ -365,11 +364,11 @@ pub fn cfg_matches<T: CfgDiag>(cfgs: &[P<MetaItem>], cfg: &ast::MetaItem, diag: &mut T) -> bool { match cfg.node { - ast::MetaList(ref pred, ref mis) if &pred[..] == "any" => + ast::MetaItemKind::List(ref pred, ref mis) if &pred[..] == "any" => mis.iter().any(|mi| cfg_matches(cfgs, &**mi, diag)), - ast::MetaList(ref pred, ref mis) if &pred[..] == "all" => + ast::MetaItemKind::List(ref pred, ref mis) if &pred[..] == "all" => mis.iter().all(|mi| cfg_matches(cfgs, &**mi, diag)), - ast::MetaList(ref pred, ref mis) if &pred[..] == "not" => { + ast::MetaItemKind::List(ref pred, ref mis) if &pred[..] == "not" => { if mis.len() != 1 { diag.emit_error(|diagnostic| { diagnostic.span_err(cfg.span, "expected 1 cfg-pattern"); @@ -378,14 +377,14 @@ pub fn cfg_matches<T: CfgDiag>(cfgs: &[P<MetaItem>], } !cfg_matches(cfgs, &*mis[0], diag) } - ast::MetaList(ref pred, _) => { + ast::MetaItemKind::List(ref pred, _) => { diag.emit_error(|diagnostic| { diagnostic.span_err(cfg.span, &format!("invalid predicate `{}`", pred)); }); false }, - ast::MetaWord(_) | ast::MetaNameValue(..) => { + ast::MetaItemKind::Word(_) | ast::MetaItemKind::NameValue(..) => { diag.flag_gated(|feature_gated_cfgs| { feature_gated_cfgs.extend( GatedCfg::gate(cfg).map(GatedCfgAttr::GatedCfg)); @@ -707,11 +706,11 @@ pub fn require_unique_names(diagnostic: &Handler, metas: &[P<MetaItem>]) { pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr> { let mut acc = Vec::new(); match attr.node.value.node { - ast::MetaList(ref s, ref items) if *s == "repr" => { + ast::MetaItemKind::List(ref s, ref items) if *s == "repr" => { mark_used(attr); for item in items { match item.node { - ast::MetaWord(ref word) => { + ast::MetaItemKind::Word(ref word) => { let hint = match &word[..] { // Can't use "extern" because it's not a lexical identifier. "C" => Some(ReprExtern), @@ -746,16 +745,16 @@ pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr> fn int_type_of_word(s: &str) -> Option<IntType> { match s { - "i8" => Some(SignedInt(ast::TyI8)), - "u8" => Some(UnsignedInt(ast::TyU8)), - "i16" => Some(SignedInt(ast::TyI16)), - "u16" => Some(UnsignedInt(ast::TyU16)), - "i32" => Some(SignedInt(ast::TyI32)), - "u32" => Some(UnsignedInt(ast::TyU32)), - "i64" => Some(SignedInt(ast::TyI64)), - "u64" => Some(UnsignedInt(ast::TyU64)), - "isize" => Some(SignedInt(ast::TyIs)), - "usize" => Some(UnsignedInt(ast::TyUs)), + "i8" => Some(SignedInt(ast::IntTy::I8)), + "u8" => Some(UnsignedInt(ast::UintTy::U8)), + "i16" => Some(SignedInt(ast::IntTy::I16)), + "u16" => Some(UnsignedInt(ast::UintTy::U16)), + "i32" => Some(SignedInt(ast::IntTy::I32)), + "u32" => Some(UnsignedInt(ast::UintTy::U32)), + "i64" => Some(SignedInt(ast::IntTy::I64)), + "u64" => Some(UnsignedInt(ast::UintTy::U64)), + "isize" => Some(SignedInt(ast::IntTy::Is)), + "usize" => Some(UnsignedInt(ast::UintTy::Us)), _ => None } } @@ -797,11 +796,11 @@ impl IntType { } fn is_ffi_safe(self) -> bool { match self { - SignedInt(ast::TyI8) | UnsignedInt(ast::TyU8) | - SignedInt(ast::TyI16) | UnsignedInt(ast::TyU16) | - SignedInt(ast::TyI32) | UnsignedInt(ast::TyU32) | - SignedInt(ast::TyI64) | UnsignedInt(ast::TyU64) => true, - SignedInt(ast::TyIs) | UnsignedInt(ast::TyUs) => false + SignedInt(ast::IntTy::I8) | UnsignedInt(ast::UintTy::U8) | + SignedInt(ast::IntTy::I16) | UnsignedInt(ast::UintTy::U16) | + SignedInt(ast::IntTy::I32) | UnsignedInt(ast::UintTy::U32) | + SignedInt(ast::IntTy::I64) | UnsignedInt(ast::UintTy::U64) => true, + SignedInt(ast::IntTy::Is) | UnsignedInt(ast::UintTy::Us) => false } } } @@ -933,8 +932,8 @@ impl WithAttrs for P<Decl> { Spanned { span: span, node: match node { - DeclLocal(local) => DeclLocal(local.with_attrs(attrs)), - DeclItem(item) => DeclItem(item.with_attrs(attrs)), + DeclKind::Local(local) => DeclKind::Local(local.with_attrs(attrs)), + DeclKind::Item(item) => DeclKind::Item(item.with_attrs(attrs)), } } }) @@ -947,12 +946,12 @@ impl WithAttrs for P<Stmt> { Spanned { span: span, node: match node { - StmtDecl(decl, id) => StmtDecl(decl.with_attrs(attrs), id), - StmtExpr(expr, id) => StmtExpr(expr.with_attrs(attrs), id), - StmtSemi(expr, id) => StmtSemi(expr.with_attrs(attrs), id), - StmtMac(mac, style, mut ats) => { + StmtKind::Decl(decl, id) => StmtKind::Decl(decl.with_attrs(attrs), id), + StmtKind::Expr(expr, id) => StmtKind::Expr(expr.with_attrs(attrs), id), + StmtKind::Semi(expr, id) => StmtKind::Semi(expr.with_attrs(attrs), id), + StmtKind::Mac(mac, style, mut ats) => { ats.update(|a| a.append(attrs)); - StmtMac(mac, style, ats) + StmtKind::Mac(mac, style, ats) } }, } diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index 64b16538f05..09408f68dfd 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -52,8 +52,8 @@ impl<'a, F> fold::Folder for Context<'a, F> where F: FnMut(&[ast::Attribute]) -> fn fold_foreign_mod(&mut self, foreign_mod: ast::ForeignMod) -> ast::ForeignMod { fold_foreign_mod(self, foreign_mod) } - fn fold_item_underscore(&mut self, item: ast::Item_) -> ast::Item_ { - fold_item_underscore(self, item) + fn fold_item_kind(&mut self, item: ast::ItemKind) -> ast::ItemKind { + fold_item_kind(self, item) } fn fold_expr(&mut self, expr: P<ast::Expr>) -> P<ast::Expr> { // If an expr is valid to cfg away it will have been removed by the @@ -129,26 +129,26 @@ fn fold_item<F>(cx: &mut Context<F>, item: P<ast::Item>) -> SmallVector<P<ast::I } } -fn fold_item_underscore<F>(cx: &mut Context<F>, item: ast::Item_) -> ast::Item_ where +fn fold_item_kind<F>(cx: &mut Context<F>, item: ast::ItemKind) -> ast::ItemKind where F: FnMut(&[ast::Attribute]) -> bool { let item = match item { - ast::ItemImpl(u, o, a, b, c, impl_items) => { + ast::ItemKind::Impl(u, o, a, b, c, impl_items) => { let impl_items = impl_items.into_iter() .filter(|ii| (cx.in_cfg)(&ii.attrs)) .collect(); - ast::ItemImpl(u, o, a, b, c, impl_items) + ast::ItemKind::Impl(u, o, a, b, c, impl_items) } - ast::ItemTrait(u, a, b, methods) => { + ast::ItemKind::Trait(u, a, b, methods) => { let methods = methods.into_iter() .filter(|ti| (cx.in_cfg)(&ti.attrs)) .collect(); - ast::ItemTrait(u, a, b, methods) + ast::ItemKind::Trait(u, a, b, methods) } - ast::ItemStruct(def, generics) => { - ast::ItemStruct(fold_struct(cx, def), generics) + ast::ItemKind::Struct(def, generics) => { + ast::ItemKind::Struct(fold_struct(cx, def), generics) } - ast::ItemEnum(def, generics) => { + ast::ItemKind::Enum(def, generics) => { let variants = def.variants.into_iter().filter_map(|v| { if !(cx.in_cfg)(&v.node.attrs) { None @@ -167,14 +167,14 @@ fn fold_item_underscore<F>(cx: &mut Context<F>, item: ast::Item_) -> ast::Item_ })) } }); - ast::ItemEnum(ast::EnumDef { + ast::ItemKind::Enum(ast::EnumDef { variants: variants.collect(), }, generics) } item => item, }; - fold::noop_fold_item_underscore(item, cx) + fold::noop_fold_item_kind(item, cx) } fn fold_struct<F>(cx: &mut Context<F>, vdata: ast::VariantData) -> ast::VariantData where @@ -212,8 +212,8 @@ fn fold_expr<F>(cx: &mut Context<F>, expr: P<ast::Expr>) -> P<ast::Expr> where fold::noop_fold_expr(ast::Expr { id: id, node: match node { - ast::ExprMatch(m, arms) => { - ast::ExprMatch(m, arms.into_iter() + ast::ExprKind::Match(m, arms) => { + ast::ExprKind::Match(m, arms.into_iter() .filter(|a| (cx.in_cfg)(&a.attrs)) .collect()) } @@ -270,7 +270,7 @@ fn in_cfg<T: CfgDiag>(cfg: &[P<ast::MetaItem>], diag: &mut T) -> bool { attrs.iter().all(|attr| { let mis = match attr.node.value.node { - ast::MetaList(_, ref mis) if is_cfg(&attr) => mis, + ast::MetaItemKind::List(_, ref mis) if is_cfg(&attr) => mis, _ => return true }; @@ -372,8 +372,8 @@ impl<'v, 'a, 'b> visit::Visitor<'v> for StmtExprAttrFeatureVisitor<'a, 'b> { let stmt_attrs = s.node.attrs(); if stmt_attrs.len() > 0 { // attributes on items are fine - if let ast::StmtDecl(ref decl, _) = s.node { - if let ast::DeclItem(_) = decl.node { + if let ast::StmtKind::Decl(ref decl, _) = s.node { + if let ast::DeclKind::Item(_) = decl.node { visit::walk_stmt(self, s); return; } diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 6e389e83591..43b4a201afc 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -207,15 +207,15 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, span, ecx.ty_ident(span, ecx.ident_of("str")), Some(static_), - ast::MutImmutable, + ast::Mutability::Immutable, ); let ty = ecx.ty( span, - ast::TyFixedLengthVec( + ast::TyKind::FixedLengthVec( ecx.ty( span, - ast::TyTup(vec![ty_str.clone(), ty_str]) + ast::TyKind::Tup(vec![ty_str.clone(), ty_str]) ), ecx.expr_usize(span, count), ), @@ -226,11 +226,11 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, ident: name.clone(), attrs: Vec::new(), id: ast::DUMMY_NODE_ID, - node: ast::ItemConst( + node: ast::ItemKind::Const( ty, expr, ), - vis: ast::Public, + vis: ast::Visibility::Public, span: span, }) ])) diff --git a/src/libsyntax/entry.rs b/src/libsyntax/entry.rs index ddc4443a77c..7014e576e2b 100644 --- a/src/libsyntax/entry.rs +++ b/src/libsyntax/entry.rs @@ -9,7 +9,7 @@ // except according to those terms. use attr; -use ast::{Item, ItemFn}; +use ast::{Item, ItemKind}; pub enum EntryPointType { None, @@ -23,7 +23,7 @@ pub enum EntryPointType { // them in sync. pub fn entry_point_type(item: &Item, depth: usize) -> EntryPointType { match item.node { - ItemFn(..) => { + ItemKind::Fn(..) => { if attr::contains_name(&item.attrs, "start") { EntryPointType::Start } else if attr::contains_name(&item.attrs, "main") { diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 107626c54cc..381d952ea88 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -120,7 +120,7 @@ impl<F> MultiItemDecorator for F } } -// A more flexible ItemModifier (ItemModifier should go away, eventually, FIXME). +// A more flexible ItemKind::Modifier (ItemKind::Modifier should go away, eventually, FIXME). // meta_item is the annotation, item is the item being modified, parent_item // is the impl or trait item is declared in if item is part of such a thing. // FIXME Decorators should follow the same pattern too. @@ -205,7 +205,7 @@ macro_rules! make_stmts_default { ($me:expr) => { $me.make_expr().map(|e| { SmallVector::one(P(codemap::respan( - e.span, ast::StmtExpr(e, ast::DUMMY_NODE_ID)))) + e.span, ast::StmtKind::Expr(e, ast::DUMMY_NODE_ID)))) }) } } @@ -303,7 +303,7 @@ impl MacResult for MacEager { return Some(p); } if let Some(e) = self.expr { - if let ast::ExprLit(_) = e.node { + if let ast::ExprKind::Lit(_) = e.node { return Some(P(ast::Pat { id: ast::DUMMY_NODE_ID, span: e.span, @@ -349,7 +349,7 @@ impl DummyResult { pub fn raw_expr(sp: Span) -> P<ast::Expr> { P(ast::Expr { id: ast::DUMMY_NODE_ID, - node: ast::ExprLit(P(codemap::respan(sp, ast::LitBool(false)))), + node: ast::ExprKind::Lit(P(codemap::respan(sp, ast::LitKind::Bool(false)))), span: sp, attrs: None, }) @@ -367,7 +367,7 @@ impl DummyResult { pub fn raw_ty(sp: Span) -> P<ast::Ty> { P(ast::Ty { id: ast::DUMMY_NODE_ID, - node: ast::TyInfer, + node: ast::TyKind::Infer, span: sp }) } @@ -402,8 +402,8 @@ impl MacResult for DummyResult { fn make_stmts(self: Box<DummyResult>) -> Option<SmallVector<P<ast::Stmt>>> { Some(SmallVector::one(P( codemap::respan(self.span, - ast::StmtExpr(DummyResult::raw_expr(self.span), - ast::DUMMY_NODE_ID))))) + ast::StmtKind::Expr(DummyResult::raw_expr(self.span), + ast::DUMMY_NODE_ID))))) } } @@ -773,8 +773,8 @@ pub fn expr_to_string(cx: &mut ExtCtxt, expr: P<ast::Expr>, err_msg: &str) // we want to be able to handle e.g. concat("foo", "bar") let expr = cx.expander().fold_expr(expr); match expr.node { - ast::ExprLit(ref l) => match l.node { - ast::LitStr(ref s, style) => return Some(((*s).clone(), style)), + ast::ExprKind::Lit(ref l) => match l.node { + ast::LitKind::Str(ref s, style) => return Some(((*s).clone(), style)), _ => cx.span_err(l.span, err_msg) }, _ => cx.span_err(expr.span, err_msg) diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index a74c2340cec..31d5521799e 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -8,9 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use abi; -use ast::{Ident, Generics, Expr}; -use ast; +use abi::Abi; +use ast::{self, Ident, Generics, Expr, BlockCheckMode, UnOp}; use attr; use codemap::{Span, respan, Spanned, DUMMY_SP, Pos}; use ext::base::ExtCtxt; @@ -53,7 +52,7 @@ pub trait AstBuilder { // types fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy; - fn ty(&self, span: Span, ty: ast::Ty_) -> P<ast::Ty>; + fn ty(&self, span: Span, ty: ast::TyKind) -> P<ast::Ty>; fn ty_path(&self, ast::Path) -> P<ast::Ty>; fn ty_sum(&self, ast::Path, ast::TyParamBounds) -> P<ast::Ty>; fn ty_ident(&self, span: Span, idents: ast::Ident) -> P<ast::Ty>; @@ -109,13 +108,13 @@ pub trait AstBuilder { expr: Option<P<ast::Expr>>) -> P<ast::Block>; // expressions - fn expr(&self, span: Span, node: ast::Expr_) -> P<ast::Expr>; + fn expr(&self, span: Span, node: ast::ExprKind) -> P<ast::Expr>; fn expr_path(&self, path: ast::Path) -> P<ast::Expr>; fn expr_qpath(&self, span: Span, qself: ast::QSelf, path: ast::Path) -> P<ast::Expr>; fn expr_ident(&self, span: Span, id: ast::Ident) -> P<ast::Expr>; fn expr_self(&self, span: Span) -> P<ast::Expr>; - fn expr_binary(&self, sp: Span, op: ast::BinOp_, + fn expr_binary(&self, sp: Span, op: ast::BinOpKind, lhs: P<ast::Expr>, rhs: P<ast::Expr>) -> P<ast::Expr>; fn expr_deref(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr>; fn expr_unary(&self, sp: Span, op: ast::UnOp, e: P<ast::Expr>) -> P<ast::Expr>; @@ -140,7 +139,7 @@ pub trait AstBuilder { fn expr_struct_ident(&self, span: Span, id: ast::Ident, fields: Vec<ast::Field>) -> P<ast::Expr>; - fn expr_lit(&self, sp: Span, lit: ast::Lit_) -> P<ast::Expr>; + fn expr_lit(&self, sp: Span, lit: ast::LitKind) -> P<ast::Expr>; fn expr_usize(&self, span: Span, i: usize) -> P<ast::Expr>; fn expr_isize(&self, sp: Span, i: isize) -> P<ast::Expr>; @@ -214,7 +213,7 @@ pub trait AstBuilder { // items fn item(&self, span: Span, - name: Ident, attrs: Vec<ast::Attribute> , node: ast::Item_) -> P<ast::Item>; + name: Ident, attrs: Vec<ast::Attribute> , node: ast::ItemKind) -> P<ast::Item>; fn arg(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> ast::Arg; // FIXME unused self @@ -286,7 +285,7 @@ pub trait AstBuilder { fn meta_name_value(&self, sp: Span, name: InternedString, - value: ast::Lit_) + value: ast::LitKind) -> P<ast::MetaItem>; fn item_use(&self, sp: Span, @@ -386,7 +385,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } } - fn ty(&self, span: Span, ty: ast::Ty_) -> P<ast::Ty> { + fn ty(&self, span: Span, ty: ast::TyKind) -> P<ast::Ty> { P(ast::Ty { id: ast::DUMMY_NODE_ID, span: span, @@ -395,12 +394,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn ty_path(&self, path: ast::Path) -> P<ast::Ty> { - self.ty(path.span, ast::TyPath(None, path)) + self.ty(path.span, ast::TyKind::Path(None, path)) } fn ty_sum(&self, path: ast::Path, bounds: ast::TyParamBounds) -> P<ast::Ty> { self.ty(path.span, - ast::TyObjectSum(self.ty_path(path), + ast::TyKind::ObjectSum(self.ty_path(path), bounds)) } @@ -418,7 +417,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { mutbl: ast::Mutability) -> P<ast::Ty> { self.ty(span, - ast::TyRptr(lifetime, self.ty_mt(ty, mutbl))) + ast::TyKind::Rptr(lifetime, self.ty_mt(ty, mutbl))) } fn ty_ptr(&self, @@ -427,7 +426,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { mutbl: ast::Mutability) -> P<ast::Ty> { self.ty(span, - ast::TyPtr(self.ty_mt(ty, mutbl))) + ast::TyKind::Ptr(self.ty_mt(ty, mutbl))) } fn ty_option(&self, ty: P<ast::Ty>) -> P<ast::Ty> { @@ -441,7 +440,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn ty_infer(&self, span: Span) -> P<ast::Ty> { - self.ty(span, ast::TyInfer) + self.ty(span, ast::TyKind::Infer) } fn typaram(&self, @@ -507,13 +506,14 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn stmt_expr(&self, expr: P<ast::Expr>) -> P<ast::Stmt> { - P(respan(expr.span, ast::StmtSemi(expr, ast::DUMMY_NODE_ID))) + P(respan(expr.span, ast::StmtKind::Semi(expr, ast::DUMMY_NODE_ID))) } fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident, ex: P<ast::Expr>) -> P<ast::Stmt> { let pat = if mutbl { - self.pat_ident_binding_mode(sp, ident, ast::BindingMode::ByValue(ast::MutMutable)) + let binding_mode = ast::BindingMode::ByValue(ast::Mutability::Mutable); + self.pat_ident_binding_mode(sp, ident, binding_mode) } else { self.pat_ident(sp, ident) }; @@ -525,8 +525,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> { span: sp, attrs: None, }); - let decl = respan(sp, ast::DeclLocal(local)); - P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID))) + let decl = respan(sp, ast::DeclKind::Local(local)); + P(respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID))) } fn stmt_let_typed(&self, @@ -537,7 +537,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ex: P<ast::Expr>) -> P<ast::Stmt> { let pat = if mutbl { - self.pat_ident_binding_mode(sp, ident, ast::BindingMode::ByValue(ast::MutMutable)) + let binding_mode = ast::BindingMode::ByValue(ast::Mutability::Mutable); + self.pat_ident_binding_mode(sp, ident, binding_mode) } else { self.pat_ident(sp, ident) }; @@ -549,8 +550,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> { span: sp, attrs: None, }); - let decl = respan(sp, ast::DeclLocal(local)); - P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID))) + let decl = respan(sp, ast::DeclKind::Local(local)); + P(respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID))) } fn block(&self, span: Span, stmts: Vec<P<ast::Stmt>>, @@ -559,8 +560,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> P<ast::Stmt> { - let decl = respan(sp, ast::DeclItem(item)); - P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID))) + let decl = respan(sp, ast::DeclKind::Item(item)); + P(respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID))) } fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block> { @@ -574,12 +575,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> { stmts: stmts, expr: expr, id: ast::DUMMY_NODE_ID, - rules: ast::DefaultBlock, + rules: BlockCheckMode::Default, span: span, }) } - fn expr(&self, span: Span, node: ast::Expr_) -> P<ast::Expr> { + fn expr(&self, span: Span, node: ast::ExprKind) -> P<ast::Expr> { P(ast::Expr { id: ast::DUMMY_NODE_ID, node: node, @@ -589,12 +590,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn expr_path(&self, path: ast::Path) -> P<ast::Expr> { - self.expr(path.span, ast::ExprPath(None, path)) + self.expr(path.span, ast::ExprKind::Path(None, path)) } /// Constructs a QPath expression. fn expr_qpath(&self, span: Span, qself: ast::QSelf, path: ast::Path) -> P<ast::Expr> { - self.expr(span, ast::ExprPath(Some(qself), path)) + self.expr(span, ast::ExprKind::Path(Some(qself), path)) } fn expr_ident(&self, span: Span, id: ast::Ident) -> P<ast::Expr> { @@ -604,16 +605,16 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.expr_ident(span, special_idents::self_) } - fn expr_binary(&self, sp: Span, op: ast::BinOp_, + fn expr_binary(&self, sp: Span, op: ast::BinOpKind, lhs: P<ast::Expr>, rhs: P<ast::Expr>) -> P<ast::Expr> { - self.expr(sp, ast::ExprBinary(Spanned { node: op, span: sp }, lhs, rhs)) + self.expr(sp, ast::ExprKind::Binary(Spanned { node: op, span: sp }, lhs, rhs)) } fn expr_deref(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> { - self.expr_unary(sp, ast::UnDeref, e) + self.expr_unary(sp, UnOp::Deref, e) } fn expr_unary(&self, sp: Span, op: ast::UnOp, e: P<ast::Expr>) -> P<ast::Expr> { - self.expr(sp, ast::ExprUnary(op, e)) + self.expr(sp, ast::ExprKind::Unary(op, e)) } fn expr_field_access(&self, sp: Span, expr: P<ast::Expr>, ident: ast::Ident) -> P<ast::Expr> { @@ -624,7 +625,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { }; let id = Spanned { node: ident, span: field_span }; - self.expr(sp, ast::ExprField(expr, id)) + self.expr(sp, ast::ExprKind::Field(expr, id)) } fn expr_tup_field_access(&self, sp: Span, expr: P<ast::Expr>, idx: usize) -> P<ast::Expr> { let field_span = Span { @@ -634,21 +635,21 @@ impl<'a> AstBuilder for ExtCtxt<'a> { }; let id = Spanned { node: idx, span: field_span }; - self.expr(sp, ast::ExprTupField(expr, id)) + self.expr(sp, ast::ExprKind::TupField(expr, id)) } fn expr_addr_of(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> { - self.expr(sp, ast::ExprAddrOf(ast::MutImmutable, e)) + self.expr(sp, ast::ExprKind::AddrOf(ast::Mutability::Immutable, e)) } fn expr_mut_addr_of(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> { - self.expr(sp, ast::ExprAddrOf(ast::MutMutable, e)) + self.expr(sp, ast::ExprKind::AddrOf(ast::Mutability::Mutable, e)) } fn expr_call(&self, span: Span, expr: P<ast::Expr>, args: Vec<P<ast::Expr>>) -> P<ast::Expr> { - self.expr(span, ast::ExprCall(expr, args)) + self.expr(span, ast::ExprKind::Call(expr, args)) } fn expr_call_ident(&self, span: Span, id: ast::Ident, args: Vec<P<ast::Expr>>) -> P<ast::Expr> { - self.expr(span, ast::ExprCall(self.expr_ident(span, id), args)) + self.expr(span, ast::ExprKind::Call(self.expr_ident(span, id), args)) } fn expr_call_global(&self, sp: Span, fn_path: Vec<ast::Ident> , args: Vec<P<ast::Expr>> ) -> P<ast::Expr> { @@ -661,44 +662,50 @@ impl<'a> AstBuilder for ExtCtxt<'a> { mut args: Vec<P<ast::Expr>> ) -> P<ast::Expr> { let id = Spanned { node: ident, span: span }; args.insert(0, expr); - self.expr(span, ast::ExprMethodCall(id, Vec::new(), args)) + self.expr(span, ast::ExprKind::MethodCall(id, Vec::new(), args)) } fn expr_block(&self, b: P<ast::Block>) -> P<ast::Expr> { - self.expr(b.span, ast::ExprBlock(b)) + self.expr(b.span, ast::ExprKind::Block(b)) } fn field_imm(&self, span: Span, name: Ident, e: P<ast::Expr>) -> ast::Field { ast::Field { ident: respan(span, name), expr: e, span: span } } fn expr_struct(&self, span: Span, path: ast::Path, fields: Vec<ast::Field>) -> P<ast::Expr> { - self.expr(span, ast::ExprStruct(path, fields, None)) + self.expr(span, ast::ExprKind::Struct(path, fields, None)) } fn expr_struct_ident(&self, span: Span, id: ast::Ident, fields: Vec<ast::Field>) -> P<ast::Expr> { self.expr_struct(span, self.path_ident(span, id), fields) } - fn expr_lit(&self, sp: Span, lit: ast::Lit_) -> P<ast::Expr> { - self.expr(sp, ast::ExprLit(P(respan(sp, lit)))) + fn expr_lit(&self, sp: Span, lit: ast::LitKind) -> P<ast::Expr> { + self.expr(sp, ast::ExprKind::Lit(P(respan(sp, lit)))) } fn expr_usize(&self, span: Span, i: usize) -> P<ast::Expr> { - self.expr_lit(span, ast::LitInt(i as u64, ast::UnsignedIntLit(ast::TyUs))) + self.expr_lit(span, ast::LitKind::Int(i as u64, ast::LitIntType::Unsigned(ast::UintTy::Us))) } fn expr_isize(&self, sp: Span, i: isize) -> P<ast::Expr> { - self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::TyIs, - ast::Sign::new(i)))) + if i < 0 { + let i = (-i) as u64; + let lit_ty = ast::LitIntType::Signed(ast::IntTy::Is); + let lit = self.expr_lit(sp, ast::LitKind::Int(i, lit_ty)); + self.expr_unary(sp, ast::UnOp::Neg, lit) + } else { + self.expr_lit(sp, ast::LitKind::Int(i as u64, ast::LitIntType::Signed(ast::IntTy::Is))) + } } fn expr_u32(&self, sp: Span, u: u32) -> P<ast::Expr> { - self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::TyU32))) + self.expr_lit(sp, ast::LitKind::Int(u as u64, ast::LitIntType::Unsigned(ast::UintTy::U32))) } fn expr_u8(&self, sp: Span, u: u8) -> P<ast::Expr> { - self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::TyU8))) + self.expr_lit(sp, ast::LitKind::Int(u as u64, ast::LitIntType::Unsigned(ast::UintTy::U8))) } fn expr_bool(&self, sp: Span, value: bool) -> P<ast::Expr> { - self.expr_lit(sp, ast::LitBool(value)) + self.expr_lit(sp, ast::LitKind::Bool(value)) } fn expr_vec(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> { - self.expr(sp, ast::ExprVec(exprs)) + self.expr(sp, ast::ExprKind::Vec(exprs)) } fn expr_vec_ng(&self, sp: Span) -> P<ast::Expr> { self.expr_call_global(sp, self.std_path(&["vec", "Vec", "new"]), @@ -708,11 +715,11 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.expr_addr_of(sp, self.expr_vec(sp, exprs)) } fn expr_str(&self, sp: Span, s: InternedString) -> P<ast::Expr> { - self.expr_lit(sp, ast::LitStr(s, ast::CookedStr)) + self.expr_lit(sp, ast::LitKind::Str(s, ast::StrStyle::Cooked)) } fn expr_cast(&self, sp: Span, expr: P<ast::Expr>, ty: P<ast::Ty>) -> P<ast::Expr> { - self.expr(sp, ast::ExprCast(expr, ty)) + self.expr(sp, ast::ExprKind::Cast(expr, ty)) } @@ -729,12 +736,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn expr_break(&self, sp: Span) -> P<ast::Expr> { - self.expr(sp, ast::ExprBreak(None)) + self.expr(sp, ast::ExprKind::Break(None)) } fn expr_tuple(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> { - self.expr(sp, ast::ExprTup(exprs)) + self.expr(sp, ast::ExprKind::Tup(exprs)) } fn expr_fail(&self, span: Span, msg: InternedString) -> P<ast::Expr> { @@ -786,7 +793,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { let err_inner_expr = self.expr_call(sp, self.expr_path(err_path), vec!(binding_expr.clone())); // return Err(__try_var) - let err_expr = self.expr(sp, ast::ExprRet(Some(err_inner_expr))); + let err_expr = self.expr(sp, ast::ExprKind::Ret(Some(err_inner_expr))); // Ok(__try_var) => __try_var let ok_arm = self.arm(sp, vec!(ok_pat), binding_expr); @@ -808,7 +815,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.pat(span, ast::PatLit(expr)) } fn pat_ident(&self, span: Span, ident: ast::Ident) -> P<ast::Pat> { - self.pat_ident_binding_mode(span, ident, ast::BindingMode::ByValue(ast::MutImmutable)) + let binding_mode = ast::BindingMode::ByValue(ast::Mutability::Immutable); + self.pat_ident_binding_mode(span, ident, binding_mode) } fn pat_ident_binding_mode(&self, @@ -869,29 +877,29 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn expr_match(&self, span: Span, arg: P<ast::Expr>, arms: Vec<ast::Arm>) -> P<Expr> { - self.expr(span, ast::ExprMatch(arg, arms)) + self.expr(span, ast::ExprKind::Match(arg, arms)) } fn expr_if(&self, span: Span, cond: P<ast::Expr>, then: P<ast::Expr>, els: Option<P<ast::Expr>>) -> P<ast::Expr> { let els = els.map(|x| self.expr_block(self.block_expr(x))); - self.expr(span, ast::ExprIf(cond, self.block_expr(then), els)) + self.expr(span, ast::ExprKind::If(cond, self.block_expr(then), els)) } fn expr_loop(&self, span: Span, block: P<ast::Block>) -> P<ast::Expr> { - self.expr(span, ast::ExprLoop(block, None)) + self.expr(span, ast::ExprKind::Loop(block, None)) } fn lambda_fn_decl(&self, span: Span, fn_decl: P<ast::FnDecl>, blk: P<ast::Block>) -> P<ast::Expr> { - self.expr(span, ast::ExprClosure(ast::CaptureByRef, fn_decl, blk)) + self.expr(span, ast::ExprKind::Closure(ast::CaptureBy::Ref, fn_decl, blk)) } fn lambda(&self, span: Span, ids: Vec<ast::Ident>, blk: P<ast::Block>) -> P<ast::Expr> { let fn_decl = self.fn_decl( ids.iter().map(|id| self.arg(span, *id, self.ty_infer(span))).collect(), self.ty_infer(span)); - self.expr(span, ast::ExprClosure(ast::CaptureByRef, fn_decl, blk)) + self.expr(span, ast::ExprKind::Closure(ast::CaptureBy::Ref, fn_decl, blk)) } fn lambda0(&self, span: Span, blk: P<ast::Block>) -> P<ast::Expr> { self.lambda(span, Vec::new(), blk) @@ -940,13 +948,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn fn_decl(&self, inputs: Vec<ast::Arg>, output: P<ast::Ty>) -> P<ast::FnDecl> { P(ast::FnDecl { inputs: inputs, - output: ast::Return(output), + output: ast::FunctionRetTy::Ty(output), variadic: false }) } fn item(&self, span: Span, name: Ident, - attrs: Vec<ast::Attribute>, node: ast::Item_) -> P<ast::Item> { + attrs: Vec<ast::Attribute>, node: ast::ItemKind) -> P<ast::Item> { // FIXME: Would be nice if our generated code didn't violate // Rust coding conventions P(ast::Item { @@ -954,7 +962,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { attrs: attrs, id: ast::DUMMY_NODE_ID, node: node, - vis: ast::Inherited, + vis: ast::Visibility::Inherited, span: span }) } @@ -969,10 +977,10 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.item(span, name, Vec::new(), - ast::ItemFn(self.fn_decl(inputs, output), + ast::ItemKind::Fn(self.fn_decl(inputs, output), ast::Unsafety::Normal, ast::Constness::NotConst, - abi::Rust, + Abi::Rust, generics, body)) } @@ -997,7 +1005,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { let fields: Vec<_> = tys.into_iter().map(|ty| { Spanned { span: ty.span, node: ast::StructField_ { ty: ty, - kind: ast::UnnamedField(ast::Inherited), + kind: ast::UnnamedField(ast::Visibility::Inherited), attrs: Vec::new(), id: ast::DUMMY_NODE_ID, }} @@ -1021,7 +1029,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn item_enum_poly(&self, span: Span, name: Ident, enum_definition: ast::EnumDef, generics: Generics) -> P<ast::Item> { - self.item(span, name, Vec::new(), ast::ItemEnum(enum_definition, generics)) + self.item(span, name, Vec::new(), ast::ItemKind::Enum(enum_definition, generics)) } fn item_enum(&self, span: Span, name: Ident, @@ -1042,7 +1050,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn item_struct_poly(&self, span: Span, name: Ident, struct_def: ast::VariantData, generics: Generics) -> P<ast::Item> { - self.item(span, name, Vec::new(), ast::ItemStruct(struct_def, generics)) + self.item(span, name, Vec::new(), ast::ItemKind::Struct(struct_def, generics)) } fn item_mod(&self, span: Span, inner_span: Span, name: Ident, @@ -1052,7 +1060,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { span, name, attrs, - ast::ItemMod(ast::Mod { + ast::ItemKind::Mod(ast::Mod { inner: inner_span, items: items, }) @@ -1066,7 +1074,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { mutbl: ast::Mutability, expr: P<ast::Expr>) -> P<ast::Item> { - self.item(span, name, Vec::new(), ast::ItemStatic(ty, mutbl, expr)) + self.item(span, name, Vec::new(), ast::ItemKind::Static(ty, mutbl, expr)) } fn item_const(&self, @@ -1075,12 +1083,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ty: P<ast::Ty>, expr: P<ast::Expr>) -> P<ast::Item> { - self.item(span, name, Vec::new(), ast::ItemConst(ty, expr)) + self.item(span, name, Vec::new(), ast::ItemKind::Const(ty, expr)) } fn item_ty_poly(&self, span: Span, name: Ident, ty: P<ast::Ty>, generics: Generics) -> P<ast::Item> { - self.item(span, name, Vec::new(), ast::ItemTy(ty, generics)) + self.item(span, name, Vec::new(), ast::ItemKind::Ty(ty, generics)) } fn item_ty(&self, span: Span, name: Ident, ty: P<ast::Ty>) -> P<ast::Item> { @@ -1097,21 +1105,21 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn meta_word(&self, sp: Span, w: InternedString) -> P<ast::MetaItem> { - P(respan(sp, ast::MetaWord(w))) + P(respan(sp, ast::MetaItemKind::Word(w))) } fn meta_list(&self, sp: Span, name: InternedString, mis: Vec<P<ast::MetaItem>> ) -> P<ast::MetaItem> { - P(respan(sp, ast::MetaList(name, mis))) + P(respan(sp, ast::MetaItemKind::List(name, mis))) } fn meta_name_value(&self, sp: Span, name: InternedString, - value: ast::Lit_) + value: ast::LitKind) -> P<ast::MetaItem> { - P(respan(sp, ast::MetaNameValue(name, respan(sp, value)))) + P(respan(sp, ast::MetaItemKind::NameValue(name, respan(sp, value)))) } fn item_use(&self, sp: Span, @@ -1120,7 +1128,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { id: ast::DUMMY_NODE_ID, ident: special_idents::invalid, attrs: vec![], - node: ast::ItemUse(vp), + node: ast::ItemKind::Use(vp), vis: vis, span: sp }) @@ -1142,7 +1150,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn item_use_list(&self, sp: Span, vis: ast::Visibility, path: Vec<ast::Ident>, imports: &[ast::Ident]) -> P<ast::Item> { let imports = imports.iter().map(|id| { - respan(sp, ast::PathListIdent { name: *id, rename: None, id: ast::DUMMY_NODE_ID }) + let item = ast::PathListItemKind::Ident { + name: *id, + rename: None, + id: ast::DUMMY_NODE_ID, + }; + respan(sp, item) }).collect(); self.item_use(sp, vis, diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 72537f6c7b2..c4bbe709f34 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -8,10 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{Block, Crate, DeclLocal, PatMac}; +use ast::{Block, Crate, DeclKind, PatMac}; use ast::{Local, Ident, Mac_, Name}; -use ast::{ItemMac, MacStmtWithSemicolon, Mrk, Stmt, StmtDecl, StmtMac}; -use ast::{StmtExpr, StmtSemi}; +use ast::{MacStmtStyle, Mrk, Stmt, StmtKind, ItemKind}; use ast::TokenTree; use ast; use ext::mtwt; @@ -42,7 +41,7 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> { // expr_mac should really be expr_ext or something; it's the // entry-point for all syntax extensions. - ast::ExprMac(mac) => { + ast::ExprKind::Mac(mac) => { // Assert that we drop any macro attributes on the floor here drop(attrs); @@ -69,7 +68,7 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> { }) } - ast::ExprInPlace(placer, value_expr) => { + ast::ExprKind::InPlace(placer, value_expr) => { // Ensure feature-gate is enabled feature_gate::check_for_placement_in( fld.cx.ecfg.features, @@ -78,18 +77,18 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> { let placer = fld.fold_expr(placer); let value_expr = fld.fold_expr(value_expr); - fld.cx.expr(span, ast::ExprInPlace(placer, value_expr)) + fld.cx.expr(span, ast::ExprKind::InPlace(placer, value_expr)) .with_attrs(fold_thin_attrs(attrs, fld)) } - ast::ExprWhile(cond, body, opt_ident) => { + ast::ExprKind::While(cond, body, opt_ident) => { let cond = fld.fold_expr(cond); let (body, opt_ident) = expand_loop_block(body, opt_ident, fld); - fld.cx.expr(span, ast::ExprWhile(cond, body, opt_ident)) + fld.cx.expr(span, ast::ExprKind::While(cond, body, opt_ident)) .with_attrs(fold_thin_attrs(attrs, fld)) } - ast::ExprWhileLet(pat, expr, body, opt_ident) => { + ast::ExprKind::WhileLet(pat, expr, body, opt_ident) => { let pat = fld.fold_pat(pat); let expr = fld.fold_expr(expr); @@ -103,17 +102,17 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> { }); assert!(rewritten_pats.len() == 1); - fld.cx.expr(span, ast::ExprWhileLet(rewritten_pats.remove(0), expr, body, opt_ident)) - .with_attrs(fold_thin_attrs(attrs, fld)) + let wl = ast::ExprKind::WhileLet(rewritten_pats.remove(0), expr, body, opt_ident); + fld.cx.expr(span, wl).with_attrs(fold_thin_attrs(attrs, fld)) } - ast::ExprLoop(loop_block, opt_ident) => { + ast::ExprKind::Loop(loop_block, opt_ident) => { let (loop_block, opt_ident) = expand_loop_block(loop_block, opt_ident, fld); - fld.cx.expr(span, ast::ExprLoop(loop_block, opt_ident)) + fld.cx.expr(span, ast::ExprKind::Loop(loop_block, opt_ident)) .with_attrs(fold_thin_attrs(attrs, fld)) } - ast::ExprForLoop(pat, head, body, opt_ident) => { + ast::ExprKind::ForLoop(pat, head, body, opt_ident) => { let pat = fld.fold_pat(pat); // Hygienic renaming of the for loop body (for loop binds its pattern). @@ -127,11 +126,11 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> { assert!(rewritten_pats.len() == 1); let head = fld.fold_expr(head); - fld.cx.expr(span, ast::ExprForLoop(rewritten_pats.remove(0), head, body, opt_ident)) - .with_attrs(fold_thin_attrs(attrs, fld)) + let fl = ast::ExprKind::ForLoop(rewritten_pats.remove(0), head, body, opt_ident); + fld.cx.expr(span, fl).with_attrs(fold_thin_attrs(attrs, fld)) } - ast::ExprIfLet(pat, sub_expr, body, else_opt) => { + ast::ExprKind::IfLet(pat, sub_expr, body, else_opt) => { let pat = fld.fold_pat(pat); // Hygienic renaming of the body. @@ -146,14 +145,14 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> { let else_opt = else_opt.map(|else_opt| fld.fold_expr(else_opt)); let sub_expr = fld.fold_expr(sub_expr); - fld.cx.expr(span, ast::ExprIfLet(rewritten_pats.remove(0), sub_expr, body, else_opt)) - .with_attrs(fold_thin_attrs(attrs, fld)) + let il = ast::ExprKind::IfLet(rewritten_pats.remove(0), sub_expr, body, else_opt); + fld.cx.expr(span, il).with_attrs(fold_thin_attrs(attrs, fld)) } - ast::ExprClosure(capture_clause, fn_decl, block) => { + ast::ExprKind::Closure(capture_clause, fn_decl, block) => { let (rewritten_fn_decl, rewritten_block) = expand_and_rename_fn_decl_and_block(fn_decl, block, fld); - let new_node = ast::ExprClosure(capture_clause, + let new_node = ast::ExprKind::Closure(capture_clause, rewritten_fn_decl, rewritten_block); P(ast::Expr{id:id, node: new_node, span: fld.new_span(span), @@ -316,17 +315,17 @@ pub fn expand_item(it: P<ast::Item>, fld: &mut MacroExpander) .into_iter().map(|i| i.expect_item()).collect() } -/// Expand item_underscore -fn expand_item_underscore(item: ast::Item_, fld: &mut MacroExpander) -> ast::Item_ { +/// Expand item_kind +fn expand_item_kind(item: ast::ItemKind, fld: &mut MacroExpander) -> ast::ItemKind { match item { - ast::ItemFn(decl, unsafety, constness, abi, generics, body) => { + ast::ItemKind::Fn(decl, unsafety, constness, abi, generics, body) => { let (rewritten_fn_decl, rewritten_body) = expand_and_rename_fn_decl_and_block(decl, body, fld); let expanded_generics = fold::noop_fold_generics(generics,fld); - ast::ItemFn(rewritten_fn_decl, unsafety, constness, abi, + ast::ItemKind::Fn(rewritten_fn_decl, unsafety, constness, abi, expanded_generics, rewritten_body) } - _ => noop_fold_item_underscore(item, fld) + _ => noop_fold_item_kind(item, fld) } } @@ -349,7 +348,7 @@ fn contains_macro_use(fld: &mut MacroExpander, attrs: &[ast::Attribute]) -> bool if is_use { match attr.node.value.node { - ast::MetaWord(..) => (), + ast::MetaItemKind::Word(..) => (), _ => fld.cx.span_err(attr.span, "arguments to macro_use are not allowed here"), } return true; @@ -363,7 +362,7 @@ fn contains_macro_use(fld: &mut MacroExpander, attrs: &[ast::Attribute]) -> bool pub fn expand_item_mac(it: P<ast::Item>, fld: &mut MacroExpander) -> SmallVector<P<ast::Item>> { let (extname, path_span, tts, span, attrs, ident) = it.and_then(|it| match it.node { - ItemMac(codemap::Spanned { node: Mac_ { path, tts, .. }, .. }) => + ItemKind::Mac(codemap::Spanned { node: Mac_ { path, tts, .. }, .. }) => (path.segments[0].identifier.name, path.span, tts, it.span, it.attrs, it.ident), _ => fld.cx.span_bug(it.span, "invalid item macro invocation") }); @@ -507,7 +506,7 @@ pub fn expand_item_mac(it: P<ast::Item>, fn expand_stmt(stmt: P<Stmt>, fld: &mut MacroExpander) -> SmallVector<P<Stmt>> { let stmt = stmt.and_then(|stmt| stmt); let (mac, style, attrs) = match stmt.node { - StmtMac(mac, style, attrs) => (mac, style, attrs), + StmtKind::Mac(mac, style, attrs) => (mac, style, attrs), _ => return expand_non_macro_stmt(stmt, fld) }; @@ -534,12 +533,12 @@ fn expand_stmt(stmt: P<Stmt>, fld: &mut MacroExpander) -> SmallVector<P<Stmt>> { // If this is a macro invocation with a semicolon, then apply that // semicolon to the final statement produced by expansion. - if style == MacStmtWithSemicolon { + if style == MacStmtStyle::Semicolon { if let Some(stmt) = fully_expanded.pop() { let new_stmt = stmt.map(|Spanned {node, span}| { Spanned { node: match node { - StmtExpr(e, stmt_id) => StmtSemi(e, stmt_id), + StmtKind::Expr(e, stmt_id) => StmtKind::Semi(e, stmt_id), _ => node /* might already have a semi */ }, span: span @@ -558,11 +557,11 @@ fn expand_non_macro_stmt(Spanned {node, span: stmt_span}: Stmt, fld: &mut MacroE -> SmallVector<P<Stmt>> { // is it a let? match node { - StmtDecl(decl, node_id) => decl.and_then(|Spanned {node: decl, span}| match decl { - DeclLocal(local) => { + StmtKind::Decl(decl, node_id) => decl.and_then(|Spanned {node: decl, span}| match decl { + DeclKind::Local(local) => { // take it apart: let rewritten_local = local.map(|Local {id, pat, ty, init, span, attrs}| { - // expand the ty since TyFixedLengthVec contains an Expr + // expand the ty since TyKind::FixedLengthVec contains an Expr // and thus may have a macro use let expanded_ty = ty.map(|t| fld.fold_ty(t)); // expand the pat (it might contain macro uses): @@ -596,8 +595,8 @@ fn expand_non_macro_stmt(Spanned {node, span: stmt_span}: Stmt, fld: &mut MacroE } }); SmallVector::one(P(Spanned { - node: StmtDecl(P(Spanned { - node: DeclLocal(rewritten_local), + node: StmtKind::Decl(P(Spanned { + node: DeclKind::Local(rewritten_local), span: span }), node_id), @@ -606,7 +605,7 @@ fn expand_non_macro_stmt(Spanned {node, span: stmt_span}: Stmt, fld: &mut MacroE } _ => { noop_fold_stmt(Spanned { - node: StmtDecl(P(Spanned { + node: StmtKind::Decl(P(Spanned { node: decl, span: span }), @@ -891,10 +890,10 @@ fn expand_annotatable(a: Annotatable, let mut new_items: SmallVector<Annotatable> = match a { Annotatable::Item(it) => match it.node { - ast::ItemMac(..) => { + ast::ItemKind::Mac(..) => { expand_item_mac(it, fld).into_iter().map(|i| Annotatable::Item(i)).collect() } - ast::ItemMod(_) | ast::ItemForeignMod(_) => { + ast::ItemKind::Mod(_) | ast::ItemKind::ForeignMod(_) => { let valid_ident = it.ident.name != parse::token::special_idents::invalid.name; @@ -920,14 +919,14 @@ fn expand_annotatable(a: Annotatable, }, Annotatable::TraitItem(it) => match it.node { - ast::MethodTraitItem(_, Some(_)) => SmallVector::one(it.map(|ti| ast::TraitItem { + ast::TraitItemKind::Method(_, Some(_)) => SmallVector::one(it.map(|ti| ast::TraitItem { id: ti.id, ident: ti.ident, attrs: ti.attrs, node: match ti.node { - ast::MethodTraitItem(sig, Some(body)) => { + ast::TraitItemKind::Method(sig, Some(body)) => { let (sig, body) = expand_and_rename_method(sig, body, fld); - ast::MethodTraitItem(sig, Some(body)) + ast::TraitItemKind::Method(sig, Some(body)) } _ => unreachable!() }, @@ -1049,7 +1048,7 @@ fn expand_item_multi_modifier(mut it: Annotatable, } } - // Expansion may have added new ItemModifiers. + // Expansion may have added new ItemKind::Modifiers. expand_item_multi_modifier(it, fld) } @@ -1133,7 +1132,7 @@ fn expand_and_rename_method(sig: ast::MethodSig, body: P<ast::Block>, pub fn expand_type(t: P<ast::Ty>, fld: &mut MacroExpander) -> P<ast::Ty> { let t = match t.node.clone() { - ast::Ty_::TyMac(mac) => { + ast::TyKind::Mac(mac) => { if fld.cx.ecfg.features.unwrap().type_macros { let expanded_ty = match expand_mac_invoc(mac, t.span, |r| r.make_ty(), @@ -1195,8 +1194,8 @@ impl<'a, 'b> Folder for MacroExpander<'a, 'b> { expand_item(item, self) } - fn fold_item_underscore(&mut self, item: ast::Item_) -> ast::Item_ { - expand_item_underscore(item, self) + fn fold_item_kind(&mut self, item: ast::ItemKind) -> ast::ItemKind { + expand_item_kind(item, self) } fn fold_stmt(&mut self, stmt: P<ast::Stmt>) -> SmallVector<P<ast::Stmt>> { @@ -1427,7 +1426,7 @@ mod tests { impl<'v> Visitor<'v> for PathExprFinderContext { fn visit_expr(&mut self, expr: &ast::Expr) { - if let ast::ExprPath(None, ref p) = expr.node { + if let ast::ExprKind::Path(None, ref p) = expr.node { self.path_accumulator.push(p.clone()); } visit::walk_expr(self, expr); @@ -1694,7 +1693,7 @@ mod tests { 0) } - // closure arg hygiene (ExprClosure) + // closure arg hygiene (ExprKind::Closure) // expands to fn f(){(|x_1 : i32| {(x_2 + x_1)})(3);} #[test] fn closure_arg_hygiene(){ diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index bc7dc67e1ba..57db1347021 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -218,8 +218,8 @@ pub mod rt { impl ToTokens for str { fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> { - let lit = ast::LitStr( - token::intern_and_get_ident(self), ast::CookedStr); + let lit = ast::LitKind::Str( + token::intern_and_get_ident(self), ast::StrStyle::Cooked); dummy_spanned(lit).to_tokens(cx) } } @@ -240,7 +240,7 @@ pub mod rt { // FIXME: This is wrong P(ast::Expr { id: ast::DUMMY_NODE_ID, - node: ast::ExprLit(P(self.clone())), + node: ast::ExprKind::Lit(P(self.clone())), span: DUMMY_SP, attrs: None, }).to_tokens(cx) @@ -249,13 +249,13 @@ pub mod rt { impl ToTokens for bool { fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> { - dummy_spanned(ast::LitBool(*self)).to_tokens(cx) + dummy_spanned(ast::LitKind::Bool(*self)).to_tokens(cx) } } impl ToTokens for char { fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> { - dummy_spanned(ast::LitChar(*self)).to_tokens(cx) + dummy_spanned(ast::LitKind::Char(*self)).to_tokens(cx) } } @@ -263,33 +263,51 @@ pub mod rt { (signed, $t:ty, $tag:expr) => ( impl ToTokens for $t { fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> { - let lit = ast::LitInt(*self as u64, ast::SignedIntLit($tag, - ast::Sign::new(*self))); - dummy_spanned(lit).to_tokens(cx) + let val = if *self < 0 { + -self + } else { + *self + }; + let lit = ast::LitKind::Int(val as u64, ast::LitIntType::Signed($tag)); + let lit = P(ast::Expr { + id: ast::DUMMY_NODE_ID, + node: ast::ExprKind::Lit(P(dummy_spanned(lit))), + span: DUMMY_SP, + attrs: None, + }); + if *self >= 0 { + return lit.to_tokens(cx); + } + P(ast::Expr { + id: ast::DUMMY_NODE_ID, + node: ast::ExprKind::Unary(ast::UnOp::Neg, lit), + span: DUMMY_SP, + attrs: None, + }).to_tokens(cx) } } ); (unsigned, $t:ty, $tag:expr) => ( impl ToTokens for $t { fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> { - let lit = ast::LitInt(*self as u64, ast::UnsignedIntLit($tag)); + let lit = ast::LitKind::Int(*self as u64, ast::LitIntType::Unsigned($tag)); dummy_spanned(lit).to_tokens(cx) } } ); } - impl_to_tokens_int! { signed, isize, ast::TyIs } - impl_to_tokens_int! { signed, i8, ast::TyI8 } - impl_to_tokens_int! { signed, i16, ast::TyI16 } - impl_to_tokens_int! { signed, i32, ast::TyI32 } - impl_to_tokens_int! { signed, i64, ast::TyI64 } + impl_to_tokens_int! { signed, isize, ast::IntTy::Is } + impl_to_tokens_int! { signed, i8, ast::IntTy::I8 } + impl_to_tokens_int! { signed, i16, ast::IntTy::I16 } + impl_to_tokens_int! { signed, i32, ast::IntTy::I32 } + impl_to_tokens_int! { signed, i64, ast::IntTy::I64 } - impl_to_tokens_int! { unsigned, usize, ast::TyUs } - impl_to_tokens_int! { unsigned, u8, ast::TyU8 } - impl_to_tokens_int! { unsigned, u16, ast::TyU16 } - impl_to_tokens_int! { unsigned, u32, ast::TyU32 } - impl_to_tokens_int! { unsigned, u64, ast::TyU64 } + impl_to_tokens_int! { unsigned, usize, ast::UintTy::Us } + impl_to_tokens_int! { unsigned, u8, ast::UintTy::U8 } + impl_to_tokens_int! { unsigned, u16, ast::UintTy::U16 } + impl_to_tokens_int! { unsigned, u32, ast::UintTy::U32 } + impl_to_tokens_int! { unsigned, u64, ast::UintTy::U64 } pub trait ExtParseUtils { fn parse_item(&self, s: String) -> P<ast::Item>; @@ -524,11 +542,6 @@ fn mk_tt_path(cx: &ExtCtxt, sp: Span, name: &str) -> P<ast::Expr> { cx.expr_path(cx.path_global(sp, idents)) } -fn mk_ast_path(cx: &ExtCtxt, sp: Span, name: &str) -> P<ast::Expr> { - let idents = vec!(id_ext("syntax"), id_ext("ast"), id_ext(name)); - cx.expr_path(cx.path_global(sp, idents)) -} - fn mk_token_path(cx: &ExtCtxt, sp: Span, name: &str) -> P<ast::Expr> { let idents = vec!(id_ext("syntax"), id_ext("parse"), id_ext("token"), id_ext(name)); cx.expr_path(cx.path_global(sp, idents)) @@ -761,9 +774,16 @@ fn statements_mk_tt(cx: &ExtCtxt, tt: &TokenTree, matcher: bool) -> Vec<P<ast::S None => cx.expr_none(sp), }; let e_op = match seq.op { - ast::ZeroOrMore => mk_ast_path(cx, sp, "ZeroOrMore"), - ast::OneOrMore => mk_ast_path(cx, sp, "OneOrMore"), + ast::KleeneOp::ZeroOrMore => "ZeroOrMore", + ast::KleeneOp::OneOrMore => "OneOrMore", }; + let e_op_idents = vec![ + id_ext("syntax"), + id_ext("ast"), + id_ext("KleeneOp"), + id_ext(e_op), + ]; + let e_op = cx.expr_path(cx.path_global(sp, e_op_idents)); let fields = vec![cx.field_imm(sp, id_ext("tts"), e_tts), cx.field_imm(sp, id_ext("separator"), e_separator), cx.field_imm(sp, id_ext("op"), e_op), @@ -886,7 +906,7 @@ fn expand_wrapper(cx: &ExtCtxt, let stmts = imports.iter().map(|path| { // make item: `use ...;` let path = path.iter().map(|s| s.to_string()).collect(); - cx.stmt_item(sp, cx.item_use_glob(sp, ast::Inherited, ids_ext(path))) + cx.stmt_item(sp, cx.item_use_glob(sp, ast::Visibility::Inherited, ids_ext(path))) }).chain(Some(stmt_let_ext_cx)).collect(); cx.expr_block(cx.block_all(sp, stmts, Some(expr))) diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index f00224bacdd..3e375e1798d 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -187,7 +187,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) let filename = format!("{}", file.display()); cx.codemap().new_filemap_and_lines(&filename, ""); - base::MacEager::expr(cx.expr_lit(sp, ast::LitByteStr(Rc::new(bytes)))) + base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Rc::new(bytes)))) } } } diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index ae8ab054105..9c8ae9460e4 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -374,7 +374,7 @@ pub fn parse(sess: &ParseSess, match ei.top_elts.get_tt(idx) { /* need to descend into sequence */ TokenTree::Sequence(sp, seq) => { - if seq.op == ast::ZeroOrMore { + if seq.op == ast::KleeneOp::ZeroOrMore { let mut new_ei = ei.clone(); new_ei.match_cur += seq.num_captures; new_ei.idx += 1; diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 82fa0f8a8b2..1e9178a55c5 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -248,7 +248,7 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt, TokenTree::Token(DUMMY_SP, token::FatArrow), TokenTree::Token(DUMMY_SP, match_rhs_tok)], separator: Some(token::Semi), - op: ast::OneOrMore, + op: ast::KleeneOp::OneOrMore, num_captures: 2 })), //to phase into semicolon-termination instead of @@ -257,7 +257,7 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt, Rc::new(ast::SequenceRepetition { tts: vec![TokenTree::Token(DUMMY_SP, token::Semi)], separator: None, - op: ast::ZeroOrMore, + op: ast::KleeneOp::ZeroOrMore, num_captures: 0 }))); diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 8878c606d6a..8d857fc8e48 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -81,7 +81,7 @@ pub fn new_tt_reader_with_doc_flag<'a>(sp_diag: &'a Handler, forest: TokenTree::Sequence(DUMMY_SP, Rc::new(ast::SequenceRepetition { tts: src, // doesn't matter. This merely holds the root unzipping. - separator: None, op: ast::ZeroOrMore, num_captures: 0 + separator: None, op: ast::KleeneOp::ZeroOrMore, num_captures: 0 })), idx: 0, dotdotdoted: false, @@ -257,7 +257,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan { } LisConstraint(len, _) => { if len == 0 { - if seq.op == ast::OneOrMore { + if seq.op == ast::KleeneOp::OneOrMore { // FIXME #2887 blame invoker panic!(r.sp_diag.span_fatal(sp.clone(), "this must repeat at least once")); diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 55087c25703..9bf1dd49db5 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -815,11 +815,11 @@ impl<'a, 'v> Visitor<'v> for MacroVisitor<'a> { // But we keep these checks as a pre-expansion check to catch // uses in e.g. conditionalized code. - if let ast::ExprBox(_) = e.node { + if let ast::ExprKind::Box(_) = e.node { self.context.gate_feature("box_syntax", e.span, EXPLAIN_BOX_SYNTAX); } - if let ast::ExprInPlace(..) = e.node { + if let ast::ExprKind::InPlace(..) = e.node { self.context.gate_feature("placement_in_syntax", e.span, EXPLAIN_PLACEMENT_IN); } @@ -855,7 +855,7 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { fn visit_item(&mut self, i: &ast::Item) { match i.node { - ast::ItemExternCrate(_) => { + ast::ItemKind::ExternCrate(_) => { if attr::contains_name(&i.attrs[..], "macro_reexport") { self.gate_feature("macro_reexport", i.span, "macros reexports are experimental \ @@ -863,7 +863,7 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { } } - ast::ItemForeignMod(ref foreign_module) => { + ast::ItemKind::ForeignMod(ref foreign_module) => { if attr::contains_name(&i.attrs[..], "link_args") { self.gate_feature("link_args", i.span, "the `link_args` attribute is not portable \ @@ -888,7 +888,7 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { } } - ast::ItemFn(..) => { + ast::ItemKind::Fn(..) => { if attr::contains_name(&i.attrs[..], "plugin_registrar") { self.gate_feature("plugin_registrar", i.span, "compiler plugins are experimental and possibly buggy"); @@ -907,7 +907,7 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { } } - ast::ItemStruct(..) => { + ast::ItemKind::Struct(..) => { if attr::contains_name(&i.attrs[..], "simd") { self.gate_feature("simd", i.span, "SIMD types are experimental and possibly buggy"); @@ -928,14 +928,14 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { } } - ast::ItemDefaultImpl(..) => { + ast::ItemKind::DefaultImpl(..) => { self.gate_feature("optin_builtin_traits", i.span, "default trait implementations are experimental \ and possibly buggy"); } - ast::ItemImpl(_, polarity, _, _, _, _) => { + ast::ItemKind::Impl(_, polarity, _, _, _, _) => { match polarity { ast::ImplPolarity::Negative => { self.gate_feature("optin_builtin_traits", @@ -988,13 +988,13 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { fn visit_expr(&mut self, e: &ast::Expr) { match e.node { - ast::ExprBox(_) => { + ast::ExprKind::Box(_) => { self.gate_feature("box_syntax", e.span, "box expression syntax is experimental; \ you can call `Box::new` instead."); } - ast::ExprType(..) => { + ast::ExprKind::Type(..) => { self.gate_feature("type_ascription", e.span, "type ascription is experimental"); } @@ -1071,17 +1071,17 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { fn visit_trait_item(&mut self, ti: &'v ast::TraitItem) { match ti.node { - ast::ConstTraitItem(..) => { + ast::TraitItemKind::Const(..) => { self.gate_feature("associated_consts", ti.span, "associated constants are experimental") } - ast::MethodTraitItem(ref sig, _) => { + ast::TraitItemKind::Method(ref sig, _) => { if sig.constness == ast::Constness::Const { self.gate_feature("const_fn", ti.span, "const fn is unstable"); } } - ast::TypeTraitItem(_, Some(_)) => { + ast::TraitItemKind::Type(_, Some(_)) => { self.gate_feature("associated_type_defaults", ti.span, "associated type defaults are unstable"); } @@ -1138,7 +1138,7 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &Handler, Some(list) => { for mi in list { let name = match mi.node { - ast::MetaWord(ref word) => (*word).clone(), + ast::MetaItemKind::Word(ref word) => (*word).clone(), _ => { span_handler.span_err(mi.span, "malformed feature, expected just \ diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 1de6d6c002f..5ae24e6fb24 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -71,8 +71,8 @@ pub trait Folder : Sized { noop_fold_struct_field(sf, self) } - fn fold_item_underscore(&mut self, i: Item_) -> Item_ { - noop_fold_item_underscore(i, self) + fn fold_item_kind(&mut self, i: ItemKind) -> ItemKind { + noop_fold_item_kind(i, self) } fn fold_trait_item(&mut self, i: P<TraitItem>) -> SmallVector<P<TraitItem>> { @@ -184,8 +184,8 @@ pub trait Folder : Sized { noop_fold_explicit_self(es, self) } - fn fold_explicit_self_underscore(&mut self, es: ExplicitSelf_) -> ExplicitSelf_ { - noop_fold_explicit_self_underscore(es, self) + fn fold_explicit_self_kind(&mut self, es: SelfKind) -> SelfKind { + noop_fold_explicit_self_kind(es, self) } fn fold_lifetime(&mut self, l: Lifetime) -> Lifetime { @@ -316,14 +316,14 @@ pub fn noop_fold_view_path<T: Folder>(view_path: P<ViewPath>, fld: &mut T) -> P< path_list_idents.move_map(|path_list_ident| { Spanned { node: match path_list_ident.node { - PathListIdent { id, name, rename } => - PathListIdent { + PathListItemKind::Ident { id, name, rename } => + PathListItemKind::Ident { id: fld.new_id(id), rename: rename, name: name }, - PathListMod { id, rename } => - PathListMod { + PathListItemKind::Mod { id, rename } => + PathListItemKind::Mod { id: fld.new_id(id), rename: rename } @@ -356,12 +356,12 @@ pub fn noop_fold_arm<T: Folder>(Arm {attrs, pats, guard, body}: Arm, fld: &mut T pub fn noop_fold_decl<T: Folder>(d: P<Decl>, fld: &mut T) -> SmallVector<P<Decl>> { d.and_then(|Spanned {node, span}| match node { - DeclLocal(l) => SmallVector::one(P(Spanned { - node: DeclLocal(fld.fold_local(l)), + DeclKind::Local(l) => SmallVector::one(P(Spanned { + node: DeclKind::Local(fld.fold_local(l)), span: fld.new_span(span) })), - DeclItem(it) => fld.fold_item(it).into_iter().map(|i| P(Spanned { - node: DeclItem(i), + DeclKind::Item(it) => fld.fold_item(it).into_iter().map(|i| P(Spanned { + node: DeclKind::Item(i), span: fld.new_span(span) })).collect() }) @@ -380,46 +380,46 @@ pub fn noop_fold_ty<T: Folder>(t: P<Ty>, fld: &mut T) -> P<Ty> { t.map(|Ty {id, node, span}| Ty { id: fld.new_id(id), node: match node { - TyInfer => node, - TyVec(ty) => TyVec(fld.fold_ty(ty)), - TyPtr(mt) => TyPtr(fld.fold_mt(mt)), - TyRptr(region, mt) => { - TyRptr(fld.fold_opt_lifetime(region), fld.fold_mt(mt)) + TyKind::Infer => node, + TyKind::Vec(ty) => TyKind::Vec(fld.fold_ty(ty)), + TyKind::Ptr(mt) => TyKind::Ptr(fld.fold_mt(mt)), + TyKind::Rptr(region, mt) => { + TyKind::Rptr(fld.fold_opt_lifetime(region), fld.fold_mt(mt)) } - TyBareFn(f) => { - TyBareFn(f.map(|BareFnTy {lifetimes, unsafety, abi, decl}| BareFnTy { + TyKind::BareFn(f) => { + TyKind::BareFn(f.map(|BareFnTy {lifetimes, unsafety, abi, decl}| BareFnTy { lifetimes: fld.fold_lifetime_defs(lifetimes), unsafety: unsafety, abi: abi, decl: fld.fold_fn_decl(decl) })) } - TyTup(tys) => TyTup(tys.move_map(|ty| fld.fold_ty(ty))), - TyParen(ty) => TyParen(fld.fold_ty(ty)), - TyPath(qself, path) => { + TyKind::Tup(tys) => TyKind::Tup(tys.move_map(|ty| fld.fold_ty(ty))), + TyKind::Paren(ty) => TyKind::Paren(fld.fold_ty(ty)), + TyKind::Path(qself, path) => { let qself = qself.map(|QSelf { ty, position }| { QSelf { ty: fld.fold_ty(ty), position: position } }); - TyPath(qself, fld.fold_path(path)) + TyKind::Path(qself, fld.fold_path(path)) } - TyObjectSum(ty, bounds) => { - TyObjectSum(fld.fold_ty(ty), + TyKind::ObjectSum(ty, bounds) => { + TyKind::ObjectSum(fld.fold_ty(ty), fld.fold_bounds(bounds)) } - TyFixedLengthVec(ty, e) => { - TyFixedLengthVec(fld.fold_ty(ty), fld.fold_expr(e)) + TyKind::FixedLengthVec(ty, e) => { + TyKind::FixedLengthVec(fld.fold_ty(ty), fld.fold_expr(e)) } - TyTypeof(expr) => { - TyTypeof(fld.fold_expr(expr)) + TyKind::Typeof(expr) => { + TyKind::Typeof(fld.fold_expr(expr)) } - TyPolyTraitRef(bounds) => { - TyPolyTraitRef(bounds.move_map(|b| fld.fold_ty_param_bound(b))) + TyKind::PolyTraitRef(bounds) => { + TyKind::PolyTraitRef(bounds.move_map(|b| fld.fold_ty_param_bound(b))) } - TyMac(mac) => { - TyMac(fld.fold_mac(mac)) + TyKind::Mac(mac) => { + TyKind::Mac(fld.fold_mac(mac)) } }, span: fld.new_span(span) @@ -520,15 +520,15 @@ pub fn noop_fold_attribute<T: Folder>(at: Attribute, fld: &mut T) -> Option<Attr }) } -pub fn noop_fold_explicit_self_underscore<T: Folder>(es: ExplicitSelf_, fld: &mut T) - -> ExplicitSelf_ { +pub fn noop_fold_explicit_self_kind<T: Folder>(es: SelfKind, fld: &mut T) + -> SelfKind { match es { - SelfStatic | SelfValue(_) => es, - SelfRegion(lifetime, m, ident) => { - SelfRegion(fld.fold_opt_lifetime(lifetime), m, ident) + SelfKind::Static | SelfKind::Value(_) => es, + SelfKind::Region(lifetime, m, ident) => { + SelfKind::Region(fld.fold_opt_lifetime(lifetime), m, ident) } - SelfExplicit(typ, ident) => { - SelfExplicit(fld.fold_ty(typ), ident) + SelfKind::Explicit(typ, ident) => { + SelfKind::Explicit(fld.fold_ty(typ), ident) } } } @@ -536,7 +536,7 @@ pub fn noop_fold_explicit_self_underscore<T: Folder>(es: ExplicitSelf_, fld: &mu pub fn noop_fold_explicit_self<T: Folder>(Spanned {span, node}: ExplicitSelf, fld: &mut T) -> ExplicitSelf { Spanned { - node: fld.fold_explicit_self_underscore(node), + node: fld.fold_explicit_self_kind(node), span: fld.new_span(span) } } @@ -556,11 +556,11 @@ pub fn noop_fold_mac<T: Folder>(Spanned {node, span}: Mac, fld: &mut T) -> Mac { pub fn noop_fold_meta_item<T: Folder>(mi: P<MetaItem>, fld: &mut T) -> P<MetaItem> { mi.map(|Spanned {node, span}| Spanned { node: match node { - MetaWord(id) => MetaWord(id), - MetaList(id, mis) => { - MetaList(id, mis.move_map(|e| fld.fold_meta_item(e))) + MetaItemKind::Word(id) => MetaItemKind::Word(id), + MetaItemKind::List(id, mis) => { + MetaItemKind::List(id, mis.move_map(|e| fld.fold_meta_item(e))) } - MetaNameValue(id, s) => MetaNameValue(id, s) + MetaItemKind::NameValue(id, s) => MetaItemKind::NameValue(id, s) }, span: fld.new_span(span) }) @@ -685,9 +685,9 @@ pub fn noop_fold_fn_decl<T: Folder>(decl: P<FnDecl>, fld: &mut T) -> P<FnDecl> { decl.map(|FnDecl {inputs, output, variadic}| FnDecl { inputs: inputs.move_map(|x| fld.fold_arg(x)), output: match output { - Return(ty) => Return(fld.fold_ty(ty)), - DefaultReturn(span) => DefaultReturn(span), - NoReturn(span) => NoReturn(span) + FunctionRetTy::Ty(ty) => FunctionRetTy::Ty(fld.fold_ty(ty)), + FunctionRetTy::Default(span) => FunctionRetTy::Default(span), + FunctionRetTy::None(span) => FunctionRetTy::None(span), }, variadic: variadic }) @@ -890,20 +890,20 @@ pub fn noop_fold_block<T: Folder>(b: P<Block>, folder: &mut T) -> P<Block> { }) } -pub fn noop_fold_item_underscore<T: Folder>(i: Item_, folder: &mut T) -> Item_ { +pub fn noop_fold_item_kind<T: Folder>(i: ItemKind, folder: &mut T) -> ItemKind { match i { - ItemExternCrate(string) => ItemExternCrate(string), - ItemUse(view_path) => { - ItemUse(folder.fold_view_path(view_path)) + ItemKind::ExternCrate(string) => ItemKind::ExternCrate(string), + ItemKind::Use(view_path) => { + ItemKind::Use(folder.fold_view_path(view_path)) } - ItemStatic(t, m, e) => { - ItemStatic(folder.fold_ty(t), m, folder.fold_expr(e)) + ItemKind::Static(t, m, e) => { + ItemKind::Static(folder.fold_ty(t), m, folder.fold_expr(e)) } - ItemConst(t, e) => { - ItemConst(folder.fold_ty(t), folder.fold_expr(e)) + ItemKind::Const(t, e) => { + ItemKind::Const(folder.fold_ty(t), folder.fold_expr(e)) } - ItemFn(decl, unsafety, constness, abi, generics, body) => { - ItemFn( + ItemKind::Fn(decl, unsafety, constness, abi, generics, body) => { + ItemKind::Fn( folder.fold_fn_decl(decl), unsafety, constness, @@ -912,26 +912,26 @@ pub fn noop_fold_item_underscore<T: Folder>(i: Item_, folder: &mut T) -> Item_ { folder.fold_block(body) ) } - ItemMod(m) => ItemMod(folder.fold_mod(m)), - ItemForeignMod(nm) => ItemForeignMod(folder.fold_foreign_mod(nm)), - ItemTy(t, generics) => { - ItemTy(folder.fold_ty(t), folder.fold_generics(generics)) + ItemKind::Mod(m) => ItemKind::Mod(folder.fold_mod(m)), + ItemKind::ForeignMod(nm) => ItemKind::ForeignMod(folder.fold_foreign_mod(nm)), + ItemKind::Ty(t, generics) => { + ItemKind::Ty(folder.fold_ty(t), folder.fold_generics(generics)) } - ItemEnum(enum_definition, generics) => { - ItemEnum( + ItemKind::Enum(enum_definition, generics) => { + ItemKind::Enum( ast::EnumDef { variants: enum_definition.variants.move_map(|x| folder.fold_variant(x)), }, folder.fold_generics(generics)) } - ItemStruct(struct_def, generics) => { + ItemKind::Struct(struct_def, generics) => { let struct_def = folder.fold_variant_data(struct_def); - ItemStruct(struct_def, folder.fold_generics(generics)) + ItemKind::Struct(struct_def, folder.fold_generics(generics)) } - ItemDefaultImpl(unsafety, ref trait_ref) => { - ItemDefaultImpl(unsafety, folder.fold_trait_ref((*trait_ref).clone())) + ItemKind::DefaultImpl(unsafety, ref trait_ref) => { + ItemKind::DefaultImpl(unsafety, folder.fold_trait_ref((*trait_ref).clone())) } - ItemImpl(unsafety, polarity, generics, ifce, ty, impl_items) => { + ItemKind::Impl(unsafety, polarity, generics, ifce, ty, impl_items) => { let new_impl_items = impl_items.move_flat_map(|item| { folder.fold_impl_item(item) }); @@ -941,24 +941,24 @@ pub fn noop_fold_item_underscore<T: Folder>(i: Item_, folder: &mut T) -> Item_ { Some(folder.fold_trait_ref((*trait_ref).clone())) } }; - ItemImpl(unsafety, + ItemKind::Impl(unsafety, polarity, folder.fold_generics(generics), ifce, folder.fold_ty(ty), new_impl_items) } - ItemTrait(unsafety, generics, bounds, items) => { + ItemKind::Trait(unsafety, generics, bounds, items) => { let bounds = folder.fold_bounds(bounds); let items = items.move_flat_map(|item| { folder.fold_trait_item(item) }); - ItemTrait(unsafety, + ItemKind::Trait(unsafety, folder.fold_generics(generics), bounds, items) } - ItemMac(m) => ItemMac(folder.fold_mac(m)), + ItemKind::Mac(m) => ItemKind::Mac(folder.fold_mac(m)), } } @@ -969,16 +969,16 @@ pub fn noop_fold_trait_item<T: Folder>(i: P<TraitItem>, folder: &mut T) ident: folder.fold_ident(ident), attrs: fold_attrs(attrs, folder), node: match node { - ConstTraitItem(ty, default) => { - ConstTraitItem(folder.fold_ty(ty), + TraitItemKind::Const(ty, default) => { + TraitItemKind::Const(folder.fold_ty(ty), default.map(|x| folder.fold_expr(x))) } - MethodTraitItem(sig, body) => { - MethodTraitItem(noop_fold_method_sig(sig, folder), + TraitItemKind::Method(sig, body) => { + TraitItemKind::Method(noop_fold_method_sig(sig, folder), body.map(|x| folder.fold_block(x))) } - TypeTraitItem(bounds, default) => { - TypeTraitItem(folder.fold_bounds(bounds), + TraitItemKind::Type(bounds, default) => { + TraitItemKind::Type(folder.fold_bounds(bounds), default.map(|x| folder.fold_ty(x))) } }, @@ -1023,9 +1023,9 @@ pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, config, mut exported_mac ident: token::special_idents::invalid, attrs: attrs, id: ast::DUMMY_NODE_ID, - vis: ast::Public, + vis: ast::Visibility::Public, span: span, - node: ast::ItemMod(module), + node: ast::ItemKind::Mod(module), })).into_iter(); let (module, attrs, span) = match items.next() { @@ -1034,7 +1034,7 @@ pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, config, mut exported_mac "a crate cannot expand to more than one item"); item.and_then(|ast::Item { attrs, span, node, .. }| { match node { - ast::ItemMod(m) => (m, attrs, span), + ast::ItemKind::Mod(m) => (m, attrs, span), _ => panic!("fold converted a module to not a module"), } }) @@ -1067,10 +1067,10 @@ pub fn noop_fold_item<T: Folder>(i: P<Item>, folder: &mut T) -> SmallVector<P<It pub fn noop_fold_item_simple<T: Folder>(Item {id, ident, attrs, node, vis, span}: Item, folder: &mut T) -> Item { let id = folder.new_id(id); - let node = folder.fold_item_underscore(node); + let node = folder.fold_item_kind(node); let ident = match node { // The node may have changed, recompute the "pretty" impl name. - ItemImpl(_, _, _, ref maybe_trait, ref ty, _) => { + ItemKind::Impl(_, _, _, ref maybe_trait, ref ty, _) => { ast_util::impl_pretty_name(maybe_trait, Some(&**ty)) } _ => ident @@ -1092,11 +1092,11 @@ pub fn noop_fold_foreign_item<T: Folder>(ni: P<ForeignItem>, folder: &mut T) -> ident: folder.fold_ident(ident), attrs: fold_attrs(attrs, folder), node: match node { - ForeignItemFn(fdec, generics) => { - ForeignItemFn(folder.fold_fn_decl(fdec), folder.fold_generics(generics)) + ForeignItemKind::Fn(fdec, generics) => { + ForeignItemKind::Fn(folder.fold_fn_decl(fdec), folder.fold_generics(generics)) } - ForeignItemStatic(t, m) => { - ForeignItemStatic(folder.fold_ty(t), m) + ForeignItemKind::Static(t, m) => { + ForeignItemKind::Static(folder.fold_ty(t), m) } }, vis: vis, @@ -1168,131 +1168,131 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span, attrs}: Expr, folder: &mu Expr { id: folder.new_id(id), node: match node { - ExprBox(e) => { - ExprBox(folder.fold_expr(e)) + ExprKind::Box(e) => { + ExprKind::Box(folder.fold_expr(e)) } - ExprInPlace(p, e) => { - ExprInPlace(folder.fold_expr(p), folder.fold_expr(e)) + ExprKind::InPlace(p, e) => { + ExprKind::InPlace(folder.fold_expr(p), folder.fold_expr(e)) } - ExprVec(exprs) => { - ExprVec(folder.fold_exprs(exprs)) + ExprKind::Vec(exprs) => { + ExprKind::Vec(folder.fold_exprs(exprs)) } - ExprRepeat(expr, count) => { - ExprRepeat(folder.fold_expr(expr), folder.fold_expr(count)) + ExprKind::Repeat(expr, count) => { + ExprKind::Repeat(folder.fold_expr(expr), folder.fold_expr(count)) } - ExprTup(exprs) => ExprTup(folder.fold_exprs(exprs)), - ExprCall(f, args) => { - ExprCall(folder.fold_expr(f), + ExprKind::Tup(exprs) => ExprKind::Tup(folder.fold_exprs(exprs)), + ExprKind::Call(f, args) => { + ExprKind::Call(folder.fold_expr(f), folder.fold_exprs(args)) } - ExprMethodCall(i, tps, args) => { - ExprMethodCall( + ExprKind::MethodCall(i, tps, args) => { + ExprKind::MethodCall( respan(folder.new_span(i.span), folder.fold_ident(i.node)), tps.move_map(|x| folder.fold_ty(x)), folder.fold_exprs(args)) } - ExprBinary(binop, lhs, rhs) => { - ExprBinary(binop, + ExprKind::Binary(binop, lhs, rhs) => { + ExprKind::Binary(binop, folder.fold_expr(lhs), folder.fold_expr(rhs)) } - ExprUnary(binop, ohs) => { - ExprUnary(binop, folder.fold_expr(ohs)) + ExprKind::Unary(binop, ohs) => { + ExprKind::Unary(binop, folder.fold_expr(ohs)) } - ExprLit(l) => ExprLit(l), - ExprCast(expr, ty) => { - ExprCast(folder.fold_expr(expr), folder.fold_ty(ty)) + ExprKind::Lit(l) => ExprKind::Lit(l), + ExprKind::Cast(expr, ty) => { + ExprKind::Cast(folder.fold_expr(expr), folder.fold_ty(ty)) } - ExprType(expr, ty) => { - ExprType(folder.fold_expr(expr), folder.fold_ty(ty)) + ExprKind::Type(expr, ty) => { + ExprKind::Type(folder.fold_expr(expr), folder.fold_ty(ty)) } - ExprAddrOf(m, ohs) => ExprAddrOf(m, folder.fold_expr(ohs)), - ExprIf(cond, tr, fl) => { - ExprIf(folder.fold_expr(cond), + ExprKind::AddrOf(m, ohs) => ExprKind::AddrOf(m, folder.fold_expr(ohs)), + ExprKind::If(cond, tr, fl) => { + ExprKind::If(folder.fold_expr(cond), folder.fold_block(tr), fl.map(|x| folder.fold_expr(x))) } - ExprIfLet(pat, expr, tr, fl) => { - ExprIfLet(folder.fold_pat(pat), + ExprKind::IfLet(pat, expr, tr, fl) => { + ExprKind::IfLet(folder.fold_pat(pat), folder.fold_expr(expr), folder.fold_block(tr), fl.map(|x| folder.fold_expr(x))) } - ExprWhile(cond, body, opt_ident) => { - ExprWhile(folder.fold_expr(cond), + ExprKind::While(cond, body, opt_ident) => { + ExprKind::While(folder.fold_expr(cond), folder.fold_block(body), opt_ident.map(|i| folder.fold_ident(i))) } - ExprWhileLet(pat, expr, body, opt_ident) => { - ExprWhileLet(folder.fold_pat(pat), + ExprKind::WhileLet(pat, expr, body, opt_ident) => { + ExprKind::WhileLet(folder.fold_pat(pat), folder.fold_expr(expr), folder.fold_block(body), opt_ident.map(|i| folder.fold_ident(i))) } - ExprForLoop(pat, iter, body, opt_ident) => { - ExprForLoop(folder.fold_pat(pat), + ExprKind::ForLoop(pat, iter, body, opt_ident) => { + ExprKind::ForLoop(folder.fold_pat(pat), folder.fold_expr(iter), folder.fold_block(body), opt_ident.map(|i| folder.fold_ident(i))) } - ExprLoop(body, opt_ident) => { - ExprLoop(folder.fold_block(body), + ExprKind::Loop(body, opt_ident) => { + ExprKind::Loop(folder.fold_block(body), opt_ident.map(|i| folder.fold_ident(i))) } - ExprMatch(expr, arms) => { - ExprMatch(folder.fold_expr(expr), + ExprKind::Match(expr, arms) => { + ExprKind::Match(folder.fold_expr(expr), arms.move_map(|x| folder.fold_arm(x))) } - ExprClosure(capture_clause, decl, body) => { - ExprClosure(capture_clause, + ExprKind::Closure(capture_clause, decl, body) => { + ExprKind::Closure(capture_clause, folder.fold_fn_decl(decl), folder.fold_block(body)) } - ExprBlock(blk) => ExprBlock(folder.fold_block(blk)), - ExprAssign(el, er) => { - ExprAssign(folder.fold_expr(el), folder.fold_expr(er)) + ExprKind::Block(blk) => ExprKind::Block(folder.fold_block(blk)), + ExprKind::Assign(el, er) => { + ExprKind::Assign(folder.fold_expr(el), folder.fold_expr(er)) } - ExprAssignOp(op, el, er) => { - ExprAssignOp(op, + ExprKind::AssignOp(op, el, er) => { + ExprKind::AssignOp(op, folder.fold_expr(el), folder.fold_expr(er)) } - ExprField(el, ident) => { - ExprField(folder.fold_expr(el), + ExprKind::Field(el, ident) => { + ExprKind::Field(folder.fold_expr(el), respan(folder.new_span(ident.span), folder.fold_ident(ident.node))) } - ExprTupField(el, ident) => { - ExprTupField(folder.fold_expr(el), + ExprKind::TupField(el, ident) => { + ExprKind::TupField(folder.fold_expr(el), respan(folder.new_span(ident.span), folder.fold_usize(ident.node))) } - ExprIndex(el, er) => { - ExprIndex(folder.fold_expr(el), folder.fold_expr(er)) + ExprKind::Index(el, er) => { + ExprKind::Index(folder.fold_expr(el), folder.fold_expr(er)) } - ExprRange(e1, e2) => { - ExprRange(e1.map(|x| folder.fold_expr(x)), + ExprKind::Range(e1, e2) => { + ExprKind::Range(e1.map(|x| folder.fold_expr(x)), e2.map(|x| folder.fold_expr(x))) } - ExprPath(qself, path) => { + ExprKind::Path(qself, path) => { let qself = qself.map(|QSelf { ty, position }| { QSelf { ty: folder.fold_ty(ty), position: position } }); - ExprPath(qself, folder.fold_path(path)) + ExprKind::Path(qself, folder.fold_path(path)) } - ExprBreak(opt_ident) => ExprBreak(opt_ident.map(|label| + ExprKind::Break(opt_ident) => ExprKind::Break(opt_ident.map(|label| respan(folder.new_span(label.span), folder.fold_ident(label.node))) ), - ExprAgain(opt_ident) => ExprAgain(opt_ident.map(|label| + ExprKind::Again(opt_ident) => ExprKind::Again(opt_ident.map(|label| respan(folder.new_span(label.span), folder.fold_ident(label.node))) ), - ExprRet(e) => ExprRet(e.map(|x| folder.fold_expr(x))), - ExprInlineAsm(InlineAsm { + ExprKind::Ret(e) => ExprKind::Ret(e.map(|x| folder.fold_expr(x))), + ExprKind::InlineAsm(InlineAsm { inputs, outputs, asm, @@ -1302,7 +1302,7 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span, attrs}: Expr, folder: &mu alignstack, dialect, expn_id, - }) => ExprInlineAsm(InlineAsm { + }) => ExprKind::InlineAsm(InlineAsm { inputs: inputs.move_map(|(c, input)| { (c, folder.fold_expr(input)) }), @@ -1322,13 +1322,13 @@ pub fn noop_fold_expr<T: Folder>(Expr {id, node, span, attrs}: Expr, folder: &mu dialect: dialect, expn_id: expn_id, }), - ExprMac(mac) => ExprMac(folder.fold_mac(mac)), - ExprStruct(path, fields, maybe_expr) => { - ExprStruct(folder.fold_path(path), + ExprKind::Mac(mac) => ExprKind::Mac(folder.fold_mac(mac)), + ExprKind::Struct(path, fields, maybe_expr) => { + ExprKind::Struct(folder.fold_path(path), fields.move_map(|x| folder.fold_field(x)), maybe_expr.map(|x| folder.fold_expr(x))) }, - ExprParen(ex) => ExprParen(folder.fold_expr(ex)) + ExprKind::Paren(ex) => ExprKind::Paren(folder.fold_expr(ex)) }, span: folder.new_span(span), attrs: attrs.map_thin_attrs(|v| fold_attrs(v, folder)), @@ -1347,39 +1347,39 @@ pub fn noop_fold_stmt<T: Folder>(Spanned {node, span}: Stmt, folder: &mut T) -> SmallVector<P<Stmt>> { let span = folder.new_span(span); match node { - StmtDecl(d, id) => { + StmtKind::Decl(d, id) => { let id = folder.new_id(id); folder.fold_decl(d).into_iter().map(|d| P(Spanned { - node: StmtDecl(d, id), + node: StmtKind::Decl(d, id), span: span })).collect() } - StmtExpr(e, id) => { + StmtKind::Expr(e, id) => { let id = folder.new_id(id); if let Some(e) = folder.fold_opt_expr(e) { SmallVector::one(P(Spanned { - node: StmtExpr(e, id), + node: StmtKind::Expr(e, id), span: span })) } else { SmallVector::zero() } } - StmtSemi(e, id) => { + StmtKind::Semi(e, id) => { let id = folder.new_id(id); if let Some(e) = folder.fold_opt_expr(e) { SmallVector::one(P(Spanned { - node: StmtSemi(e, id), + node: StmtKind::Semi(e, id), span: span })) } else { SmallVector::zero() } } - StmtMac(mac, semi, attrs) => SmallVector::one(P(Spanned { - node: StmtMac(mac.map(|m| folder.fold_mac(m)), - semi, - attrs.map_thin_attrs(|v| fold_attrs(v, folder))), + StmtKind::Mac(mac, semi, attrs) => SmallVector::one(P(Spanned { + node: StmtKind::Mac(mac.map(|m| folder.fold_mac(m)), + semi, + attrs.map_thin_attrs(|v| fold_attrs(v, folder))), span: span })) } diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index 96ac9b83d2f..505e543a3fb 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -175,23 +175,23 @@ impl<'a> Parser<'a> { // FIXME #623 Non-string meta items are not serialized correctly; // just forbid them for now match lit.node { - ast::LitStr(..) => {} + ast::LitKind::Str(..) => {} _ => { self.span_err(lit.span, "non-string literals are not allowed in meta-items"); } } let hi = self.span.hi; - Ok(P(spanned(lo, hi, ast::MetaNameValue(name, lit)))) + Ok(P(spanned(lo, hi, ast::MetaItemKind::NameValue(name, lit)))) } token::OpenDelim(token::Paren) => { let inner_items = try!(self.parse_meta_seq()); let hi = self.span.hi; - Ok(P(spanned(lo, hi, ast::MetaList(name, inner_items)))) + Ok(P(spanned(lo, hi, ast::MetaItemKind::List(name, inner_items)))) } _ => { let hi = self.last_span.hi; - Ok(P(spanned(lo, hi, ast::MetaWord(name)))) + Ok(P(spanned(lo, hi, ast::MetaItemKind::Word(name)))) } } } diff --git a/src/libsyntax/parse/classify.rs b/src/libsyntax/parse/classify.rs index 1193224bdb6..89110f3160f 100644 --- a/src/libsyntax/parse/classify.rs +++ b/src/libsyntax/parse/classify.rs @@ -12,7 +12,7 @@ // Predicates on exprs and stmts that the pretty-printer and parser use -use ast; +use ast::{self, BlockCheckMode}; /// Does this expression require a semicolon to be treated /// as a statement? The negation of this: 'can this expression @@ -23,21 +23,21 @@ use ast; /// isn't parsed as (if true {...} else {...} | x) | 5 pub fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool { match e.node { - ast::ExprIf(..) | - ast::ExprIfLet(..) | - ast::ExprMatch(..) | - ast::ExprBlock(_) | - ast::ExprWhile(..) | - ast::ExprWhileLet(..) | - ast::ExprLoop(..) | - ast::ExprForLoop(..) => false, + ast::ExprKind::If(..) | + ast::ExprKind::IfLet(..) | + ast::ExprKind::Match(..) | + ast::ExprKind::Block(_) | + ast::ExprKind::While(..) | + ast::ExprKind::WhileLet(..) | + ast::ExprKind::Loop(..) | + ast::ExprKind::ForLoop(..) => false, _ => true, } } pub fn expr_is_simple_block(e: &ast::Expr) -> bool { match e.node { - ast::ExprBlock(ref block) => block.rules == ast::DefaultBlock, + ast::ExprKind::Block(ref block) => block.rules == BlockCheckMode::Default, _ => false, } } @@ -45,16 +45,16 @@ pub fn expr_is_simple_block(e: &ast::Expr) -> bool { /// this statement requires a semicolon after it. /// note that in one case (stmt_semi), we've already /// seen the semicolon, and thus don't need another. -pub fn stmt_ends_with_semi(stmt: &ast::Stmt_) -> bool { +pub fn stmt_ends_with_semi(stmt: &ast::StmtKind) -> bool { match *stmt { - ast::StmtDecl(ref d, _) => { + ast::StmtKind::Decl(ref d, _) => { match d.node { - ast::DeclLocal(_) => true, - ast::DeclItem(_) => false, + ast::DeclKind::Local(_) => true, + ast::DeclKind::Item(_) => false, } } - ast::StmtExpr(ref e, _) => expr_requires_semi_to_be_stmt(e), - ast::StmtSemi(..) => false, - ast::StmtMac(..) => false, + ast::StmtKind::Expr(ref e, _) => expr_requires_semi_to_be_stmt(e), + ast::StmtKind::Semi(..) => false, + ast::StmtKind::Mac(..) => false, } } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 32372ccc13b..f7060296f1a 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -449,11 +449,11 @@ fn looks_like_width_suffix(first_chars: &[char], s: &str) -> bool { } fn filtered_float_lit(data: token::InternedString, suffix: Option<&str>, - sd: &Handler, sp: Span) -> ast::Lit_ { + sd: &Handler, sp: Span) -> ast::LitKind { debug!("filtered_float_lit: {}, {:?}", data, suffix); match suffix.as_ref().map(|s| &**s) { - Some("f32") => ast::LitFloat(data, ast::TyF32), - Some("f64") => ast::LitFloat(data, ast::TyF64), + Some("f32") => ast::LitKind::Float(data, ast::FloatTy::F32), + Some("f64") => ast::LitKind::Float(data, ast::FloatTy::F64), Some(suf) => { if suf.len() >= 2 && looks_like_width_suffix(&['f'], suf) { // if it looks like a width, lets try to be helpful. @@ -466,13 +466,13 @@ fn filtered_float_lit(data: token::InternedString, suffix: Option<&str>, .emit(); } - ast::LitFloatUnsuffixed(data) + ast::LitKind::FloatUnsuffixed(data) } - None => ast::LitFloatUnsuffixed(data) + None => ast::LitKind::FloatUnsuffixed(data) } } pub fn float_lit(s: &str, suffix: Option<InternedString>, - sd: &Handler, sp: Span) -> ast::Lit_ { + sd: &Handler, sp: Span) -> ast::LitKind { debug!("float_lit: {:?}, {:?}", s, suffix); // FIXME #2252: bounds checking float literals is deferred until trans let s = s.chars().filter(|&c| c != '_').collect::<String>(); @@ -576,7 +576,7 @@ pub fn integer_lit(s: &str, suffix: Option<InternedString>, sd: &Handler, sp: Span) - -> ast::Lit_ { + -> ast::LitKind { // s can only be ascii, byte indexing is fine let s2 = s.chars().filter(|&c| c != '_').collect::<String>(); @@ -586,7 +586,7 @@ pub fn integer_lit(s: &str, let mut base = 10; let orig = s; - let mut ty = ast::UnsuffixedIntLit(ast::Plus); + let mut ty = ast::LitIntType::Unsuffixed; if char_at(s, 0) == '0' && s.len() > 1 { match char_at(s, 1) { @@ -618,16 +618,16 @@ pub fn integer_lit(s: &str, if let Some(ref suf) = suffix { if suf.is_empty() { sd.span_bug(sp, "found empty literal suffix in Some")} ty = match &**suf { - "isize" => ast::SignedIntLit(ast::TyIs, ast::Plus), - "i8" => ast::SignedIntLit(ast::TyI8, ast::Plus), - "i16" => ast::SignedIntLit(ast::TyI16, ast::Plus), - "i32" => ast::SignedIntLit(ast::TyI32, ast::Plus), - "i64" => ast::SignedIntLit(ast::TyI64, ast::Plus), - "usize" => ast::UnsignedIntLit(ast::TyUs), - "u8" => ast::UnsignedIntLit(ast::TyU8), - "u16" => ast::UnsignedIntLit(ast::TyU16), - "u32" => ast::UnsignedIntLit(ast::TyU32), - "u64" => ast::UnsignedIntLit(ast::TyU64), + "isize" => ast::LitIntType::Signed(ast::IntTy::Is), + "i8" => ast::LitIntType::Signed(ast::IntTy::I8), + "i16" => ast::LitIntType::Signed(ast::IntTy::I16), + "i32" => ast::LitIntType::Signed(ast::IntTy::I32), + "i64" => ast::LitIntType::Signed(ast::IntTy::I64), + "usize" => ast::LitIntType::Unsigned(ast::UintTy::Us), + "u8" => ast::LitIntType::Unsigned(ast::UintTy::U8), + "u16" => ast::LitIntType::Unsigned(ast::UintTy::U16), + "u32" => ast::LitIntType::Unsigned(ast::UintTy::U32), + "u64" => ast::LitIntType::Unsigned(ast::UintTy::U64), _ => { // i<digits> and u<digits> look like widths, so lets // give an error message along those lines @@ -651,9 +651,9 @@ pub fn integer_lit(s: &str, debug!("integer_lit: the type is {:?}, base {:?}, the new string is {:?}, the original \ string was {:?}, the original suffix was {:?}", ty, base, s, orig, suffix); - let res = match u64::from_str_radix(s, base).ok() { - Some(r) => r, - None => { + match u64::from_str_radix(s, base) { + Ok(r) => ast::LitKind::Int(r, ty), + Err(_) => { // small bases are lexed as if they were base 10, e.g, the string // might be `0b10201`. This will cause the conversion above to fail, // but these cases have errors in the lexer: we don't want to emit @@ -665,16 +665,8 @@ pub fn integer_lit(s: &str, if !already_errored { sd.span_err(sp, "int literal is too large"); } - 0 + ast::LitKind::Int(0, ty) } - }; - - // adjust the sign - let sign = ast::Sign::new(res); - match ty { - ast::SignedIntLit(t, _) => ast::LitInt(res, ast::SignedIntLit(t, sign)), - ast::UnsuffixedIntLit(_) => ast::LitInt(res, ast::UnsuffixedIntLit(sign)), - us@ast::UnsignedIntLit(_) => ast::LitInt(res, us) } } @@ -684,7 +676,7 @@ mod tests { use std::rc::Rc; use codemap::{Span, BytePos, Pos, Spanned, NO_EXPANSION}; use ast::{self, TokenTree}; - use abi; + use abi::Abi; use attr::{first_attr_value_str_by_name, AttrMetaMethods}; use parse; use parse::parser::Parser; @@ -703,7 +695,7 @@ mod tests { assert!(string_to_expr("a".to_string()) == P(ast::Expr{ id: ast::DUMMY_NODE_ID, - node: ast::ExprPath(None, ast::Path { + node: ast::ExprKind::Path(None, ast::Path { span: sp(0, 1), global: false, segments: vec!( @@ -722,7 +714,7 @@ mod tests { assert!(string_to_expr("::a::b".to_string()) == P(ast::Expr { id: ast::DUMMY_NODE_ID, - node: ast::ExprPath(None, ast::Path { + node: ast::ExprKind::Path(None, ast::Path { span: sp(0, 6), global: true, segments: vec!( @@ -852,9 +844,9 @@ mod tests { assert!(string_to_expr("return d".to_string()) == P(ast::Expr{ id: ast::DUMMY_NODE_ID, - node:ast::ExprRet(Some(P(ast::Expr{ + node:ast::ExprKind::Ret(Some(P(ast::Expr{ id: ast::DUMMY_NODE_ID, - node:ast::ExprPath(None, ast::Path{ + node:ast::ExprKind::Path(None, ast::Path{ span: sp(7, 8), global: false, segments: vec!( @@ -875,9 +867,9 @@ mod tests { #[test] fn parse_stmt_1 () { assert!(string_to_stmt("b;".to_string()) == Some(P(Spanned{ - node: ast::StmtExpr(P(ast::Expr { + node: ast::StmtKind::Expr(P(ast::Expr { id: ast::DUMMY_NODE_ID, - node: ast::ExprPath(None, ast::Path { + node: ast::ExprKind::Path(None, ast::Path { span:sp(0,1), global:false, segments: vec!( @@ -904,7 +896,7 @@ mod tests { assert!(panictry!(parser.parse_pat()) == P(ast::Pat{ id: ast::DUMMY_NODE_ID, - node: ast::PatIdent(ast::BindingMode::ByValue(ast::MutImmutable), + node: ast::PatIdent(ast::BindingMode::ByValue(ast::Mutability::Immutable), Spanned{ span:sp(0, 1), node: str_to_ident("b") }, @@ -921,10 +913,10 @@ mod tests { P(ast::Item{ident:str_to_ident("a"), attrs:Vec::new(), id: ast::DUMMY_NODE_ID, - node: ast::ItemFn(P(ast::FnDecl { + node: ast::ItemKind::Fn(P(ast::FnDecl { inputs: vec!(ast::Arg{ ty: P(ast::Ty{id: ast::DUMMY_NODE_ID, - node: ast::TyPath(None, ast::Path{ + node: ast::TyKind::Path(None, ast::Path{ span:sp(10,13), global:false, segments: vec!( @@ -940,7 +932,7 @@ mod tests { pat: P(ast::Pat { id: ast::DUMMY_NODE_ID, node: ast::PatIdent( - ast::BindingMode::ByValue(ast::MutImmutable), + ast::BindingMode::ByValue(ast::Mutability::Immutable), Spanned{ span: sp(6,7), node: str_to_ident("b")}, @@ -950,12 +942,12 @@ mod tests { }), id: ast::DUMMY_NODE_ID }), - output: ast::DefaultReturn(sp(15, 15)), + output: ast::FunctionRetTy::Default(sp(15, 15)), variadic: false }), ast::Unsafety::Normal, ast::Constness::NotConst, - abi::Rust, + Abi::Rust, ast::Generics{ // no idea on either of these: lifetimes: Vec::new(), ty_params: P::empty(), @@ -966,9 +958,9 @@ mod tests { }, P(ast::Block { stmts: vec!(P(Spanned{ - node: ast::StmtSemi(P(ast::Expr{ + node: ast::StmtKind::Semi(P(ast::Expr{ id: ast::DUMMY_NODE_ID, - node: ast::ExprPath(None, + node: ast::ExprKind::Path(None, ast::Path{ span:sp(17,18), global:false, @@ -988,10 +980,10 @@ mod tests { span: sp(17,19)})), expr: None, id: ast::DUMMY_NODE_ID, - rules: ast::DefaultBlock, // no idea + rules: ast::BlockCheckMode::Default, // no idea span: sp(15,21), })), - vis: ast::Inherited, + vis: ast::Visibility::Inherited, span: sp(0,21)}))); } @@ -1110,7 +1102,7 @@ mod tests { "foo!( fn main() { body } )".to_string(), vec![], &sess); let tts = match expr.node { - ast::ExprMac(ref mac) => mac.node.tts.clone(), + ast::ExprKind::Mac(ref mac) => mac.node.tts.clone(), _ => panic!("not a macro"), }; diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 82bfc26ee34..e985bfd37b0 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -10,53 +10,40 @@ pub use self::PathParsingMode::*; -use abi; +use abi::{self, Abi}; use ast::BareFnTy; use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; -use ast::{Public, Unsafety}; -use ast::{Mod, BiAdd, Arg, Arm, Attribute, BindingMode}; -use ast::{BiBitAnd, BiBitOr, BiBitXor, BiRem, BiLt, Block}; -use ast::{BlockCheckMode, CaptureByRef, CaptureByValue, CaptureClause}; -use ast::{Constness, ConstTraitItem, Crate, CrateConfig}; -use ast::{Decl, DeclItem, DeclLocal, DefaultBlock, DefaultReturn}; -use ast::{UnDeref, BiDiv, EMPTY_CTXT, EnumDef, ExplicitSelf}; -use ast::{Expr, Expr_, ExprAddrOf, ExprMatch, ExprAgain}; -use ast::{ExprAssign, ExprAssignOp, ExprBinary, ExprBlock, ExprBox}; -use ast::{ExprBreak, ExprCall, ExprCast, ExprInPlace}; -use ast::{ExprField, ExprTupField, ExprClosure, ExprIf, ExprIfLet, ExprIndex}; -use ast::{ExprLit, ExprLoop, ExprMac, ExprRange}; -use ast::{ExprMethodCall, ExprParen, ExprPath}; -use ast::{ExprRepeat, ExprRet, ExprStruct, ExprTup, ExprType, ExprUnary}; -use ast::{ExprVec, ExprWhile, ExprWhileLet, ExprForLoop, Field, FnDecl}; -use ast::{ForeignItem, ForeignItemStatic, ForeignItemFn, FunctionRetTy}; -use ast::{Ident, Inherited, ImplItem, Item, Item_, ItemStatic}; -use ast::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl, ItemConst}; -use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy, ItemDefaultImpl}; -use ast::{ItemExternCrate, ItemUse}; -use ast::{Lit, Lit_}; -use ast::{LitBool, LitChar, LitByte, LitByteStr}; -use ast::{LitStr, LitInt, Local}; -use ast::{MacStmtWithBraces, MacStmtWithSemicolon, MacStmtWithoutBraces}; -use ast::{MutImmutable, MutMutable, Mac_}; -use ast::{MutTy, BiMul, Mutability}; -use ast::{NamedField, UnNeg, NoReturn, UnNot}; +use ast::Unsafety; +use ast::{Mod, Arg, Arm, Attribute, BindingMode, TraitItemKind}; +use ast::Block; +use ast::{BlockCheckMode, CaptureBy}; +use ast::{Constness, Crate, CrateConfig}; +use ast::{Decl, DeclKind}; +use ast::{EMPTY_CTXT, EnumDef, ExplicitSelf}; +use ast::{Expr, ExprKind}; +use ast::{Field, FnDecl}; +use ast::{ForeignItem, ForeignItemKind, FunctionRetTy}; +use ast::{Ident, ImplItem, Item, ItemKind}; +use ast::{Lit, LitKind, UintTy}; +use ast::Local; +use ast::MacStmtStyle; +use ast::Mac_; +use ast::{MutTy, Mutability}; +use ast::NamedField; use ast::{Pat, PatBox, PatEnum, PatIdent, PatLit, PatQPath, PatMac, PatRange}; use ast::{PatRegion, PatStruct, PatTup, PatVec, PatWild}; use ast::{PolyTraitRef, QSelf}; -use ast::{Return, BiShl, BiShr, Stmt, StmtDecl}; -use ast::{StmtExpr, StmtSemi, StmtMac, VariantData, StructField}; -use ast::{BiSub, StrStyle}; -use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue}; +use ast::{Stmt, StmtKind}; +use ast::{VariantData, StructField}; +use ast::StrStyle; +use ast::SelfKind; use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef}; -use ast::{Ty, Ty_, TypeBinding, TyMac}; -use ast::{TyFixedLengthVec, TyBareFn, TyTypeof, TyInfer}; -use ast::{TyParam, TyParamBounds, TyParen, TyPath, TyPtr}; -use ast::{TyRptr, TyTup, TyU32, TyVec}; -use ast::TypeTraitItem; -use ast::{UnnamedField, UnsafeBlock}; +use ast::{Ty, TyKind, TypeBinding, TyParam, TyParamBounds}; +use ast::UnnamedField; use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple}; use ast::{Visibility, WhereClause}; use attr::{ThinAttributes, ThinAttributesExt, AttributesExt}; +use ast::{BinOpKind, UnOp}; use ast; use ast_util::{self, ident_to_path}; use codemap::{self, Span, BytePos, Spanned, spanned, mk_sp, CodeMap}; @@ -89,7 +76,7 @@ bitflags! { } } -type ItemInfo = (Ident, Item_, Option<Vec<Attribute> >); +type ItemInfo = (Ident, ItemKind, Option<Vec<Attribute> >); /// How to parse a path. There are four different kinds of paths, all of which /// are parsed somewhat differently. @@ -139,7 +126,7 @@ macro_rules! maybe_whole_expr { _ => unreachable!() }; let span = $p.span; - Some($p.mk_expr(span.lo, span.hi, ExprPath(None, pt), None)) + Some($p.mk_expr(span.lo, span.hi, ExprKind::Path(None, pt), None)) } token::Interpolated(token::NtBlock(_)) => { // FIXME: The following avoids an issue with lexical borrowck scopes, @@ -149,7 +136,7 @@ macro_rules! maybe_whole_expr { _ => unreachable!() }; let span = $p.span; - Some($p.mk_expr(span.lo, span.hi, ExprBlock(b), None)) + Some($p.mk_expr(span.lo, span.hi, ExprKind::Block(b), None)) } _ => None }; @@ -507,7 +494,7 @@ impl<'a> Parser<'a> { pub fn commit_expr(&mut self, e: &Expr, edible: &[token::Token], inedible: &[token::Token]) -> PResult<'a, ()> { debug!("commit_expr {:?}", e); - if let ExprPath(..) = e.node { + if let ExprKind::Path(..) = e.node { // might be unit-struct construction; check for recoverableinput error. let expected = edible.iter() .cloned() @@ -587,11 +574,11 @@ impl<'a> Parser<'a> { let lo = self.span.lo; let node = if self.eat_keyword(keywords::SelfValue) { let rename = try!(self.parse_rename()); - ast::PathListMod { id: ast::DUMMY_NODE_ID, rename: rename } + ast::PathListItemKind::Mod { id: ast::DUMMY_NODE_ID, rename: rename } } else { let ident = try!(self.parse_ident()); let rename = try!(self.parse_rename()); - ast::PathListIdent { name: ident, rename: rename, id: ast::DUMMY_NODE_ID } + ast::PathListItemKind::Ident { name: ident, rename: rename, id: ast::DUMMY_NODE_ID } }; let hi = self.last_span.hi; Ok(spanned(lo, hi, node)) @@ -1063,7 +1050,7 @@ impl<'a> Parser<'a> { } } - pub fn parse_for_in_type(&mut self) -> PResult<'a, Ty_> { + pub fn parse_for_in_type(&mut self) -> PResult<'a, TyKind> { /* Parses whatever can come after a `for` keyword in a type. The `for` has already been consumed. @@ -1102,16 +1089,17 @@ impl<'a> Parser<'a> { Some(TraitTyParamBound(poly_trait_ref, TraitBoundModifier::None)).into_iter() .chain(other_bounds.into_vec()) .collect(); - Ok(ast::TyPolyTraitRef(all_bounds)) + Ok(ast::TyKind::PolyTraitRef(all_bounds)) } } - pub fn parse_ty_path(&mut self) -> PResult<'a, Ty_> { - Ok(TyPath(None, try!(self.parse_path(LifetimeAndTypesWithoutColons)))) + pub fn parse_ty_path(&mut self) -> PResult<'a, TyKind> { + Ok(TyKind::Path(None, try!(self.parse_path(LifetimeAndTypesWithoutColons)))) } - /// parse a TyBareFn type: - pub fn parse_ty_bare_fn(&mut self, lifetime_defs: Vec<ast::LifetimeDef>) -> PResult<'a, Ty_> { + /// parse a TyKind::BareFn type: + pub fn parse_ty_bare_fn(&mut self, lifetime_defs: Vec<ast::LifetimeDef>) + -> PResult<'a, TyKind> { /* [unsafe] [extern "ABI"] fn <'lt> (S) -> T @@ -1126,9 +1114,9 @@ impl<'a> Parser<'a> { let unsafety = try!(self.parse_unsafety()); let abi = if self.eat_keyword(keywords::Extern) { - try!(self.parse_opt_abi()).unwrap_or(abi::C) + try!(self.parse_opt_abi()).unwrap_or(Abi::C) } else { - abi::Rust + Abi::Rust }; try!(self.expect_keyword(keywords::Fn)); @@ -1139,7 +1127,7 @@ impl<'a> Parser<'a> { output: ret_ty, variadic: variadic }); - Ok(TyBareFn(P(BareFnTy { + Ok(TyKind::BareFn(P(BareFnTy { abi: abi, unsafety: unsafety, lifetimes: lifetime_defs, @@ -1199,7 +1187,7 @@ impl<'a> Parser<'a> { let (name, node) = if p.eat_keyword(keywords::Type) { let TyParam {ident, bounds, default, ..} = try!(p.parse_ty_param()); try!(p.expect(&token::Semi)); - (ident, TypeTraitItem(bounds, default)) + (ident, TraitItemKind::Type(bounds, default)) } else if p.is_const_item() { try!(p.expect_keyword(keywords::Const)); let ident = try!(p.parse_ident()); @@ -1214,7 +1202,7 @@ impl<'a> Parser<'a> { try!(p.expect(&token::Semi)); None }; - (ident, ConstTraitItem(ty, default)) + (ident, TraitItemKind::Const(ty, default)) } else { let (constness, unsafety, abi) = try!(p.parse_fn_front_matter()); @@ -1258,7 +1246,7 @@ impl<'a> Parser<'a> { token_str)[..])) } }; - (ident, ast::MethodTraitItem(sig, body)) + (ident, ast::TraitItemKind::Method(sig, body)) }; Ok(P(TraitItem { @@ -1282,13 +1270,13 @@ impl<'a> Parser<'a> { pub fn parse_ret_ty(&mut self) -> PResult<'a, FunctionRetTy> { if self.eat(&token::RArrow) { if self.eat(&token::Not) { - Ok(NoReturn(self.last_span)) + Ok(FunctionRetTy::None(self.last_span)) } else { - Ok(Return(try!(self.parse_ty()))) + Ok(FunctionRetTy::Ty(try!(self.parse_ty()))) } } else { let pos = self.span.lo; - Ok(DefaultReturn(mk_sp(pos, pos))) + Ok(FunctionRetTy::Default(mk_sp(pos, pos))) } } @@ -1313,7 +1301,7 @@ impl<'a> Parser<'a> { } let sp = mk_sp(lo, self.last_span.hi); - let sum = ast::TyObjectSum(lhs, bounds); + let sum = ast::TyKind::ObjectSum(lhs, bounds); Ok(P(Ty {id: ast::DUMMY_NODE_ID, node: sum, span: sp})) } @@ -1344,14 +1332,14 @@ impl<'a> Parser<'a> { try!(self.expect(&token::CloseDelim(token::Paren))); if ts.len() == 1 && !last_comma { - TyParen(ts.into_iter().nth(0).unwrap()) + TyKind::Paren(ts.into_iter().nth(0).unwrap()) } else { - TyTup(ts) + TyKind::Tup(ts) } } else if self.check(&token::BinOp(token::Star)) { // STAR POINTER (bare pointer?) self.bump(); - TyPtr(try!(self.parse_ptr())) + TyKind::Ptr(try!(self.parse_ptr())) } else if self.check(&token::OpenDelim(token::Bracket)) { // VECTOR try!(self.expect(&token::OpenDelim(token::Bracket))); @@ -1360,8 +1348,8 @@ impl<'a> Parser<'a> { // Parse the `; e` in `[ i32; e ]` // where `e` is a const expression let t = match try!(self.maybe_parse_fixed_length_of_vec()) { - None => TyVec(t), - Some(suffix) => TyFixedLengthVec(t, suffix) + None => TyKind::Vec(t), + Some(suffix) => TyKind::FixedLengthVec(t, suffix) }; try!(self.expect(&token::CloseDelim(token::Bracket))); t @@ -1381,13 +1369,13 @@ impl<'a> Parser<'a> { try!(self.expect(&token::OpenDelim(token::Paren))); let e = try!(self.parse_expr()); try!(self.expect(&token::CloseDelim(token::Paren))); - TyTypeof(e) + TyKind::Typeof(e) } else if self.eat_lt() { let (qself, path) = try!(self.parse_qualified_path(NoTypesAllowed)); - TyPath(Some(qself), path) + TyKind::Path(Some(qself), path) } else if self.check(&token::ModSep) || self.token.is_ident() || self.token.is_path() { @@ -1400,14 +1388,14 @@ impl<'a> Parser<'a> { seq_sep_none(), |p| p.parse_token_tree())); let hi = self.span.hi; - TyMac(spanned(lo, hi, Mac_ { path: path, tts: tts, ctxt: EMPTY_CTXT })) + TyKind::Mac(spanned(lo, hi, Mac_ { path: path, tts: tts, ctxt: EMPTY_CTXT })) } else { // NAMED TYPE - TyPath(None, path) + TyKind::Path(None, path) } } else if self.eat(&token::Underscore) { // TYPE TO BE INFERRED - TyInfer + TyKind::Infer } else { let this_token_str = self.this_token_to_string(); let msg = format!("expected type, found `{}`", this_token_str); @@ -1418,26 +1406,26 @@ impl<'a> Parser<'a> { Ok(P(Ty {id: ast::DUMMY_NODE_ID, node: t, span: sp})) } - pub fn parse_borrowed_pointee(&mut self) -> PResult<'a, Ty_> { + pub fn parse_borrowed_pointee(&mut self) -> PResult<'a, TyKind> { // look for `&'lt` or `&'foo ` and interpret `foo` as the region name: let opt_lifetime = try!(self.parse_opt_lifetime()); let mt = try!(self.parse_mt()); - return Ok(TyRptr(opt_lifetime, mt)); + return Ok(TyKind::Rptr(opt_lifetime, mt)); } pub fn parse_ptr(&mut self) -> PResult<'a, MutTy> { let mutbl = if self.eat_keyword(keywords::Mut) { - MutMutable + Mutability::Mutable } else if self.eat_keyword(keywords::Const) { - MutImmutable + Mutability::Immutable } else { let span = self.last_span; self.span_err(span, "bare raw pointers are no longer allowed, you should \ likely use `*mut T`, but otherwise `*T` is now \ known as `*const T`"); - MutImmutable + Mutability::Immutable }; let t = try!(self.parse_ty()); Ok(MutTy { ty: t, mutbl: mutbl }) @@ -1503,7 +1491,7 @@ impl<'a> Parser<'a> { } else { P(Ty { id: ast::DUMMY_NODE_ID, - node: TyInfer, + node: TyKind::Infer, span: mk_sp(self.span.lo, self.span.hi), }) }; @@ -1524,18 +1512,18 @@ impl<'a> Parser<'a> { } /// Matches token_lit = LIT_INTEGER | ... - pub fn lit_from_token(&self, tok: &token::Token) -> PResult<'a, Lit_> { + pub fn lit_from_token(&self, tok: &token::Token) -> PResult<'a, LitKind> { match *tok { token::Interpolated(token::NtExpr(ref v)) => { match v.node { - ExprLit(ref lit) => { Ok(lit.node.clone()) } + ExprKind::Lit(ref lit) => { Ok(lit.node.clone()) } _ => { return self.unexpected_last(tok); } } } token::Literal(lit, suf) => { let (suffix_illegal, out) = match lit { - token::Byte(i) => (true, LitByte(parse::byte_lit(&i.as_str()).0)), - token::Char(i) => (true, LitChar(parse::char_lit(&i.as_str()).0)), + token::Byte(i) => (true, LitKind::Byte(parse::byte_lit(&i.as_str()).0)), + token::Char(i) => (true, LitKind::Char(parse::char_lit(&i.as_str()).0)), // there are some valid suffixes for integer and // float literals, so all the handling is done @@ -1555,20 +1543,20 @@ impl<'a> Parser<'a> { token::Str_(s) => { (true, - LitStr(token::intern_and_get_ident(&parse::str_lit(&s.as_str())), - ast::CookedStr)) + LitKind::Str(token::intern_and_get_ident(&parse::str_lit(&s.as_str())), + ast::StrStyle::Cooked)) } token::StrRaw(s, n) => { (true, - LitStr( + LitKind::Str( token::intern_and_get_ident(&parse::raw_str_lit(&s.as_str())), - ast::RawStr(n))) + ast::StrStyle::Raw(n))) } token::ByteStr(i) => - (true, LitByteStr(parse::byte_str_lit(&i.as_str()))), + (true, LitKind::ByteStr(parse::byte_str_lit(&i.as_str()))), token::ByteStrRaw(i, _) => (true, - LitByteStr(Rc::new(i.to_string().into_bytes()))), + LitKind::ByteStr(Rc::new(i.to_string().into_bytes()))), }; if suffix_illegal { @@ -1586,9 +1574,9 @@ impl<'a> Parser<'a> { pub fn parse_lit(&mut self) -> PResult<'a, Lit> { let lo = self.span.lo; let lit = if self.eat_keyword(keywords::True) { - LitBool(true) + LitKind::Bool(true) } else if self.eat_keyword(keywords::False) { - LitBool(false) + LitKind::Bool(false) } else { let token = self.bump_and_get(); let lit = try!(self.lit_from_token(&token)); @@ -1604,11 +1592,11 @@ impl<'a> Parser<'a> { let lo = self.span.lo; let literal = P(try!(self.parse_lit())); let hi = self.last_span.hi; - let expr = self.mk_expr(lo, hi, ExprLit(literal), None); + let expr = self.mk_expr(lo, hi, ExprKind::Lit(literal), None); if minus_present { let minus_hi = self.last_span.hi; - let unary = self.mk_unary(UnNeg, expr); + let unary = self.mk_unary(UnOp::Neg, expr); Ok(self.mk_expr(minus_lo, minus_hi, unary, None)) } else { Ok(expr) @@ -1935,9 +1923,9 @@ impl<'a> Parser<'a> { /// Parse mutability declaration (mut/const/imm) pub fn parse_mutability(&mut self) -> PResult<'a, Mutability> { if self.eat_keyword(keywords::Mut) { - Ok(MutMutable) + Ok(Mutability::Mutable) } else { - Ok(MutImmutable) + Ok(Mutability::Immutable) } } @@ -1956,7 +1944,7 @@ impl<'a> Parser<'a> { } pub fn mk_expr(&mut self, lo: BytePos, hi: BytePos, - node: Expr_, attrs: ThinAttributes) -> P<Expr> { + node: ExprKind, attrs: ThinAttributes) -> P<Expr> { P(Expr { id: ast::DUMMY_NODE_ID, node: node, @@ -1965,55 +1953,55 @@ impl<'a> Parser<'a> { }) } - pub fn mk_unary(&mut self, unop: ast::UnOp, expr: P<Expr>) -> ast::Expr_ { - ExprUnary(unop, expr) + pub fn mk_unary(&mut self, unop: ast::UnOp, expr: P<Expr>) -> ast::ExprKind { + ExprKind::Unary(unop, expr) } - pub fn mk_binary(&mut self, binop: ast::BinOp, lhs: P<Expr>, rhs: P<Expr>) -> ast::Expr_ { - ExprBinary(binop, lhs, rhs) + pub fn mk_binary(&mut self, binop: ast::BinOp, lhs: P<Expr>, rhs: P<Expr>) -> ast::ExprKind { + ExprKind::Binary(binop, lhs, rhs) } - pub fn mk_call(&mut self, f: P<Expr>, args: Vec<P<Expr>>) -> ast::Expr_ { - ExprCall(f, args) + pub fn mk_call(&mut self, f: P<Expr>, args: Vec<P<Expr>>) -> ast::ExprKind { + ExprKind::Call(f, args) } fn mk_method_call(&mut self, ident: ast::SpannedIdent, tps: Vec<P<Ty>>, args: Vec<P<Expr>>) - -> ast::Expr_ { - ExprMethodCall(ident, tps, args) + -> ast::ExprKind { + ExprKind::MethodCall(ident, tps, args) } - pub fn mk_index(&mut self, expr: P<Expr>, idx: P<Expr>) -> ast::Expr_ { - ExprIndex(expr, idx) + pub fn mk_index(&mut self, expr: P<Expr>, idx: P<Expr>) -> ast::ExprKind { + ExprKind::Index(expr, idx) } pub fn mk_range(&mut self, start: Option<P<Expr>>, end: Option<P<Expr>>) - -> ast::Expr_ { - ExprRange(start, end) + -> ast::ExprKind { + ExprKind::Range(start, end) } - pub fn mk_field(&mut self, expr: P<Expr>, ident: ast::SpannedIdent) -> ast::Expr_ { - ExprField(expr, ident) + pub fn mk_field(&mut self, expr: P<Expr>, ident: ast::SpannedIdent) -> ast::ExprKind { + ExprKind::Field(expr, ident) } - pub fn mk_tup_field(&mut self, expr: P<Expr>, idx: codemap::Spanned<usize>) -> ast::Expr_ { - ExprTupField(expr, idx) + pub fn mk_tup_field(&mut self, expr: P<Expr>, idx: codemap::Spanned<usize>) -> ast::ExprKind { + ExprKind::TupField(expr, idx) } pub fn mk_assign_op(&mut self, binop: ast::BinOp, - lhs: P<Expr>, rhs: P<Expr>) -> ast::Expr_ { - ExprAssignOp(binop, lhs, rhs) + lhs: P<Expr>, rhs: P<Expr>) -> ast::ExprKind { + ExprKind::AssignOp(binop, lhs, rhs) } pub fn mk_mac_expr(&mut self, lo: BytePos, hi: BytePos, m: Mac_, attrs: ThinAttributes) -> P<Expr> { P(Expr { id: ast::DUMMY_NODE_ID, - node: ExprMac(codemap::Spanned {node: m, span: mk_sp(lo, hi)}), + node: ExprKind::Mac(codemap::Spanned {node: m, span: mk_sp(lo, hi)}), span: mk_sp(lo, hi), attrs: attrs, }) @@ -2022,13 +2010,13 @@ impl<'a> Parser<'a> { pub fn mk_lit_u32(&mut self, i: u32, attrs: ThinAttributes) -> P<Expr> { let span = &self.span; let lv_lit = P(codemap::Spanned { - node: LitInt(i as u64, ast::UnsignedIntLit(TyU32)), + node: LitKind::Int(i as u64, ast::LitIntType::Unsigned(UintTy::U32)), span: *span }); P(Expr { id: ast::DUMMY_NODE_ID, - node: ExprLit(lv_lit), + node: ExprKind::Lit(lv_lit), span: *span, attrs: attrs, }) @@ -2065,7 +2053,7 @@ impl<'a> Parser<'a> { let lo = self.span.lo; let mut hi = self.span.hi; - let ex: Expr_; + let ex: ExprKind; // Note: when adding new syntax here, don't forget to adjust Token::can_begin_expr(). match self.token { @@ -2097,17 +2085,17 @@ impl<'a> Parser<'a> { hi = self.last_span.hi; return if es.len() == 1 && !trailing_comma { - Ok(self.mk_expr(lo, hi, ExprParen(es.into_iter().nth(0).unwrap()), attrs)) + Ok(self.mk_expr(lo, hi, ExprKind::Paren(es.into_iter().nth(0).unwrap()), attrs)) } else { - Ok(self.mk_expr(lo, hi, ExprTup(es), attrs)) + Ok(self.mk_expr(lo, hi, ExprKind::Tup(es), attrs)) } }, token::OpenDelim(token::Brace) => { - return self.parse_block_expr(lo, DefaultBlock, attrs); + return self.parse_block_expr(lo, BlockCheckMode::Default, attrs); }, token::BinOp(token::Or) | token::OrOr => { let lo = self.span.lo; - return self.parse_lambda_expr(lo, CaptureByRef, attrs); + return self.parse_lambda_expr(lo, CaptureBy::Ref, attrs); }, token::Ident(id @ ast::Ident { name: token::SELF_KEYWORD_NAME, @@ -2115,7 +2103,7 @@ impl<'a> Parser<'a> { }, token::Plain) => { self.bump(); let path = ast_util::ident_to_path(mk_sp(lo, hi), id); - ex = ExprPath(None, path); + ex = ExprKind::Path(None, path); hi = self.last_span.hi; } token::OpenDelim(token::Bracket) => { @@ -2128,7 +2116,7 @@ impl<'a> Parser<'a> { if self.check(&token::CloseDelim(token::Bracket)) { // Empty vector. self.bump(); - ex = ExprVec(Vec::new()); + ex = ExprKind::Vec(Vec::new()); } else { // Nonempty vector. let first_expr = try!(self.parse_expr()); @@ -2137,7 +2125,7 @@ impl<'a> Parser<'a> { self.bump(); let count = try!(self.parse_expr()); try!(self.expect(&token::CloseDelim(token::Bracket))); - ex = ExprRepeat(first_expr, count); + ex = ExprKind::Repeat(first_expr, count); } else if self.check(&token::Comma) { // Vector with two or more elements. self.bump(); @@ -2148,11 +2136,11 @@ impl<'a> Parser<'a> { )); let mut exprs = vec!(first_expr); exprs.extend(remaining_exprs); - ex = ExprVec(exprs); + ex = ExprKind::Vec(exprs); } else { // Vector with one element. try!(self.expect(&token::CloseDelim(token::Bracket))); - ex = ExprVec(vec!(first_expr)); + ex = ExprKind::Vec(vec!(first_expr)); } } hi = self.last_span.hi; @@ -2162,11 +2150,11 @@ impl<'a> Parser<'a> { let (qself, path) = try!(self.parse_qualified_path(LifetimeAndTypesWithColons)); hi = path.span.hi; - return Ok(self.mk_expr(lo, hi, ExprPath(Some(qself), path), attrs)); + return Ok(self.mk_expr(lo, hi, ExprKind::Path(Some(qself), path), attrs)); } if self.eat_keyword(keywords::Move) { let lo = self.last_span.lo; - return self.parse_lambda_expr(lo, CaptureByValue, attrs); + return self.parse_lambda_expr(lo, CaptureBy::Value, attrs); } if self.eat_keyword(keywords::If) { return self.parse_if_expr(attrs); @@ -2201,14 +2189,14 @@ impl<'a> Parser<'a> { } if self.eat_keyword(keywords::Continue) { let ex = if self.token.is_lifetime() { - let ex = ExprAgain(Some(Spanned{ + let ex = ExprKind::Again(Some(Spanned{ node: self.get_lifetime(), span: self.span })); self.bump(); ex } else { - ExprAgain(None) + ExprKind::Again(None) }; let hi = self.last_span.hi; return Ok(self.mk_expr(lo, hi, ex, attrs)); @@ -2219,26 +2207,26 @@ impl<'a> Parser<'a> { if self.eat_keyword(keywords::Unsafe) { return self.parse_block_expr( lo, - UnsafeBlock(ast::UserProvided), + BlockCheckMode::Unsafe(ast::UserProvided), attrs); } if self.eat_keyword(keywords::Return) { if self.token.can_begin_expr() { let e = try!(self.parse_expr()); hi = e.span.hi; - ex = ExprRet(Some(e)); + ex = ExprKind::Ret(Some(e)); } else { - ex = ExprRet(None); + ex = ExprKind::Ret(None); } } else if self.eat_keyword(keywords::Break) { if self.token.is_lifetime() { - ex = ExprBreak(Some(Spanned { + ex = ExprKind::Break(Some(Spanned { node: self.get_lifetime(), span: self.span })); self.bump(); } else { - ex = ExprBreak(None); + ex = ExprKind::Break(None); } hi = self.last_span.hi; } else if self.token.is_keyword(keywords::Let) { @@ -2301,18 +2289,18 @@ impl<'a> Parser<'a> { hi = self.span.hi; try!(self.expect(&token::CloseDelim(token::Brace))); - ex = ExprStruct(pth, fields, base); + ex = ExprKind::Struct(pth, fields, base); return Ok(self.mk_expr(lo, hi, ex, attrs)); } } hi = pth.span.hi; - ex = ExprPath(None, pth); + ex = ExprKind::Path(None, pth); } else { // other literal expression let lit = try!(self.parse_lit()); hi = lit.span.hi; - ex = ExprLit(P(lit)); + ex = ExprKind::Lit(P(lit)); } } } @@ -2342,7 +2330,7 @@ impl<'a> Parser<'a> { let attrs = outer_attrs.append(inner_attrs); let blk = try!(self.parse_block_tail(lo, blk_mode)); - return Ok(self.mk_expr(blk.span.lo, blk.span.hi, ExprBlock(blk), attrs)); + return Ok(self.mk_expr(blk.span.lo, blk.span.hi, ExprKind::Block(blk), attrs)); } /// parse a.b or a(13) or a[4] or just a @@ -2369,7 +2357,7 @@ impl<'a> Parser<'a> { expr.map(|mut expr| { expr.attrs.update(|a| a.prepend(attrs)); match expr.node { - ExprIf(..) | ExprIfLet(..) => { + ExprKind::If(..) | ExprKind::IfLet(..) => { if !expr.attrs.as_attr_slice().is_empty() { // Just point to the first attribute in there... let span = expr.attrs.as_attr_slice()[0].span; @@ -2610,11 +2598,11 @@ impl<'a> Parser<'a> { match parser.token { token::BinOp(token::Star) => { parser.bump(); - Ok(Some(ast::ZeroOrMore)) + Ok(Some(ast::KleeneOp::ZeroOrMore)) }, token::BinOp(token::Plus) => { parser.bump(); - Ok(Some(ast::OneOrMore)) + Ok(Some(ast::KleeneOp::OneOrMore)) }, _ => Ok(None) } @@ -2740,21 +2728,21 @@ impl<'a> Parser<'a> { let e = self.parse_prefix_expr(None); let (span, e) = try!(self.interpolated_or_expr_span(e)); hi = span.hi; - self.mk_unary(UnNot, e) + self.mk_unary(UnOp::Not, e) } token::BinOp(token::Minus) => { self.bump(); let e = self.parse_prefix_expr(None); let (span, e) = try!(self.interpolated_or_expr_span(e)); hi = span.hi; - self.mk_unary(UnNeg, e) + self.mk_unary(UnOp::Neg, e) } token::BinOp(token::Star) => { self.bump(); let e = self.parse_prefix_expr(None); let (span, e) = try!(self.interpolated_or_expr_span(e)); hi = span.hi; - self.mk_unary(UnDeref, e) + self.mk_unary(UnOp::Deref, e) } token::BinOp(token::And) | token::AndAnd => { try!(self.expect_and()); @@ -2762,7 +2750,7 @@ impl<'a> Parser<'a> { let e = self.parse_prefix_expr(None); let (span, e) = try!(self.interpolated_or_expr_span(e)); hi = span.hi; - ExprAddrOf(m, e) + ExprKind::AddrOf(m, e) } token::Ident(..) if self.token.is_keyword(keywords::In) => { self.bump(); @@ -2773,16 +2761,16 @@ impl<'a> Parser<'a> { let blk = try!(self.parse_block()); let span = blk.span; hi = span.hi; - let blk_expr = self.mk_expr(span.lo, span.hi, ExprBlock(blk), + let blk_expr = self.mk_expr(span.lo, span.hi, ExprKind::Block(blk), None); - ExprInPlace(place, blk_expr) + ExprKind::InPlace(place, blk_expr) } token::Ident(..) if self.token.is_keyword(keywords::Box) => { self.bump(); let e = self.parse_prefix_expr(None); let (span, e) = try!(self.interpolated_or_expr_span(e)); hi = span.hi; - ExprBox(e) + ExprKind::Box(e) } _ => return self.parse_dot_or_call_expr(Some(attrs)) }; @@ -2849,12 +2837,12 @@ impl<'a> Parser<'a> { if op == AssocOp::As { let rhs = try!(self.parse_ty()); lhs = self.mk_expr(lhs_span.lo, rhs.span.hi, - ExprCast(lhs, rhs), None); + ExprKind::Cast(lhs, rhs), None); continue } else if op == AssocOp::Colon { let rhs = try!(self.parse_ty()); lhs = self.mk_expr(lhs_span.lo, rhs.span.hi, - ExprType(lhs, rhs), None); + ExprKind::Type(lhs, rhs), None); continue } else if op == AssocOp::DotDot { // If we didn’t have to handle `x..`, it would be pretty easy to generalise @@ -2920,21 +2908,21 @@ impl<'a> Parser<'a> { self.mk_expr(lhs_span.lo, rhs_span.hi, binary, None) } AssocOp::Assign => - self.mk_expr(lhs_span.lo, rhs.span.hi, ExprAssign(lhs, rhs), None), + self.mk_expr(lhs_span.lo, rhs.span.hi, ExprKind::Assign(lhs, rhs), None), AssocOp::Inplace => - self.mk_expr(lhs_span.lo, rhs.span.hi, ExprInPlace(lhs, rhs), None), + self.mk_expr(lhs_span.lo, rhs.span.hi, ExprKind::InPlace(lhs, rhs), None), AssocOp::AssignOp(k) => { let aop = match k { - token::Plus => BiAdd, - token::Minus => BiSub, - token::Star => BiMul, - token::Slash => BiDiv, - token::Percent => BiRem, - token::Caret => BiBitXor, - token::And => BiBitAnd, - token::Or => BiBitOr, - token::Shl => BiShl, - token::Shr => BiShr + token::Plus => BinOpKind::Add, + token::Minus => BinOpKind::Sub, + token::Star => BinOpKind::Mul, + token::Slash => BinOpKind::Div, + token::Percent => BinOpKind::Rem, + token::Caret => BinOpKind::BitXor, + token::And => BinOpKind::BitAnd, + token::Or => BinOpKind::BitOr, + token::Shl => BinOpKind::Shl, + token::Shr => BinOpKind::Shr, }; let (lhs_span, rhs_span) = (lhs_span, rhs.span); let aopexpr = self.mk_assign_op(codemap::respan(cur_op_span, aop), lhs, rhs); @@ -2956,12 +2944,12 @@ impl<'a> Parser<'a> { fn check_no_chained_comparison(&mut self, lhs: &Expr, outer_op: &AssocOp) { debug_assert!(outer_op.is_comparison()); match lhs.node { - ExprBinary(op, _, _) if op.node.is_comparison() => { + ExprKind::Binary(op, _, _) if op.node.is_comparison() => { // respan to include both operators let op_span = mk_sp(op.span.lo, self.span.hi); let mut err = self.diagnostic().struct_span_err(op_span, "chained comparison operators require parentheses"); - if op.node == BiLt && *outer_op == AssocOp::Greater { + if op.node == BinOpKind::Lt && *outer_op == AssocOp::Greater { err.fileline_help(op_span, "use `::<...>` instead of `<...>` if you meant to specify type arguments"); } @@ -3023,7 +3011,7 @@ impl<'a> Parser<'a> { hi = elexpr.span.hi; els = Some(elexpr); } - Ok(self.mk_expr(lo, hi, ExprIf(cond, thn, els), attrs)) + Ok(self.mk_expr(lo, hi, ExprKind::If(cond, thn, els), attrs)) } /// Parse an 'if let' expression ('if' token already eaten) @@ -3041,18 +3029,18 @@ impl<'a> Parser<'a> { } else { (thn.span.hi, None) }; - Ok(self.mk_expr(lo, hi, ExprIfLet(pat, expr, thn, els), attrs)) + Ok(self.mk_expr(lo, hi, ExprKind::IfLet(pat, expr, thn, els), attrs)) } // `|args| expr` pub fn parse_lambda_expr(&mut self, lo: BytePos, - capture_clause: CaptureClause, + capture_clause: CaptureBy, attrs: ThinAttributes) -> PResult<'a, P<Expr>> { let decl = try!(self.parse_fn_block_decl()); let body = match decl.output { - DefaultReturn(_) => { + FunctionRetTy::Default(_) => { // If no explicit return type is given, parse any // expr and wrap it up in a dummy block: let body_expr = try!(self.parse_expr()); @@ -3061,7 +3049,7 @@ impl<'a> Parser<'a> { stmts: vec![], span: body_expr.span, expr: Some(body_expr), - rules: DefaultBlock, + rules: BlockCheckMode::Default, }) } _ => { @@ -3074,7 +3062,7 @@ impl<'a> Parser<'a> { Ok(self.mk_expr( lo, body.span.hi, - ExprClosure(capture_clause, decl, body), attrs)) + ExprKind::Closure(capture_clause, decl, body), attrs)) } // `else` token already eaten @@ -3083,7 +3071,7 @@ impl<'a> Parser<'a> { return self.parse_if_expr(None); } else { let blk = try!(self.parse_block()); - return Ok(self.mk_expr(blk.span.lo, blk.span.hi, ExprBlock(blk), None)); + return Ok(self.mk_expr(blk.span.lo, blk.span.hi, ExprKind::Block(blk), None)); } } @@ -3102,7 +3090,7 @@ impl<'a> Parser<'a> { let hi = self.last_span.hi; Ok(self.mk_expr(span_lo, hi, - ExprForLoop(pat, expr, loop_block, opt_ident), + ExprKind::ForLoop(pat, expr, loop_block, opt_ident), attrs)) } @@ -3117,7 +3105,7 @@ impl<'a> Parser<'a> { let (iattrs, body) = try!(self.parse_inner_attrs_and_block()); let attrs = attrs.append(iattrs.into_thin_attrs()); let hi = body.span.hi; - return Ok(self.mk_expr(span_lo, hi, ExprWhile(cond, body, opt_ident), + return Ok(self.mk_expr(span_lo, hi, ExprKind::While(cond, body, opt_ident), attrs)); } @@ -3132,7 +3120,7 @@ impl<'a> Parser<'a> { let (iattrs, body) = try!(self.parse_inner_attrs_and_block()); let attrs = attrs.append(iattrs.into_thin_attrs()); let hi = body.span.hi; - return Ok(self.mk_expr(span_lo, hi, ExprWhileLet(pat, expr, body, opt_ident), attrs)); + return Ok(self.mk_expr(span_lo, hi, ExprKind::WhileLet(pat, expr, body, opt_ident), attrs)); } // parse `loop {...}`, `loop` token already eaten @@ -3142,7 +3130,7 @@ impl<'a> Parser<'a> { let (iattrs, body) = try!(self.parse_inner_attrs_and_block()); let attrs = attrs.append(iattrs.into_thin_attrs()); let hi = body.span.hi; - Ok(self.mk_expr(span_lo, hi, ExprLoop(body, opt_ident), attrs)) + Ok(self.mk_expr(span_lo, hi, ExprKind::Loop(body, opt_ident), attrs)) } // `match` token already eaten @@ -3166,7 +3154,7 @@ impl<'a> Parser<'a> { } let hi = self.span.hi; self.bump(); - return Ok(self.mk_expr(lo, hi, ExprMatch(discriminant, arms), attrs)); + return Ok(self.mk_expr(lo, hi, ExprKind::Match(discriminant, arms), attrs)); } pub fn parse_arm(&mut self) -> PResult<'a, Arm> { @@ -3361,10 +3349,10 @@ impl<'a> Parser<'a> { hi = self.last_span.hi; let bind_type = match (is_ref, is_mut) { - (true, true) => BindingMode::ByRef(MutMutable), - (true, false) => BindingMode::ByRef(MutImmutable), - (false, true) => BindingMode::ByValue(MutMutable), - (false, false) => BindingMode::ByValue(MutImmutable), + (true, true) => BindingMode::ByRef(Mutability::Mutable), + (true, false) => BindingMode::ByRef(Mutability::Immutable), + (false, true) => BindingMode::ByValue(Mutability::Mutable), + (false, false) => BindingMode::ByValue(Mutability::Immutable), }; let fieldpath = codemap::Spanned{span:self.last_span, node:fieldname}; let fieldpat = P(ast::Pat{ @@ -3406,7 +3394,7 @@ impl<'a> Parser<'a> { (None, try!(self.parse_path(LifetimeAndTypesWithColons))) }; let hi = self.last_span.hi; - Ok(self.mk_expr(lo, hi, ExprPath(qself, path), None)) + Ok(self.mk_expr(lo, hi, ExprKind::Path(qself, path), None)) } else { self.parse_pat_literal_maybe_minus() } @@ -3459,7 +3447,7 @@ impl<'a> Parser<'a> { // At this point, token != _, &, &&, (, [ if self.eat_keyword(keywords::Mut) { // Parse mut ident @ pat - pat = try!(self.parse_pat_ident(BindingMode::ByValue(MutMutable))); + pat = try!(self.parse_pat_ident(BindingMode::ByValue(Mutability::Mutable))); } else if self.eat_keyword(keywords::Ref) { // Parse ref ident @ pat / ref mut ident @ pat let mutbl = try!(self.parse_mutability()); @@ -3492,7 +3480,8 @@ impl<'a> Parser<'a> { // Parse ident @ pat // This can give false positives and parse nullary enums, // they are dealt with later in resolve - pat = try!(self.parse_pat_ident(BindingMode::ByValue(MutImmutable))); + let binding_mode = BindingMode::ByValue(Mutability::Immutable); + pat = try!(self.parse_pat_ident(binding_mode)); } } else { let (qself, path) = if self.eat_lt() { @@ -3508,7 +3497,7 @@ impl<'a> Parser<'a> { token::DotDotDot => { // Parse range let hi = self.last_span.hi; - let begin = self.mk_expr(lo, hi, ExprPath(qself, path), None); + let begin = self.mk_expr(lo, hi, ExprKind::Path(qself, path), None); self.bump(); let end = try!(self.parse_pat_range_end()); pat = PatRange(begin, end); @@ -3635,15 +3624,15 @@ impl<'a> Parser<'a> { fn parse_let(&mut self, attrs: ThinAttributes) -> PResult<'a, P<Decl>> { let lo = self.span.lo; let local = try!(self.parse_local(attrs)); - Ok(P(spanned(lo, self.last_span.hi, DeclLocal(local)))) + Ok(P(spanned(lo, self.last_span.hi, DeclKind::Local(local)))) } /// Parse a structure field fn parse_name_and_ty(&mut self, pr: Visibility, attrs: Vec<Attribute> ) -> PResult<'a, StructField> { let lo = match pr { - Inherited => self.span.lo, - Public => self.last_span.lo, + Visibility::Inherited => self.span.lo, + Visibility::Public => self.last_span.lo, }; if !self.token.is_plain_ident() { return Err(self.fatal("expected ident")); @@ -3686,7 +3675,7 @@ impl<'a> Parser<'a> { try!(self.expect_keyword(keywords::Let)); let decl = try!(self.parse_let(attrs.into_thin_attrs())); let hi = decl.span.hi; - let stmt = StmtDecl(decl, ast::DUMMY_NODE_ID); + let stmt = StmtKind::Decl(decl, ast::DUMMY_NODE_ID); spanned(lo, hi, stmt) } else if self.token.is_ident() && !self.token.is_any_keyword() @@ -3732,23 +3721,20 @@ impl<'a> Parser<'a> { let hi = self.last_span.hi; let style = if delim == token::Brace { - MacStmtWithBraces + MacStmtStyle::Braces } else { - MacStmtWithoutBraces + MacStmtStyle::NoBraces }; if id.name == token::special_idents::invalid.name { - let stmt = StmtMac(P(spanned(lo, - hi, - Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT })), - style, - attrs.into_thin_attrs()); + let mac = P(spanned(lo, hi, Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT })); + let stmt = StmtKind::Mac(mac, style, attrs.into_thin_attrs()); spanned(lo, hi, stmt) } else { // if it has a special ident, it's definitely an item // // Require a semicolon or braces. - if style != MacStmtWithBraces { + if style != MacStmtStyle::Braces { if !self.eat(&token::Semi) { let last_span = self.last_span; self.span_err(last_span, @@ -3757,13 +3743,13 @@ impl<'a> Parser<'a> { followed by a semicolon"); } } - spanned(lo, hi, StmtDecl( - P(spanned(lo, hi, DeclItem( + spanned(lo, hi, StmtKind::Decl( + P(spanned(lo, hi, DeclKind::Item( self.mk_item( lo, hi, id /*id is good here*/, - ItemMac(spanned(lo, hi, + ItemKind::Mac(spanned(lo, hi, Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT })), - Inherited, attrs)))), + Visibility::Inherited, attrs)))), ast::DUMMY_NODE_ID)) } } else { @@ -3771,8 +3757,8 @@ impl<'a> Parser<'a> { match try!(self.parse_item_(attrs.clone(), false, true)) { Some(i) => { let hi = i.span.hi; - let decl = P(spanned(lo, hi, DeclItem(i))); - spanned(lo, hi, StmtDecl(decl, ast::DUMMY_NODE_ID)) + let decl = P(spanned(lo, hi, DeclKind::Item(i))); + spanned(lo, hi, StmtKind::Decl(decl, ast::DUMMY_NODE_ID)) } None => { let unused_attrs = |attrs: &[_], s: &mut Self| { @@ -3798,7 +3784,7 @@ impl<'a> Parser<'a> { let e = try!(self.parse_expr_res( Restrictions::RESTRICTION_STMT_EXPR, Some(attrs.into_thin_attrs()))); let hi = e.span.hi; - let stmt = StmtExpr(e, ast::DUMMY_NODE_ID); + let stmt = StmtKind::Expr(e, ast::DUMMY_NODE_ID); spanned(lo, hi, stmt) } } @@ -3825,7 +3811,7 @@ impl<'a> Parser<'a> { "place this code inside a block")); } - self.parse_block_tail(lo, DefaultBlock) + self.parse_block_tail(lo, BlockCheckMode::Default) } /// Parse a block. Inner attrs are allowed. @@ -3835,7 +3821,7 @@ impl<'a> Parser<'a> { let lo = self.span.lo; try!(self.expect(&token::OpenDelim(token::Brace))); Ok((try!(self.parse_inner_attributes()), - try!(self.parse_block_tail(lo, DefaultBlock)))) + try!(self.parse_block_tail(lo, BlockCheckMode::Default)))) } /// Parse the rest of a block expression or function body @@ -3852,16 +3838,16 @@ impl<'a> Parser<'a> { continue; }; match node { - StmtExpr(e, _) => { + StmtKind::Expr(e, _) => { try!(self.handle_expression_like_statement(e, span, &mut stmts, &mut expr)); } - StmtMac(mac, MacStmtWithoutBraces, attrs) => { + StmtKind::Mac(mac, MacStmtStyle::NoBraces, attrs) => { // statement macro without braces; might be an // expr depending on whether a semicolon follows match self.token { token::Semi => { stmts.push(P(Spanned { - node: StmtMac(mac, MacStmtWithSemicolon, attrs), + node: StmtKind::Mac(mac, MacStmtStyle::Semicolon, attrs), span: mk_sp(span.lo, self.span.hi), })); self.bump(); @@ -3881,12 +3867,12 @@ impl<'a> Parser<'a> { } } } - StmtMac(m, style, attrs) => { + StmtKind::Mac(m, style, attrs) => { // statement macro; might be an expr match self.token { token::Semi => { stmts.push(P(Spanned { - node: StmtMac(m, MacStmtWithSemicolon, attrs), + node: StmtKind::Mac(m, MacStmtStyle::Semicolon, attrs), span: mk_sp(span.lo, self.span.hi), })); self.bump(); @@ -3900,7 +3886,7 @@ impl<'a> Parser<'a> { } _ => { stmts.push(P(Spanned { - node: StmtMac(m, style, attrs), + node: StmtKind::Mac(m, style, attrs), span: span })); } @@ -3952,14 +3938,14 @@ impl<'a> Parser<'a> { expn_id: span.expn_id, }; stmts.push(P(Spanned { - node: StmtSemi(e, ast::DUMMY_NODE_ID), + node: StmtKind::Semi(e, ast::DUMMY_NODE_ID), span: span_with_semi, })); } token::CloseDelim(token::Brace) => *last_block_expr = Some(e), _ => { stmts.push(P(Spanned { - node: StmtExpr(e, ast::DUMMY_NODE_ID), + node: StmtKind::Expr(e, ast::DUMMY_NODE_ID), span: span })); } @@ -4410,7 +4396,7 @@ impl<'a> Parser<'a> { F: FnMut(&mut Parser<'a>) -> PResult<'a, Arg>, { fn maybe_parse_borrowed_explicit_self<'b>(this: &mut Parser<'b>) - -> PResult<'b, ast::ExplicitSelf_> { + -> PResult<'b, ast::SelfKind> { // The following things are possible to see here: // // fn(&mut self) @@ -4422,26 +4408,27 @@ impl<'a> Parser<'a> { if this.look_ahead(1, |t| t.is_keyword(keywords::SelfValue)) { this.bump(); - Ok(SelfRegion(None, MutImmutable, try!(this.expect_self_ident()))) + Ok(SelfKind::Region(None, Mutability::Immutable, try!(this.expect_self_ident()))) } else if this.look_ahead(1, |t| t.is_mutability()) && this.look_ahead(2, |t| t.is_keyword(keywords::SelfValue)) { this.bump(); let mutability = try!(this.parse_mutability()); - Ok(SelfRegion(None, mutability, try!(this.expect_self_ident()))) + Ok(SelfKind::Region(None, mutability, try!(this.expect_self_ident()))) } else if this.look_ahead(1, |t| t.is_lifetime()) && this.look_ahead(2, |t| t.is_keyword(keywords::SelfValue)) { this.bump(); let lifetime = try!(this.parse_lifetime()); - Ok(SelfRegion(Some(lifetime), MutImmutable, try!(this.expect_self_ident()))) + let ident = try!(this.expect_self_ident()); + Ok(SelfKind::Region(Some(lifetime), Mutability::Immutable, ident)) } else if this.look_ahead(1, |t| t.is_lifetime()) && this.look_ahead(2, |t| t.is_mutability()) && this.look_ahead(3, |t| t.is_keyword(keywords::SelfValue)) { this.bump(); let lifetime = try!(this.parse_lifetime()); let mutability = try!(this.parse_mutability()); - Ok(SelfRegion(Some(lifetime), mutability, try!(this.expect_self_ident()))) + Ok(SelfKind::Region(Some(lifetime), mutability, try!(this.expect_self_ident()))) } else { - Ok(SelfStatic) + Ok(SelfKind::Static) } } @@ -4453,7 +4440,7 @@ impl<'a> Parser<'a> { let mut self_ident_lo = self.span.lo; let mut self_ident_hi = self.span.hi; - let mut mutbl_self = MutImmutable; + let mut mutbl_self = Mutability::Immutable; let explicit_self = match self.token { token::BinOp(token::And) => { let eself = try!(maybe_parse_borrowed_explicit_self(self)); @@ -4468,7 +4455,7 @@ impl<'a> Parser<'a> { let _mutability = if self.token.is_mutability() { try!(self.parse_mutability()) } else { - MutImmutable + Mutability::Immutable }; if self.is_self_ident() { let span = self.span; @@ -4476,7 +4463,7 @@ impl<'a> Parser<'a> { self.bump(); } // error case, making bogus self ident: - SelfValue(special_idents::self_) + SelfKind::Value(special_idents::self_) } token::Ident(..) => { if self.is_self_ident() { @@ -4485,9 +4472,9 @@ impl<'a> Parser<'a> { // Determine whether this is the fully explicit form, `self: // TYPE`. if self.eat(&token::Colon) { - SelfExplicit(try!(self.parse_ty_sum()), self_ident) + SelfKind::Explicit(try!(self.parse_ty_sum()), self_ident) } else { - SelfValue(self_ident) + SelfKind::Value(self_ident) } } else if self.token.is_mutability() && self.look_ahead(1, |t| t.is_keyword(keywords::SelfValue)) { @@ -4497,15 +4484,15 @@ impl<'a> Parser<'a> { // Determine whether this is the fully explicit form, // `self: TYPE`. if self.eat(&token::Colon) { - SelfExplicit(try!(self.parse_ty_sum()), self_ident) + SelfKind::Explicit(try!(self.parse_ty_sum()), self_ident) } else { - SelfValue(self_ident) + SelfKind::Value(self_ident) } } else { - SelfStatic + SelfKind::Static } } - _ => SelfStatic, + _ => SelfKind::Static, }; let explicit_self_sp = mk_sp(self_ident_lo, self_ident_hi); @@ -4541,14 +4528,14 @@ impl<'a> Parser<'a> { } let fn_inputs = match explicit_self { - SelfStatic => { + SelfKind::Static => { let sep = seq_sep_trailing_allowed(token::Comma); try!(self.parse_seq_to_before_end(&token::CloseDelim(token::Paren), sep, parse_arg_fn)) } - SelfValue(id) => parse_remaining_arguments!(id), - SelfRegion(_,_,id) => parse_remaining_arguments!(id), - SelfExplicit(_,id) => parse_remaining_arguments!(id), + SelfKind::Value(id) => parse_remaining_arguments!(id), + SelfKind::Region(_,_,id) => parse_remaining_arguments!(id), + SelfKind::Explicit(_,id) => parse_remaining_arguments!(id), }; @@ -4601,7 +4588,7 @@ impl<'a> Parser<'a> { } fn mk_item(&mut self, lo: BytePos, hi: BytePos, ident: Ident, - node: Item_, vis: Visibility, + node: ItemKind, vis: Visibility, attrs: Vec<Attribute>) -> P<Item> { P(Item { ident: ident, @@ -4623,7 +4610,7 @@ impl<'a> Parser<'a> { let decl = try!(self.parse_fn_decl(false)); generics.where_clause = try!(self.parse_where_clause()); let (inner_attrs, body) = try!(self.parse_inner_attrs_and_block()); - Ok((ident, ItemFn(decl, unsafety, constness, abi, generics, body), Some(inner_attrs))) + Ok((ident, ItemKind::Fn(decl, unsafety, constness, abi, generics, body), Some(inner_attrs))) } /// true if we are looking at `const ID`, false for things like `const fn` etc @@ -4646,12 +4633,12 @@ impl<'a> Parser<'a> { let is_const_fn = self.eat_keyword(keywords::Const); let unsafety = try!(self.parse_unsafety()); let (constness, unsafety, abi) = if is_const_fn { - (Constness::Const, unsafety, abi::Rust) + (Constness::Const, unsafety, Abi::Rust) } else { let abi = if self.eat_keyword(keywords::Extern) { - try!(self.parse_opt_abi()).unwrap_or(abi::C) + try!(self.parse_opt_abi()).unwrap_or(Abi::C) } else { - abi::Rust + Abi::Rust }; (Constness::NotConst, unsafety, abi) }; @@ -4699,7 +4686,7 @@ impl<'a> Parser<'a> { fn complain_if_pub_macro(&mut self, visa: Visibility, span: Span) { match visa { - Public => { + Visibility::Public => { let is_macro_rules: bool = match self.token { token::Ident(sid, _) => sid.name == intern("macro_rules"), _ => false, @@ -4717,7 +4704,7 @@ impl<'a> Parser<'a> { .emit(); } } - Inherited => (), + Visibility::Inherited => (), } } @@ -4783,7 +4770,7 @@ impl<'a> Parser<'a> { tps.where_clause = try!(self.parse_where_clause()); let meths = try!(self.parse_trait_items()); - Ok((ident, ItemTrait(unsafety, tps, bounds, meths), None)) + Ok((ident, ItemKind::Trait(unsafety, tps, bounds, meths), None)) } /// Parses items implementations variants @@ -4814,7 +4801,7 @@ impl<'a> Parser<'a> { let opt_trait = if could_be_trait && self.eat_keyword(keywords::For) { // New-style trait. Reinterpret the type as a trait. match ty.node { - TyPath(None, ref path) => { + TyKind::Path(None, ref path) => { Some(TraitRef { path: (*path).clone(), ref_id: ty.id, @@ -4846,7 +4833,7 @@ impl<'a> Parser<'a> { try!(self.expect(&token::OpenDelim(token::Brace))); try!(self.expect(&token::CloseDelim(token::Brace))); Ok((ast_util::impl_pretty_name(&opt_trait, None), - ItemDefaultImpl(unsafety, opt_trait.unwrap()), None)) + ItemKind::DefaultImpl(unsafety, opt_trait.unwrap()), None)) } else { if opt_trait.is_some() { ty = try!(self.parse_ty_sum()); @@ -4862,7 +4849,7 @@ impl<'a> Parser<'a> { } Ok((ast_util::impl_pretty_name(&opt_trait, Some(&*ty)), - ItemImpl(unsafety, polarity, generics, opt_trait, ty, impl_items), + ItemKind::Impl(unsafety, polarity, generics, opt_trait, ty, impl_items), Some(attrs))) } } @@ -4947,7 +4934,7 @@ impl<'a> Parser<'a> { name, found `{}`", token_str))) }; - Ok((class_name, ItemStruct(vdata, generics), None)) + Ok((class_name, ItemKind::Struct(vdata, generics), None)) } pub fn parse_record_struct_body(&mut self, @@ -4987,7 +4974,7 @@ impl<'a> Parser<'a> { if parse_pub == ParsePub::Yes { try!(p.parse_visibility()) } else { - Inherited + Visibility::Inherited } ), id: ast::DUMMY_NODE_ID, @@ -5033,16 +5020,16 @@ impl<'a> Parser<'a> { let span = self.last_span; self.span_err(span, "`pub` is not allowed here"); } - return self.parse_single_struct_field(Public, attrs); + return self.parse_single_struct_field(Visibility::Public, attrs); } - return self.parse_single_struct_field(Inherited, attrs); + return self.parse_single_struct_field(Visibility::Inherited, attrs); } /// Parse visibility: PUB or nothing fn parse_visibility(&mut self) -> PResult<'a, Visibility> { - if self.eat_keyword(keywords::Pub) { Ok(Public) } - else { Ok(Inherited) } + if self.eat_keyword(keywords::Pub) { Ok(Visibility::Public) } + else { Ok(Visibility::Inherited) } } /// Given a termination token, parse all of the items in a module @@ -5077,8 +5064,8 @@ impl<'a> Parser<'a> { let e = try!(self.parse_expr()); try!(self.commit_expr_expecting(&*e, token::Semi)); let item = match m { - Some(m) => ItemStatic(ty, m, e), - None => ItemConst(ty, e), + Some(m) => ItemKind::Static(ty, m, e), + None => ItemKind::Const(ty, e), }; Ok((id, item, None)) } @@ -5102,7 +5089,7 @@ impl<'a> Parser<'a> { let m = try!(self.parse_mod_items(&token::CloseDelim(token::Brace), mod_inner_lo)); self.owns_directory = old_owns_directory; self.pop_mod_path(); - Ok((id, ItemMod(m), Some(attrs))) + Ok((id, ItemKind::Mod(m), Some(attrs))) } } @@ -5208,7 +5195,7 @@ impl<'a> Parser<'a> { id: ast::Ident, outer_attrs: &[ast::Attribute], id_sp: Span) - -> PResult<'a, (ast::Item_, Vec<ast::Attribute> )> { + -> PResult<'a, (ast::ItemKind, Vec<ast::Attribute> )> { let ModulePathSuccess { path, owns_directory } = try!(self.submod_path(id, outer_attrs, id_sp)); @@ -5223,7 +5210,7 @@ impl<'a> Parser<'a> { path: PathBuf, owns_directory: bool, name: String, - id_sp: Span) -> PResult<'a, (ast::Item_, Vec<ast::Attribute> )> { + id_sp: Span) -> PResult<'a, (ast::ItemKind, Vec<ast::Attribute> )> { let mut included_mod_stack = self.sess.included_mod_stack.borrow_mut(); match included_mod_stack.iter().position(|p| *p == path) { Some(i) => { @@ -5251,7 +5238,7 @@ impl<'a> Parser<'a> { let mod_attrs = try!(p0.parse_inner_attributes()); let m0 = try!(p0.parse_mod_items(&token::Eof, mod_inner_lo)); self.sess.included_mod_stack.borrow_mut().pop(); - Ok((ast::ItemMod(m0), mod_attrs)) + Ok((ast::ItemKind::Mod(m0), mod_attrs)) } /// Parse a function declaration from a foreign module @@ -5267,7 +5254,7 @@ impl<'a> Parser<'a> { Ok(P(ast::ForeignItem { ident: ident, attrs: attrs, - node: ForeignItemFn(decl, generics), + node: ForeignItemKind::Fn(decl, generics), id: ast::DUMMY_NODE_ID, span: mk_sp(lo, hi), vis: vis @@ -5288,7 +5275,7 @@ impl<'a> Parser<'a> { Ok(P(ForeignItem { ident: ident, attrs: attrs, - node: ForeignItemStatic(ty, mutbl), + node: ForeignItemKind::Static(ty, mutbl), id: ast::DUMMY_NODE_ID, span: mk_sp(lo, hi), vis: vis @@ -5317,7 +5304,7 @@ impl<'a> Parser<'a> { let last_span = self.last_span; - if visibility == ast::Public { + if visibility == ast::Visibility::Public { self.span_warn(mk_sp(lo, last_span.hi), "`pub extern crate` does not work as expected and should not be used. \ Likely to become an error. Prefer `extern crate` and `pub use`."); @@ -5326,7 +5313,7 @@ impl<'a> Parser<'a> { Ok(self.mk_item(lo, last_span.hi, ident, - ItemExternCrate(maybe_path), + ItemKind::ExternCrate(maybe_path), visibility, attrs)) } @@ -5349,7 +5336,7 @@ impl<'a> Parser<'a> { -> PResult<'a, P<Item>> { try!(self.expect(&token::OpenDelim(token::Brace))); - let abi = opt_abi.unwrap_or(abi::C); + let abi = opt_abi.unwrap_or(Abi::C); attrs.extend(try!(self.parse_inner_attributes())); @@ -5367,7 +5354,7 @@ impl<'a> Parser<'a> { Ok(self.mk_item(lo, last_span.hi, special_idents::invalid, - ItemForeignMod(m), + ItemKind::ForeignMod(m), visibility, attrs)) } @@ -5380,7 +5367,7 @@ impl<'a> Parser<'a> { try!(self.expect(&token::Eq)); let ty = try!(self.parse_ty_sum()); try!(self.expect(&token::Semi)); - Ok((ident, ItemTy(ty, tps), None)) + Ok((ident, ItemKind::Ty(ty, tps), None)) } /// Parse the part of an "enum" decl following the '{' @@ -5441,7 +5428,7 @@ impl<'a> Parser<'a> { try!(self.expect(&token::OpenDelim(token::Brace))); let enum_definition = try!(self.parse_enum_def(&generics)); - Ok((id, ItemEnum(enum_definition, generics), None)) + Ok((id, ItemKind::Enum(enum_definition, generics), None)) } /// Parses a string as an ABI spec on an extern type or module. Consumes @@ -5499,7 +5486,7 @@ impl<'a> Parser<'a> { if self.eat_keyword(keywords::Use) { // USE ITEM - let item_ = ItemUse(try!(self.parse_view_path())); + let item_ = ItemKind::Use(try!(self.parse_view_path())); try!(self.expect(&token::Semi)); let last_span = self.last_span; @@ -5521,7 +5508,7 @@ impl<'a> Parser<'a> { if self.eat_keyword(keywords::Fn) { // EXTERN FUNCTION ITEM - let abi = opt_abi.unwrap_or(abi::C); + let abi = opt_abi.unwrap_or(Abi::C); let (ident, item_, extra_attrs) = try!(self.parse_item_fn(Unsafety::Normal, Constness::NotConst, abi)); let last_span = self.last_span; @@ -5541,7 +5528,11 @@ impl<'a> Parser<'a> { if self.eat_keyword(keywords::Static) { // STATIC ITEM - let m = if self.eat_keyword(keywords::Mut) {MutMutable} else {MutImmutable}; + let m = if self.eat_keyword(keywords::Mut) { + Mutability::Mutable + } else { + Mutability::Immutable + }; let (ident, item_, extra_attrs) = try!(self.parse_item_const(Some(m))); let last_span = self.last_span; let item = self.mk_item(lo, @@ -5564,7 +5555,7 @@ impl<'a> Parser<'a> { }; self.bump(); let (ident, item_, extra_attrs) = - try!(self.parse_item_fn(unsafety, Constness::Const, abi::Rust)); + try!(self.parse_item_fn(unsafety, Constness::Const, Abi::Rust)); let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5629,7 +5620,7 @@ impl<'a> Parser<'a> { // FUNCTION ITEM self.bump(); let (ident, item_, extra_attrs) = - try!(self.parse_item_fn(Unsafety::Normal, Constness::NotConst, abi::Rust)); + try!(self.parse_item_fn(Unsafety::Normal, Constness::NotConst, Abi::Rust)); let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5644,9 +5635,9 @@ impl<'a> Parser<'a> { // UNSAFE FUNCTION ITEM self.bump(); let abi = if self.eat_keyword(keywords::Extern) { - try!(self.parse_opt_abi()).unwrap_or(abi::C) + try!(self.parse_opt_abi()).unwrap_or(Abi::C) } else { - abi::Rust + Abi::Rust }; try!(self.expect_keyword(keywords::Fn)); let (ident, item_, extra_attrs) = @@ -5815,7 +5806,7 @@ impl<'a> Parser<'a> { } } - let item_ = ItemMac(m); + let item_ = ItemKind::Mac(m); let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, @@ -5828,8 +5819,8 @@ impl<'a> Parser<'a> { // FAILURE TO PARSE ITEM match visibility { - Inherited => {} - Public => { + Visibility::Inherited => {} + Visibility::Public => { let last_span = self.last_span; return Err(self.span_fatal(last_span, "unmatched visibility `pub`")); } @@ -5975,10 +5966,12 @@ impl<'a> Parser<'a> { Option<ast::Name>)> { let ret = match self.token { token::Literal(token::Str_(s), suf) => { - (self.id_to_interned_str(ast::Ident::with_empty_ctxt(s)), ast::CookedStr, suf) + let s = self.id_to_interned_str(ast::Ident::with_empty_ctxt(s)); + (s, ast::StrStyle::Cooked, suf) } token::Literal(token::StrRaw(s, n), suf) => { - (self.id_to_interned_str(ast::Ident::with_empty_ctxt(s)), ast::RawStr(n), suf) + let s = self.id_to_interned_str(ast::Ident::with_empty_ctxt(s)); + (s, ast::StrStyle::Raw(n), suf) } _ => return None }; diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 220d0aff2e3..7d1b78b632f 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -15,7 +15,7 @@ pub use self::IdentStyle::*; pub use self::Lit::*; pub use self::Token::*; -use ast; +use ast::{self, BinOpKind}; use ext::mtwt; use ptr::P; use util::interner::{RcStr, StrInterner}; @@ -264,26 +264,26 @@ impl Token { } /// Maps a token to its corresponding binary operator. - pub fn to_binop(&self) -> Option<ast::BinOp_> { + pub fn to_binop(&self) -> Option<BinOpKind> { match *self { - BinOp(Star) => Some(ast::BiMul), - BinOp(Slash) => Some(ast::BiDiv), - BinOp(Percent) => Some(ast::BiRem), - BinOp(Plus) => Some(ast::BiAdd), - BinOp(Minus) => Some(ast::BiSub), - BinOp(Shl) => Some(ast::BiShl), - BinOp(Shr) => Some(ast::BiShr), - BinOp(And) => Some(ast::BiBitAnd), - BinOp(Caret) => Some(ast::BiBitXor), - BinOp(Or) => Some(ast::BiBitOr), - Lt => Some(ast::BiLt), - Le => Some(ast::BiLe), - Ge => Some(ast::BiGe), - Gt => Some(ast::BiGt), - EqEq => Some(ast::BiEq), - Ne => Some(ast::BiNe), - AndAnd => Some(ast::BiAnd), - OrOr => Some(ast::BiOr), + BinOp(Star) => Some(BinOpKind::Mul), + BinOp(Slash) => Some(BinOpKind::Div), + BinOp(Percent) => Some(BinOpKind::Rem), + BinOp(Plus) => Some(BinOpKind::Add), + BinOp(Minus) => Some(BinOpKind::Sub), + BinOp(Shl) => Some(BinOpKind::Shl), + BinOp(Shr) => Some(BinOpKind::Shr), + BinOp(And) => Some(BinOpKind::BitAnd), + BinOp(Caret) => Some(BinOpKind::BitXor), + BinOp(Or) => Some(BinOpKind::BitOr), + Lt => Some(BinOpKind::Lt), + Le => Some(BinOpKind::Le), + Ge => Some(BinOpKind::Ge), + Gt => Some(BinOpKind::Gt), + EqEq => Some(BinOpKind::Eq), + Ne => Some(BinOpKind::Ne), + AndAnd => Some(BinOpKind::And), + OrOr => Some(BinOpKind::Or), _ => None, } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 759b16c5738..ab218971a51 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -10,8 +10,8 @@ pub use self::AnnNode::*; -use abi; -use ast::{self, TokenTree}; +use abi::{self, Abi}; +use ast::{self, TokenTree, BlockCheckMode}; use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; use ast::Attribute; use attr::ThinAttributesExt; @@ -382,13 +382,13 @@ pub fn fun_to_string(decl: &ast::FnDecl, unsafety: ast::Unsafety, constness: ast::Constness, name: ast::Ident, - opt_explicit_self: Option<&ast::ExplicitSelf_>, + opt_explicit_self: Option<&ast::SelfKind>, generics: &ast::Generics) -> String { to_string(|s| { try!(s.head("")); - try!(s.print_fn(decl, unsafety, constness, abi::Rust, Some(name), - generics, opt_explicit_self, ast::Inherited)); + try!(s.print_fn(decl, unsafety, constness, Abi::Rust, Some(name), + generics, opt_explicit_self, ast::Visibility::Inherited)); try!(s.end()); // Close the head box s.end() // Close the outer box }) @@ -416,8 +416,8 @@ pub fn lit_to_string(l: &ast::Lit) -> String { to_string(|s| s.print_literal(l)) } -pub fn explicit_self_to_string(explicit_self: &ast::ExplicitSelf_) -> String { - to_string(|s| s.print_explicit_self(explicit_self, ast::MutImmutable).map(|_| {})) +pub fn explicit_self_to_string(explicit_self: &ast::SelfKind) -> String { + to_string(|s| s.print_explicit_self(explicit_self, ast::Mutability::Immutable).map(|_| {})) } pub fn variant_to_string(var: &ast::Variant) -> String { @@ -434,17 +434,17 @@ pub fn mac_to_string(arg: &ast::Mac) -> String { pub fn visibility_qualified(vis: ast::Visibility, s: &str) -> String { match vis { - ast::Public => format!("pub {}", s), - ast::Inherited => s.to_string() + ast::Visibility::Public => format!("pub {}", s), + ast::Visibility::Inherited => s.to_string() } } fn needs_parentheses(expr: &ast::Expr) -> bool { match expr.node { - ast::ExprAssign(..) | ast::ExprBinary(..) | - ast::ExprClosure(..) | - ast::ExprAssignOp(..) | ast::ExprCast(..) | - ast::ExprInPlace(..) | ast::ExprType(..) => true, + ast::ExprKind::Assign(..) | ast::ExprKind::Binary(..) | + ast::ExprKind::Closure(..) | + ast::ExprKind::AssignOp(..) | ast::ExprKind::Cast(..) | + ast::ExprKind::InPlace(..) | ast::ExprKind::Type(..) => true, _ => false, } } @@ -630,53 +630,45 @@ pub trait PrintState<'a> { _ => () } match lit.node { - ast::LitStr(ref st, style) => self.print_string(&st, style), - ast::LitByte(byte) => { + ast::LitKind::Str(ref st, style) => self.print_string(&st, style), + ast::LitKind::Byte(byte) => { let mut res = String::from("b'"); res.extend(ascii::escape_default(byte).map(|c| c as char)); res.push('\''); word(self.writer(), &res[..]) } - ast::LitChar(ch) => { + ast::LitKind::Char(ch) => { let mut res = String::from("'"); res.extend(ch.escape_default()); res.push('\''); word(self.writer(), &res[..]) } - ast::LitInt(i, t) => { + ast::LitKind::Int(i, t) => { match t { - ast::SignedIntLit(st, ast::Plus) => { + ast::LitIntType::Signed(st) => { word(self.writer(), &st.val_to_string(i as i64)) } - ast::SignedIntLit(st, ast::Minus) => { - let istr = st.val_to_string(-(i as i64)); - word(self.writer(), - &format!("-{}", istr)) - } - ast::UnsignedIntLit(ut) => { + ast::LitIntType::Unsigned(ut) => { word(self.writer(), &ut.val_to_string(i)) } - ast::UnsuffixedIntLit(ast::Plus) => { + ast::LitIntType::Unsuffixed => { word(self.writer(), &format!("{}", i)) } - ast::UnsuffixedIntLit(ast::Minus) => { - word(self.writer(), &format!("-{}", i)) - } } } - ast::LitFloat(ref f, t) => { + ast::LitKind::Float(ref f, t) => { word(self.writer(), &format!( "{}{}", &f, t.ty_to_string())) } - ast::LitFloatUnsuffixed(ref f) => word(self.writer(), &f[..]), - ast::LitBool(val) => { + ast::LitKind::FloatUnsuffixed(ref f) => word(self.writer(), &f[..]), + ast::LitKind::Bool(val) => { if val { word(self.writer(), "true") } else { word(self.writer(), "false") } } - ast::LitByteStr(ref v) => { + ast::LitKind::ByteStr(ref v) => { let mut escaped: String = String::new(); for &ch in v.iter() { escaped.extend(ascii::escape_default(ch) @@ -690,10 +682,10 @@ pub trait PrintState<'a> { fn print_string(&mut self, st: &str, style: ast::StrStyle) -> io::Result<()> { let st = match style { - ast::CookedStr => { + ast::StrStyle::Cooked => { (format!("\"{}\"", st.escape_default())) } - ast::RawStr(n) => { + ast::StrStyle::Raw(n) => { (format!("r{delim}\"{string}\"{delim}", delim=repeat("#", n), string=st)) @@ -774,15 +766,15 @@ pub trait PrintState<'a> { fn print_meta_item(&mut self, item: &ast::MetaItem) -> io::Result<()> { try!(self.ibox(INDENT_UNIT)); match item.node { - ast::MetaWord(ref name) => { + ast::MetaItemKind::Word(ref name) => { try!(word(self.writer(), &name)); } - ast::MetaNameValue(ref name, ref value) => { + ast::MetaItemKind::NameValue(ref name, ref value) => { try!(self.word_space(&name[..])); try!(self.word_space("=")); try!(self.print_literal(value)); } - ast::MetaList(ref name, ref items) => { + ast::MetaItemKind::List(ref name, ref items) => { try!(word(self.writer(), &name)); try!(self.popen()); try!(self.commasep(Consistent, @@ -965,25 +957,25 @@ impl<'a> State<'a> { try!(self.maybe_print_comment(ty.span.lo)); try!(self.ibox(0)); match ty.node { - ast::TyVec(ref ty) => { + ast::TyKind::Vec(ref ty) => { try!(word(&mut self.s, "[")); try!(self.print_type(&**ty)); try!(word(&mut self.s, "]")); } - ast::TyPtr(ref mt) => { + ast::TyKind::Ptr(ref mt) => { try!(word(&mut self.s, "*")); match mt.mutbl { - ast::MutMutable => try!(self.word_nbsp("mut")), - ast::MutImmutable => try!(self.word_nbsp("const")), + ast::Mutability::Mutable => try!(self.word_nbsp("mut")), + ast::Mutability::Immutable => try!(self.word_nbsp("const")), } try!(self.print_type(&*mt.ty)); } - ast::TyRptr(ref lifetime, ref mt) => { + ast::TyKind::Rptr(ref lifetime, ref mt) => { try!(word(&mut self.s, "&")); try!(self.print_opt_lifetime(lifetime)); try!(self.print_mt(mt)); } - ast::TyTup(ref elts) => { + ast::TyKind::Tup(ref elts) => { try!(self.popen()); try!(self.commasep(Inconsistent, &elts[..], |s, ty| s.print_type(&**ty))); @@ -992,12 +984,12 @@ impl<'a> State<'a> { } try!(self.pclose()); } - ast::TyParen(ref typ) => { + ast::TyKind::Paren(ref typ) => { try!(self.popen()); try!(self.print_type(&**typ)); try!(self.pclose()); } - ast::TyBareFn(ref f) => { + ast::TyKind::BareFn(ref f) => { let generics = ast::Generics { lifetimes: f.lifetimes.clone(), ty_params: P::empty(), @@ -1013,35 +1005,35 @@ impl<'a> State<'a> { &generics, None)); } - ast::TyPath(None, ref path) => { + ast::TyKind::Path(None, ref path) => { try!(self.print_path(path, false, 0)); } - ast::TyPath(Some(ref qself), ref path) => { + ast::TyKind::Path(Some(ref qself), ref path) => { try!(self.print_qpath(path, qself, false)) } - ast::TyObjectSum(ref ty, ref bounds) => { + ast::TyKind::ObjectSum(ref ty, ref bounds) => { try!(self.print_type(&**ty)); try!(self.print_bounds("+", &bounds[..])); } - ast::TyPolyTraitRef(ref bounds) => { + ast::TyKind::PolyTraitRef(ref bounds) => { try!(self.print_bounds("", &bounds[..])); } - ast::TyFixedLengthVec(ref ty, ref v) => { + ast::TyKind::FixedLengthVec(ref ty, ref v) => { try!(word(&mut self.s, "[")); try!(self.print_type(&**ty)); try!(word(&mut self.s, "; ")); try!(self.print_expr(&**v)); try!(word(&mut self.s, "]")); } - ast::TyTypeof(ref e) => { + ast::TyKind::Typeof(ref e) => { try!(word(&mut self.s, "typeof(")); try!(self.print_expr(&**e)); try!(word(&mut self.s, ")")); } - ast::TyInfer => { + ast::TyKind::Infer => { try!(word(&mut self.s, "_")); } - ast::TyMac(ref m) => { + ast::TyKind::Mac(ref m) => { try!(self.print_mac(m, token::Paren)); } } @@ -1054,17 +1046,17 @@ impl<'a> State<'a> { try!(self.maybe_print_comment(item.span.lo)); try!(self.print_outer_attributes(&item.attrs)); match item.node { - ast::ForeignItemFn(ref decl, ref generics) => { + ast::ForeignItemKind::Fn(ref decl, ref generics) => { try!(self.head("")); try!(self.print_fn(decl, ast::Unsafety::Normal, ast::Constness::NotConst, - abi::Rust, Some(item.ident), + Abi::Rust, Some(item.ident), generics, None, item.vis)); try!(self.end()); // end head-ibox try!(word(&mut self.s, ";")); self.end() // end the outer fn box } - ast::ForeignItemStatic(ref t, m) => { + ast::ForeignItemKind::Static(ref t, m) => { try!(self.head(&visibility_qualified(item.vis, "static"))); if m { @@ -1125,13 +1117,13 @@ impl<'a> State<'a> { try!(self.print_outer_attributes(&item.attrs)); try!(self.ann.pre(self, NodeItem(item))); match item.node { - ast::ItemExternCrate(ref optional_path) => { + ast::ItemKind::ExternCrate(ref optional_path) => { try!(self.head(&visibility_qualified(item.vis, "extern crate"))); if let Some(p) = *optional_path { let val = p.as_str(); if val.contains("-") { - try!(self.print_string(&val, ast::CookedStr)); + try!(self.print_string(&val, ast::StrStyle::Cooked)); } else { try!(self.print_name(p)); } @@ -1144,7 +1136,7 @@ impl<'a> State<'a> { try!(self.end()); // end inner head-block try!(self.end()); // end outer head-block } - ast::ItemUse(ref vp) => { + ast::ItemKind::Use(ref vp) => { try!(self.head(&visibility_qualified(item.vis, "use"))); try!(self.print_view_path(&**vp)); @@ -1152,10 +1144,10 @@ impl<'a> State<'a> { try!(self.end()); // end inner head-block try!(self.end()); // end outer head-block } - ast::ItemStatic(ref ty, m, ref expr) => { + ast::ItemKind::Static(ref ty, m, ref expr) => { try!(self.head(&visibility_qualified(item.vis, "static"))); - if m == ast::MutMutable { + if m == ast::Mutability::Mutable { try!(self.word_space("mut")); } try!(self.print_ident(item.ident)); @@ -1169,7 +1161,7 @@ impl<'a> State<'a> { try!(word(&mut self.s, ";")); try!(self.end()); // end the outer cbox } - ast::ItemConst(ref ty, ref expr) => { + ast::ItemKind::Const(ref ty, ref expr) => { try!(self.head(&visibility_qualified(item.vis, "const"))); try!(self.print_ident(item.ident)); @@ -1183,7 +1175,7 @@ impl<'a> State<'a> { try!(word(&mut self.s, ";")); try!(self.end()); // end the outer cbox } - ast::ItemFn(ref decl, unsafety, constness, abi, ref typarams, ref body) => { + ast::ItemKind::Fn(ref decl, unsafety, constness, abi, ref typarams, ref body) => { try!(self.head("")); try!(self.print_fn( decl, @@ -1198,7 +1190,7 @@ impl<'a> State<'a> { try!(word(&mut self.s, " ")); try!(self.print_block_with_attrs(&**body, &item.attrs)); } - ast::ItemMod(ref _mod) => { + ast::ItemKind::Mod(ref _mod) => { try!(self.head(&visibility_qualified(item.vis, "mod"))); try!(self.print_ident(item.ident)); @@ -1207,14 +1199,14 @@ impl<'a> State<'a> { try!(self.print_mod(_mod, &item.attrs)); try!(self.bclose(item.span)); } - ast::ItemForeignMod(ref nmod) => { + ast::ItemKind::ForeignMod(ref nmod) => { try!(self.head("extern")); try!(self.word_nbsp(&nmod.abi.to_string())); try!(self.bopen()); try!(self.print_foreign_mod(nmod, &item.attrs)); try!(self.bclose(item.span)); } - ast::ItemTy(ref ty, ref params) => { + ast::ItemKind::Ty(ref ty, ref params) => { try!(self.ibox(INDENT_UNIT)); try!(self.ibox(0)); try!(self.word_nbsp(&visibility_qualified(item.vis, "type"))); @@ -1229,7 +1221,7 @@ impl<'a> State<'a> { try!(word(&mut self.s, ";")); try!(self.end()); // end the outer ibox } - ast::ItemEnum(ref enum_definition, ref params) => { + ast::ItemKind::Enum(ref enum_definition, ref params) => { try!(self.print_enum_def( enum_definition, params, @@ -1238,12 +1230,12 @@ impl<'a> State<'a> { item.vis )); } - ast::ItemStruct(ref struct_def, ref generics) => { + ast::ItemKind::Struct(ref struct_def, ref generics) => { try!(self.head(&visibility_qualified(item.vis,"struct"))); try!(self.print_struct(&struct_def, generics, item.ident, item.span, true)); } - ast::ItemDefaultImpl(unsafety, ref trait_ref) => { + ast::ItemKind::DefaultImpl(unsafety, ref trait_ref) => { try!(self.head("")); try!(self.print_visibility(item.vis)); try!(self.print_unsafety(unsafety)); @@ -1255,7 +1247,7 @@ impl<'a> State<'a> { try!(self.bopen()); try!(self.bclose(item.span)); } - ast::ItemImpl(unsafety, + ast::ItemKind::Impl(unsafety, polarity, ref generics, ref opt_trait, @@ -1298,7 +1290,7 @@ impl<'a> State<'a> { } try!(self.bclose(item.span)); } - ast::ItemTrait(unsafety, ref generics, ref bounds, ref trait_items) => { + ast::ItemKind::Trait(unsafety, ref generics, ref bounds, ref trait_items) => { try!(self.head("")); try!(self.print_visibility(item.vis)); try!(self.print_unsafety(unsafety)); @@ -1324,7 +1316,7 @@ impl<'a> State<'a> { } try!(self.bclose(item.span)); } - ast::ItemMac(codemap::Spanned { ref node, .. }) => { + ast::ItemKind::Mac(codemap::Spanned { ref node, .. }) => { try!(self.print_visibility(item.vis)); try!(self.print_path(&node.path, false, 0)); try!(word(&mut self.s, "! ")); @@ -1396,8 +1388,8 @@ impl<'a> State<'a> { pub fn print_visibility(&mut self, vis: ast::Visibility) -> io::Result<()> { match vis { - ast::Public => self.word_nbsp("pub"), - ast::Inherited => Ok(()) + ast::Visibility::Public => self.word_nbsp("pub"), + ast::Visibility::Inherited => Ok(()) } } @@ -1497,8 +1489,8 @@ impl<'a> State<'a> { None => {}, } match seq.op { - ast::ZeroOrMore => word(&mut self.s, "*"), - ast::OneOrMore => word(&mut self.s, "+"), + ast::KleeneOp::ZeroOrMore => word(&mut self.s, "*"), + ast::KleeneOp::OneOrMore => word(&mut self.s, "+"), } } } @@ -1560,16 +1552,16 @@ impl<'a> State<'a> { try!(self.maybe_print_comment(ti.span.lo)); try!(self.print_outer_attributes(&ti.attrs)); match ti.node { - ast::ConstTraitItem(ref ty, ref default) => { + ast::TraitItemKind::Const(ref ty, ref default) => { try!(self.print_associated_const(ti.ident, &ty, default.as_ref().map(|expr| &**expr), - ast::Inherited)); + ast::Visibility::Inherited)); } - ast::MethodTraitItem(ref sig, ref body) => { + ast::TraitItemKind::Method(ref sig, ref body) => { if body.is_some() { try!(self.head("")); } - try!(self.print_method_sig(ti.ident, sig, ast::Inherited)); + try!(self.print_method_sig(ti.ident, sig, ast::Visibility::Inherited)); if let Some(ref body) = *body { try!(self.nbsp()); try!(self.print_block_with_attrs(body, &ti.attrs)); @@ -1577,7 +1569,7 @@ impl<'a> State<'a> { try!(word(&mut self.s, ";")); } } - ast::TypeTraitItem(ref bounds, ref default) => { + ast::TraitItemKind::Type(ref bounds, ref default) => { try!(self.print_associated_type(ti.ident, Some(bounds), default.as_ref().map(|ty| &**ty))); } @@ -1604,7 +1596,7 @@ impl<'a> State<'a> { try!(self.print_associated_type(ii.ident, None, Some(ty))); } ast::ImplItemKind::Macro(codemap::Spanned { ref node, .. }) => { - // code copied from ItemMac: + // code copied from ItemKind::Mac: try!(self.print_path(&node.path, false, 0)); try!(word(&mut self.s, "! ")); try!(self.cbox(INDENT_UNIT)); @@ -1621,28 +1613,28 @@ impl<'a> State<'a> { pub fn print_stmt(&mut self, st: &ast::Stmt) -> io::Result<()> { try!(self.maybe_print_comment(st.span.lo)); match st.node { - ast::StmtDecl(ref decl, _) => { + ast::StmtKind::Decl(ref decl, _) => { try!(self.print_decl(&**decl)); } - ast::StmtExpr(ref expr, _) => { + ast::StmtKind::Expr(ref expr, _) => { try!(self.space_if_not_bol()); try!(self.print_expr_outer_attr_style(&**expr, false)); } - ast::StmtSemi(ref expr, _) => { + ast::StmtKind::Semi(ref expr, _) => { try!(self.space_if_not_bol()); try!(self.print_expr_outer_attr_style(&**expr, false)); try!(word(&mut self.s, ";")); } - ast::StmtMac(ref mac, style, ref attrs) => { + ast::StmtKind::Mac(ref mac, style, ref attrs) => { try!(self.space_if_not_bol()); try!(self.print_outer_attributes(attrs.as_attr_slice())); let delim = match style { - ast::MacStmtWithBraces => token::Brace, + ast::MacStmtStyle::Braces => token::Brace, _ => token::Paren }; try!(self.print_mac(&**mac, delim)); match style { - ast::MacStmtWithBraces => {} + ast::MacStmtStyle::Braces => {} _ => try!(word(&mut self.s, ";")), } } @@ -1684,8 +1676,8 @@ impl<'a> State<'a> { attrs: &[ast::Attribute], close_box: bool) -> io::Result<()> { match blk.rules { - ast::UnsafeBlock(..) => try!(self.word_space("unsafe")), - ast::DefaultBlock => () + BlockCheckMode::Unsafe(..) => try!(self.word_space("unsafe")), + BlockCheckMode::Default => () } try!(self.maybe_print_comment(blk.span.lo)); try!(self.ann.pre(self, NodeBlock(blk))); @@ -1713,7 +1705,7 @@ impl<'a> State<'a> { Some(_else) => { match _else.node { // "another else-if" - ast::ExprIf(ref i, ref then, ref e) => { + ast::ExprKind::If(ref i, ref then, ref e) => { try!(self.cbox(INDENT_UNIT - 1)); try!(self.ibox(0)); try!(word(&mut self.s, " else if ")); @@ -1723,7 +1715,7 @@ impl<'a> State<'a> { self.print_else(e.as_ref().map(|e| &**e)) } // "another else-if-let" - ast::ExprIfLet(ref pat, ref expr, ref then, ref e) => { + ast::ExprKind::IfLet(ref pat, ref expr, ref then, ref e) => { try!(self.cbox(INDENT_UNIT - 1)); try!(self.ibox(0)); try!(word(&mut self.s, " else if let ")); @@ -1736,7 +1728,7 @@ impl<'a> State<'a> { self.print_else(e.as_ref().map(|e| &**e)) } // "final else" - ast::ExprBlock(ref b) => { + ast::ExprKind::Block(ref b) => { try!(self.cbox(INDENT_UNIT - 1)); try!(self.ibox(0)); try!(word(&mut self.s, " else ")); @@ -1803,7 +1795,7 @@ impl<'a> State<'a> { pub fn check_expr_bin_needs_paren(&mut self, sub_expr: &ast::Expr, binop: ast::BinOp) -> bool { match sub_expr.node { - ast::ExprBinary(ref sub_op, _, _) => { + ast::ExprKind::Binary(ref sub_op, _, _) => { if AssocOp::from_ast_binop(sub_op.node).precedence() < AssocOp::from_ast_binop(binop.node).precedence() { true @@ -1985,45 +1977,45 @@ impl<'a> State<'a> { try!(self.ibox(INDENT_UNIT)); try!(self.ann.pre(self, NodeExpr(expr))); match expr.node { - ast::ExprBox(ref expr) => { + ast::ExprKind::Box(ref expr) => { try!(self.word_space("box")); try!(self.print_expr(expr)); } - ast::ExprInPlace(ref place, ref expr) => { + ast::ExprKind::InPlace(ref place, ref expr) => { try!(self.print_expr_in_place(place, expr)); } - ast::ExprVec(ref exprs) => { + ast::ExprKind::Vec(ref exprs) => { try!(self.print_expr_vec(&exprs[..], attrs)); } - ast::ExprRepeat(ref element, ref count) => { + ast::ExprKind::Repeat(ref element, ref count) => { try!(self.print_expr_repeat(&**element, &**count, attrs)); } - ast::ExprStruct(ref path, ref fields, ref wth) => { + ast::ExprKind::Struct(ref path, ref fields, ref wth) => { try!(self.print_expr_struct(path, &fields[..], wth, attrs)); } - ast::ExprTup(ref exprs) => { + ast::ExprKind::Tup(ref exprs) => { try!(self.print_expr_tup(&exprs[..], attrs)); } - ast::ExprCall(ref func, ref args) => { + ast::ExprKind::Call(ref func, ref args) => { try!(self.print_expr_call(&**func, &args[..])); } - ast::ExprMethodCall(ident, ref tys, ref args) => { + ast::ExprKind::MethodCall(ident, ref tys, ref args) => { try!(self.print_expr_method_call(ident, &tys[..], &args[..])); } - ast::ExprBinary(op, ref lhs, ref rhs) => { + ast::ExprKind::Binary(op, ref lhs, ref rhs) => { try!(self.print_expr_binary(op, &**lhs, &**rhs)); } - ast::ExprUnary(op, ref expr) => { + ast::ExprKind::Unary(op, ref expr) => { try!(self.print_expr_unary(op, &**expr)); } - ast::ExprAddrOf(m, ref expr) => { + ast::ExprKind::AddrOf(m, ref expr) => { try!(self.print_expr_addr_of(m, &**expr)); } - ast::ExprLit(ref lit) => { + ast::ExprKind::Lit(ref lit) => { try!(self.print_literal(&**lit)); } - ast::ExprCast(ref expr, ref ty) => { - if let ast::ExprCast(..) = expr.node { + ast::ExprKind::Cast(ref expr, ref ty) => { + if let ast::ExprKind::Cast(..) = expr.node { try!(self.print_expr(&**expr)); } else { try!(self.print_expr_maybe_paren(&**expr)); @@ -2032,18 +2024,18 @@ impl<'a> State<'a> { try!(self.word_space("as")); try!(self.print_type(&**ty)); } - ast::ExprType(ref expr, ref ty) => { + ast::ExprKind::Type(ref expr, ref ty) => { try!(self.print_expr(&**expr)); try!(self.word_space(":")); try!(self.print_type(&**ty)); } - ast::ExprIf(ref test, ref blk, ref elseopt) => { + ast::ExprKind::If(ref test, ref blk, ref elseopt) => { try!(self.print_if(&**test, &**blk, elseopt.as_ref().map(|e| &**e))); } - ast::ExprIfLet(ref pat, ref expr, ref blk, ref elseopt) => { + ast::ExprKind::IfLet(ref pat, ref expr, ref blk, ref elseopt) => { try!(self.print_if_let(&**pat, &**expr, &** blk, elseopt.as_ref().map(|e| &**e))); } - ast::ExprWhile(ref test, ref blk, opt_ident) => { + ast::ExprKind::While(ref test, ref blk, opt_ident) => { if let Some(ident) = opt_ident { try!(self.print_ident(ident)); try!(self.word_space(":")); @@ -2053,7 +2045,7 @@ impl<'a> State<'a> { try!(space(&mut self.s)); try!(self.print_block_with_attrs(&**blk, attrs)); } - ast::ExprWhileLet(ref pat, ref expr, ref blk, opt_ident) => { + ast::ExprKind::WhileLet(ref pat, ref expr, ref blk, opt_ident) => { if let Some(ident) = opt_ident { try!(self.print_ident(ident)); try!(self.word_space(":")); @@ -2066,7 +2058,7 @@ impl<'a> State<'a> { try!(space(&mut self.s)); try!(self.print_block_with_attrs(&**blk, attrs)); } - ast::ExprForLoop(ref pat, ref iter, ref blk, opt_ident) => { + ast::ExprKind::ForLoop(ref pat, ref iter, ref blk, opt_ident) => { if let Some(ident) = opt_ident { try!(self.print_ident(ident)); try!(self.word_space(":")); @@ -2079,7 +2071,7 @@ impl<'a> State<'a> { try!(space(&mut self.s)); try!(self.print_block_with_attrs(&**blk, attrs)); } - ast::ExprLoop(ref blk, opt_ident) => { + ast::ExprKind::Loop(ref blk, opt_ident) => { if let Some(ident) = opt_ident { try!(self.print_ident(ident)); try!(self.word_space(":")); @@ -2088,7 +2080,7 @@ impl<'a> State<'a> { try!(space(&mut self.s)); try!(self.print_block_with_attrs(&**blk, attrs)); } - ast::ExprMatch(ref expr, ref arms) => { + ast::ExprKind::Match(ref expr, ref arms) => { try!(self.cbox(INDENT_UNIT)); try!(self.ibox(4)); try!(self.word_nbsp("match")); @@ -2101,14 +2093,14 @@ impl<'a> State<'a> { } try!(self.bclose_(expr.span, INDENT_UNIT)); } - ast::ExprClosure(capture_clause, ref decl, ref body) => { + ast::ExprKind::Closure(capture_clause, ref decl, ref body) => { try!(self.print_capture_clause(capture_clause)); try!(self.print_fn_block_args(&**decl)); try!(space(&mut self.s)); let default_return = match decl.output { - ast::DefaultReturn(..) => true, + ast::FunctionRetTy::Default(..) => true, _ => false }; @@ -2118,7 +2110,7 @@ impl<'a> State<'a> { // we extract the block, so as not to create another set of boxes let i_expr = body.expr.as_ref().unwrap(); match i_expr.node { - ast::ExprBlock(ref blk) => { + ast::ExprKind::Block(ref blk) => { try!(self.print_block_unclosed_with_attrs( &**blk, i_expr.attrs.as_attr_slice())); @@ -2135,43 +2127,43 @@ impl<'a> State<'a> { // empty box to satisfy the close. try!(self.ibox(0)); } - ast::ExprBlock(ref blk) => { + ast::ExprKind::Block(ref blk) => { // containing cbox, will be closed by print-block at } try!(self.cbox(INDENT_UNIT)); // head-box, will be closed by print-block after { try!(self.ibox(0)); try!(self.print_block_with_attrs(&**blk, attrs)); } - ast::ExprAssign(ref lhs, ref rhs) => { + ast::ExprKind::Assign(ref lhs, ref rhs) => { try!(self.print_expr(&**lhs)); try!(space(&mut self.s)); try!(self.word_space("=")); try!(self.print_expr(&**rhs)); } - ast::ExprAssignOp(op, ref lhs, ref rhs) => { + ast::ExprKind::AssignOp(op, ref lhs, ref rhs) => { try!(self.print_expr(&**lhs)); try!(space(&mut self.s)); try!(word(&mut self.s, op.node.to_string())); try!(self.word_space("=")); try!(self.print_expr(&**rhs)); } - ast::ExprField(ref expr, id) => { + ast::ExprKind::Field(ref expr, id) => { try!(self.print_expr(&**expr)); try!(word(&mut self.s, ".")); try!(self.print_ident(id.node)); } - ast::ExprTupField(ref expr, id) => { + ast::ExprKind::TupField(ref expr, id) => { try!(self.print_expr(&**expr)); try!(word(&mut self.s, ".")); try!(self.print_usize(id.node)); } - ast::ExprIndex(ref expr, ref index) => { + ast::ExprKind::Index(ref expr, ref index) => { try!(self.print_expr(&**expr)); try!(word(&mut self.s, "[")); try!(self.print_expr(&**index)); try!(word(&mut self.s, "]")); } - ast::ExprRange(ref start, ref end) => { + ast::ExprKind::Range(ref start, ref end) => { if let &Some(ref e) = start { try!(self.print_expr(&**e)); } @@ -2180,13 +2172,13 @@ impl<'a> State<'a> { try!(self.print_expr(&**e)); } } - ast::ExprPath(None, ref path) => { + ast::ExprKind::Path(None, ref path) => { try!(self.print_path(path, true, 0)) } - ast::ExprPath(Some(ref qself), ref path) => { + ast::ExprKind::Path(Some(ref qself), ref path) => { try!(self.print_qpath(path, qself, true)) } - ast::ExprBreak(opt_ident) => { + ast::ExprKind::Break(opt_ident) => { try!(word(&mut self.s, "break")); try!(space(&mut self.s)); if let Some(ident) = opt_ident { @@ -2194,7 +2186,7 @@ impl<'a> State<'a> { try!(space(&mut self.s)); } } - ast::ExprAgain(opt_ident) => { + ast::ExprKind::Again(opt_ident) => { try!(word(&mut self.s, "continue")); try!(space(&mut self.s)); if let Some(ident) = opt_ident { @@ -2202,7 +2194,7 @@ impl<'a> State<'a> { try!(space(&mut self.s)) } } - ast::ExprRet(ref result) => { + ast::ExprKind::Ret(ref result) => { try!(word(&mut self.s, "return")); match *result { Some(ref expr) => { @@ -2212,7 +2204,7 @@ impl<'a> State<'a> { _ => () } } - ast::ExprInlineAsm(ref a) => { + ast::ExprKind::InlineAsm(ref a) => { try!(word(&mut self.s, "asm!")); try!(self.popen()); try!(self.print_string(&a.asm, a.asm_str_style)); @@ -2223,9 +2215,9 @@ impl<'a> State<'a> { match out.constraint.slice_shift_char() { Some(('=', operand)) if out.is_rw => { try!(s.print_string(&format!("+{}", operand), - ast::CookedStr)) + ast::StrStyle::Cooked)) } - _ => try!(s.print_string(&out.constraint, ast::CookedStr)) + _ => try!(s.print_string(&out.constraint, ast::StrStyle::Cooked)) } try!(s.popen()); try!(s.print_expr(&*out.expr)); @@ -2237,7 +2229,7 @@ impl<'a> State<'a> { try!(self.commasep(Inconsistent, &a.inputs, |s, &(ref co, ref o)| { - try!(s.print_string(&co, ast::CookedStr)); + try!(s.print_string(&co, ast::StrStyle::Cooked)); try!(s.popen()); try!(s.print_expr(&**o)); try!(s.pclose()); @@ -2248,7 +2240,7 @@ impl<'a> State<'a> { try!(self.commasep(Inconsistent, &a.clobbers, |s, co| { - try!(s.print_string(&co, ast::CookedStr)); + try!(s.print_string(&co, ast::StrStyle::Cooked)); Ok(()) })); @@ -2268,15 +2260,15 @@ impl<'a> State<'a> { try!(self.word_space(":")); try!(self.commasep(Inconsistent, &*options, |s, &co| { - try!(s.print_string(co, ast::CookedStr)); + try!(s.print_string(co, ast::StrStyle::Cooked)); Ok(()) })); } try!(self.pclose()); } - ast::ExprMac(ref m) => try!(self.print_mac(m, token::Paren)), - ast::ExprParen(ref e) => { + ast::ExprKind::Mac(ref m) => try!(self.print_mac(m, token::Paren)), + ast::ExprKind::Paren(ref e) => { try!(self.popen()); try!(self.print_inner_attributes_inline(attrs)); try!(self.print_expr(&**e)); @@ -2299,7 +2291,7 @@ impl<'a> State<'a> { pub fn print_decl(&mut self, decl: &ast::Decl) -> io::Result<()> { try!(self.maybe_print_comment(decl.span.lo)); match decl.node { - ast::DeclLocal(ref loc) => { + ast::DeclKind::Local(ref loc) => { try!(self.print_outer_attributes(loc.attrs.as_attr_slice())); try!(self.space_if_not_bol()); try!(self.ibox(INDENT_UNIT)); @@ -2315,7 +2307,7 @@ impl<'a> State<'a> { } self.end() } - ast::DeclItem(ref item) => self.print_item(&**item) + ast::DeclKind::Item(ref item) => self.print_item(&**item) } } @@ -2472,8 +2464,8 @@ impl<'a> State<'a> { try!(self.word_nbsp("ref")); try!(self.print_mutability(mutbl)); } - ast::BindingMode::ByValue(ast::MutImmutable) => {} - ast::BindingMode::ByValue(ast::MutMutable) => { + ast::BindingMode::ByValue(ast::Mutability::Immutable) => {} + ast::BindingMode::ByValue(ast::Mutability::Mutable) => { try!(self.word_nbsp("mut")); } } @@ -2542,7 +2534,7 @@ impl<'a> State<'a> { } ast::PatRegion(ref inner, mutbl) => { try!(word(&mut self.s, "&")); - if mutbl == ast::MutMutable { + if mutbl == ast::Mutability::Mutable { try!(word(&mut self.s, "mut ")); } try!(self.print_pat(&**inner)); @@ -2605,12 +2597,12 @@ impl<'a> State<'a> { try!(self.word_space("=>")); match arm.body.node { - ast::ExprBlock(ref blk) => { + ast::ExprKind::Block(ref blk) => { // the block will close the pattern's ibox try!(self.print_block_unclosed_indent(&**blk, INDENT_UNIT)); // If it is a user-provided unsafe block, print a comma after it - if let ast::UnsafeBlock(ast::UserProvided) = blk.rules { + if let BlockCheckMode::Unsafe(ast::UserProvided) = blk.rules { try!(word(&mut self.s, ",")); } } @@ -2625,21 +2617,21 @@ impl<'a> State<'a> { // Returns whether it printed anything fn print_explicit_self(&mut self, - explicit_self: &ast::ExplicitSelf_, + explicit_self: &ast::SelfKind, mutbl: ast::Mutability) -> io::Result<bool> { try!(self.print_mutability(mutbl)); match *explicit_self { - ast::SelfStatic => { return Ok(false); } - ast::SelfValue(_) => { + ast::SelfKind::Static => { return Ok(false); } + ast::SelfKind::Value(_) => { try!(word(&mut self.s, "self")); } - ast::SelfRegion(ref lt, m, _) => { + ast::SelfKind::Region(ref lt, m, _) => { try!(word(&mut self.s, "&")); try!(self.print_opt_lifetime(lt)); try!(self.print_mutability(m)); try!(word(&mut self.s, "self")); } - ast::SelfExplicit(ref typ, _) => { + ast::SelfKind::Explicit(ref typ, _) => { try!(word(&mut self.s, "self")); try!(self.word_space(":")); try!(self.print_type(&**typ)); @@ -2655,7 +2647,7 @@ impl<'a> State<'a> { abi: abi::Abi, name: Option<ast::Ident>, generics: &ast::Generics, - opt_explicit_self: Option<&ast::ExplicitSelf_>, + opt_explicit_self: Option<&ast::SelfKind>, vis: ast::Visibility) -> io::Result<()> { try!(self.print_fn_header_info(unsafety, constness, abi, vis)); @@ -2669,7 +2661,7 @@ impl<'a> State<'a> { } pub fn print_fn_args(&mut self, decl: &ast::FnDecl, - opt_explicit_self: Option<&ast::ExplicitSelf_>, + opt_explicit_self: Option<&ast::SelfKind>, is_closure: bool) -> io::Result<()> { // It is unfortunate to duplicate the commasep logic, but we want the // self type and the args all in the same box. @@ -2677,10 +2669,10 @@ impl<'a> State<'a> { let mut first = true; if let Some(explicit_self) = opt_explicit_self { let m = match *explicit_self { - ast::SelfStatic => ast::MutImmutable, + ast::SelfKind::Static => ast::Mutability::Immutable, _ => match decl.inputs[0].pat.node { ast::PatIdent(ast::BindingMode::ByValue(m), _, _) => m, - _ => ast::MutImmutable + _ => ast::Mutability::Immutable } }; first = !try!(self.print_explicit_self(explicit_self, m)); @@ -2702,7 +2694,7 @@ impl<'a> State<'a> { } pub fn print_fn_args_and_ret(&mut self, decl: &ast::FnDecl, - opt_explicit_self: Option<&ast::ExplicitSelf_>) + opt_explicit_self: Option<&ast::SelfKind>) -> io::Result<()> { try!(self.popen()); try!(self.print_fn_args(decl, opt_explicit_self, false)); @@ -2722,30 +2714,30 @@ impl<'a> State<'a> { try!(self.print_fn_args(decl, None, true)); try!(word(&mut self.s, "|")); - if let ast::DefaultReturn(..) = decl.output { + if let ast::FunctionRetTy::Default(..) = decl.output { return Ok(()); } try!(self.space_if_not_bol()); try!(self.word_space("->")); match decl.output { - ast::Return(ref ty) => { + ast::FunctionRetTy::Ty(ref ty) => { try!(self.print_type(&**ty)); self.maybe_print_comment(ty.span.lo) } - ast::DefaultReturn(..) => unreachable!(), - ast::NoReturn(span) => { + ast::FunctionRetTy::Default(..) => unreachable!(), + ast::FunctionRetTy::None(span) => { try!(self.word_nbsp("!")); self.maybe_print_comment(span.lo) } } } - pub fn print_capture_clause(&mut self, capture_clause: ast::CaptureClause) + pub fn print_capture_clause(&mut self, capture_clause: ast::CaptureBy) -> io::Result<()> { match capture_clause { - ast::CaptureByValue => self.word_space("move"), - ast::CaptureByRef => Ok(()), + ast::CaptureBy::Value => self.word_space("move"), + ast::CaptureBy::Ref => Ok(()), } } @@ -2926,7 +2918,7 @@ impl<'a> State<'a> { } try!(self.commasep(Inconsistent, &idents[..], |s, w| { match w.node { - ast::PathListIdent { name, rename, .. } => { + ast::PathListItemKind::Ident { name, rename, .. } => { try!(s.print_ident(name)); if let Some(ident) = rename { try!(space(&mut s.s)); @@ -2935,7 +2927,7 @@ impl<'a> State<'a> { } Ok(()) }, - ast::PathListMod { rename, .. } => { + ast::PathListItemKind::Mod { rename, .. } => { try!(word(&mut s.s, "self")); if let Some(ident) = rename { try!(space(&mut s.s)); @@ -2954,8 +2946,8 @@ impl<'a> State<'a> { pub fn print_mutability(&mut self, mutbl: ast::Mutability) -> io::Result<()> { match mutbl { - ast::MutMutable => self.word_nbsp("mut"), - ast::MutImmutable => Ok(()), + ast::Mutability::Mutable => self.word_nbsp("mut"), + ast::Mutability::Immutable => Ok(()), } } @@ -2967,7 +2959,7 @@ impl<'a> State<'a> { pub fn print_arg(&mut self, input: &ast::Arg, is_closure: bool) -> io::Result<()> { try!(self.ibox(INDENT_UNIT)); match input.ty.node { - ast::TyInfer if is_closure => try!(self.print_pat(&*input.pat)), + ast::TyKind::Infer if is_closure => try!(self.print_pat(&*input.pat)), _ => { match input.pat.node { ast::PatIdent(_, ref path1, _) if @@ -2988,7 +2980,7 @@ impl<'a> State<'a> { } pub fn print_fn_output(&mut self, decl: &ast::FnDecl) -> io::Result<()> { - if let ast::DefaultReturn(..) = decl.output { + if let ast::FunctionRetTy::Default(..) = decl.output { return Ok(()); } @@ -2996,16 +2988,16 @@ impl<'a> State<'a> { try!(self.ibox(INDENT_UNIT)); try!(self.word_space("->")); match decl.output { - ast::NoReturn(_) => + ast::FunctionRetTy::None(_) => try!(self.word_nbsp("!")), - ast::DefaultReturn(..) => unreachable!(), - ast::Return(ref ty) => + ast::FunctionRetTy::Default(..) => unreachable!(), + ast::FunctionRetTy::Ty(ref ty) => try!(self.print_type(&**ty)) } try!(self.end()); match decl.output { - ast::Return(ref output) => self.maybe_print_comment(output.span.lo), + ast::FunctionRetTy::Ty(ref output) => self.maybe_print_comment(output.span.lo), _ => Ok(()) } } @@ -3016,7 +3008,7 @@ impl<'a> State<'a> { decl: &ast::FnDecl, name: Option<ast::Ident>, generics: &ast::Generics, - opt_explicit_self: Option<&ast::ExplicitSelf_>) + opt_explicit_self: Option<&ast::SelfKind>) -> io::Result<()> { try!(self.ibox(INDENT_UNIT)); if !generics.lifetimes.is_empty() || !generics.ty_params.is_empty() { @@ -3038,7 +3030,7 @@ impl<'a> State<'a> { name, &generics, opt_explicit_self, - ast::Inherited)); + ast::Visibility::Inherited)); self.end() } @@ -3086,10 +3078,10 @@ impl<'a> State<'a> { } pub fn print_opt_abi_and_extern_if_nondefault(&mut self, - opt_abi: Option<abi::Abi>) + opt_abi: Option<Abi>) -> io::Result<()> { match opt_abi { - Some(abi::Rust) => Ok(()), + Some(Abi::Rust) => Ok(()), Some(abi) => { try!(self.word_nbsp("extern")); self.word_nbsp(&abi.to_string()) @@ -3099,7 +3091,7 @@ impl<'a> State<'a> { } pub fn print_extern_opt_abi(&mut self, - opt_abi: Option<abi::Abi>) -> io::Result<()> { + opt_abi: Option<Abi>) -> io::Result<()> { match opt_abi { Some(abi) => { try!(self.word_nbsp("extern")); @@ -3112,7 +3104,7 @@ impl<'a> State<'a> { pub fn print_fn_header_info(&mut self, unsafety: ast::Unsafety, constness: ast::Constness, - abi: abi::Abi, + abi: Abi, vis: ast::Visibility) -> io::Result<()> { try!(word(&mut self.s, &visibility_qualified(vis, ""))); @@ -3123,7 +3115,7 @@ impl<'a> State<'a> { try!(self.print_unsafety(unsafety)); - if abi != abi::Rust { + if abi != Abi::Rust { try!(self.word_nbsp("extern")); try!(self.word_nbsp(&abi.to_string())); } @@ -3155,7 +3147,7 @@ mod tests { let decl = ast::FnDecl { inputs: Vec::new(), - output: ast::DefaultReturn(codemap::DUMMY_SP), + output: ast::FunctionRetTy::Default(codemap::DUMMY_SP), variadic: false }; let generics = ast::Generics::default(); @@ -3181,12 +3173,4 @@ mod tests { let varstr = variant_to_string(&var); assert_eq!(varstr, "principal_skinner"); } - - #[test] - fn test_signed_int_to_string() { - let pos_int = ast::LitInt(42, ast::SignedIntLit(ast::TyI32, ast::Plus)); - let neg_int = ast::LitInt((!42 + 1) as u64, ast::SignedIntLit(ast::TyI32, ast::Minus)); - assert_eq!(format!("-{}", lit_to_string(&codemap::dummy_spanned(pos_int))), - lit_to_string(&codemap::dummy_spanned(neg_int))); - } } diff --git a/src/libsyntax/ptr.rs b/src/libsyntax/ptr.rs index 0504c313c91..6190cf73464 100644 --- a/src/libsyntax/ptr.rs +++ b/src/libsyntax/ptr.rs @@ -17,7 +17,7 @@ //! //! * **Identity**: sharing AST nodes is problematic for the various analysis //! passes (e.g. one may be able to bypass the borrow checker with a shared -//! `ExprAddrOf` node taking a mutable borrow). The only reason `@T` in the +//! `ExprKind::AddrOf` node taking a mutable borrow). The only reason `@T` in the //! AST hasn't caused issues is because of inefficient folding passes which //! would always deduplicate any such shared nodes. Even if the AST were to //! switch to an arena, this would still hold, i.e. it couldn't use `&'a T`, diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index 345adff2344..9049b21d8b4 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -89,8 +89,8 @@ impl fold::Folder for CrateInjector { attrs: vec!( attr::mk_attr_outer(attr::mk_attr_id(), attr::mk_word_item( InternedString::new("macro_use")))), - node: ast::ItemExternCrate(Some(self.crate_name)), - vis: ast::Inherited, + node: ast::ItemKind::ExternCrate(Some(self.crate_name)), + vis: ast::Visibility::Inherited, span: DUMMY_SP })); @@ -149,7 +149,7 @@ impl fold::Folder for PreludeInjector { mod_.items.insert(0, P(ast::Item { id: ast::DUMMY_NODE_ID, ident: special_idents::invalid, - node: ast::ItemUse(vp), + node: ast::ItemKind::Use(vp), attrs: vec![ast::Attribute { span: self.span, node: ast::Attribute_ { @@ -157,12 +157,12 @@ impl fold::Folder for PreludeInjector { style: ast::AttrStyle::Outer, value: P(ast::MetaItem { span: self.span, - node: ast::MetaWord(special_idents::prelude_import.name.as_str()), + node: ast::MetaItemKind::Word(special_idents::prelude_import.name.as_str()), }), is_sugared_doc: false, }, }], - vis: ast::Inherited, + vis: ast::Visibility::Inherited, span: self.span, })); diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 9a6d1f8fdab..6b4f9464190 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -125,7 +125,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> { let i = if is_test_fn(&self.cx, &*i) || is_bench_fn(&self.cx, &*i) { match i.node { - ast::ItemFn(_, ast::Unsafety::Unsafe, _, _, _, _) => { + ast::ItemKind::Fn(_, ast::Unsafety::Unsafe, _, _, _, _) => { let diag = self.cx.span_diagnostic; panic!(diag.span_fatal(i.span, "unsafe functions cannot be used for tests")); } @@ -147,7 +147,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> { // the module (note that the tests are re-exported and must // be made public themselves to avoid privacy errors). i.map(|mut i| { - i.vis = ast::Public; + i.vis = ast::Visibility::Public; i }) } @@ -159,7 +159,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> { // We don't want to recurse into anything other than mods, since // mods or tests inside of functions will break things let res = match i.node { - ast::ItemMod(..) => fold::noop_fold_item(i, self), + ast::ItemKind::Mod(..) => fold::noop_fold_item(i, self), _ => SmallVector::one(i), }; if ident.name != token::special_idents::invalid.name { @@ -245,11 +245,11 @@ fn mk_reexport_mod(cx: &mut TestCtxt, tests: Vec<ast::Ident>, let super_ = token::str_to_ident("super"); let items = tests.into_iter().map(|r| { - cx.ext_cx.item_use_simple(DUMMY_SP, ast::Public, + cx.ext_cx.item_use_simple(DUMMY_SP, ast::Visibility::Public, cx.ext_cx.path(DUMMY_SP, vec![super_, r])) }).chain(tested_submods.into_iter().map(|(r, sym)| { let path = cx.ext_cx.path(DUMMY_SP, vec![super_, r, sym]); - cx.ext_cx.item_use_simple_(DUMMY_SP, ast::Public, r, path) + cx.ext_cx.item_use_simple_(DUMMY_SP, ast::Visibility::Public, r, path) })); let reexport_mod = ast::Mod { @@ -262,8 +262,8 @@ fn mk_reexport_mod(cx: &mut TestCtxt, tests: Vec<ast::Ident>, ident: sym.clone(), attrs: Vec::new(), id: ast::DUMMY_NODE_ID, - node: ast::ItemMod(reexport_mod), - vis: ast::Public, + node: ast::ItemKind::Mod(reexport_mod), + vis: ast::Visibility::Public, span: DUMMY_SP, }); @@ -355,10 +355,10 @@ fn is_test_fn(cx: &TestCtxt, i: &ast::Item) -> bool { fn has_test_signature(i: &ast::Item) -> HasTestSignature { match i.node { - ast::ItemFn(ref decl, _, _, _, ref generics, _) => { + ast::ItemKind::Fn(ref decl, _, _, _, ref generics, _) => { let no_output = match decl.output { - ast::DefaultReturn(..) => true, - ast::Return(ref t) if t.node == ast::TyTup(vec![]) => true, + ast::FunctionRetTy::Default(..) => true, + ast::FunctionRetTy::Ty(ref t) if t.node == ast::TyKind::Tup(vec![]) => true, _ => false }; if decl.inputs.is_empty() @@ -391,11 +391,11 @@ fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool { fn has_test_signature(i: &ast::Item) -> bool { match i.node { - ast::ItemFn(ref decl, _, _, _, ref generics, _) => { + ast::ItemKind::Fn(ref decl, _, _, _, ref generics, _) => { let input_cnt = decl.inputs.len(); let no_output = match decl.output { - ast::DefaultReturn(..) => true, - ast::Return(ref t) if t.node == ast::TyTup(vec![]) => true, + ast::FunctionRetTy::Default(..) => true, + ast::FunctionRetTy::Ty(ref t) if t.node == ast::TyKind::Tup(vec![]) => true, _ => false }; let tparm_cnt = generics.ty_params.len(); @@ -453,12 +453,12 @@ mod __test { fn mk_std(cx: &TestCtxt) -> P<ast::Item> { let id_test = token::str_to_ident("test"); let (vi, vis, ident) = if cx.is_test_crate { - (ast::ItemUse( + (ast::ItemKind::Use( P(nospan(ast::ViewPathSimple(id_test, path_node(vec!(id_test)))))), - ast::Public, token::special_idents::invalid) + ast::Visibility::Public, token::special_idents::invalid) } else { - (ast::ItemExternCrate(None), ast::Inherited, id_test) + (ast::ItemKind::ExternCrate(None), ast::Visibility::Inherited, id_test) }; P(ast::Item { id: ast::DUMMY_NODE_ID, @@ -494,18 +494,18 @@ fn mk_main(cx: &mut TestCtxt) -> P<ast::Item> { let main_meta = ecx.meta_word(sp, token::intern_and_get_ident("main")); let main_attr = ecx.attribute(sp, main_meta); // pub fn main() { ... } - let main_ret_ty = ecx.ty(sp, ast::TyTup(vec![])); + let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(vec![])); let main_body = ecx.block_all(sp, vec![call_test_main], None); - let main = ast::ItemFn(ecx.fn_decl(vec![], main_ret_ty), + let main = ast::ItemKind::Fn(ecx.fn_decl(vec![], main_ret_ty), ast::Unsafety::Normal, ast::Constness::NotConst, - ::abi::Rust, ast::Generics::default(), main_body); + ::abi::Abi::Rust, ast::Generics::default(), main_body); let main = P(ast::Item { ident: token::str_to_ident("main"), attrs: vec![main_attr], id: ast::DUMMY_NODE_ID, node: main, - vis: ast::Public, + vis: ast::Visibility::Public, span: sp }); @@ -527,7 +527,7 @@ fn mk_test_module(cx: &mut TestCtxt) -> (P<ast::Item>, Option<P<ast::Item>>) { inner: DUMMY_SP, items: vec![import, mainfn, tests], }; - let item_ = ast::ItemMod(testmod); + let item_ = ast::ItemKind::Mod(testmod); let mod_ident = token::gensym_ident("__test"); let item = P(ast::Item { @@ -535,7 +535,7 @@ fn mk_test_module(cx: &mut TestCtxt) -> (P<ast::Item>, Option<P<ast::Item>>) { ident: mod_ident, attrs: vec![], node: item_, - vis: ast::Public, + vis: ast::Visibility::Public, span: DUMMY_SP, }); let reexport = cx.reexport_test_harness_main.as_ref().map(|s| { @@ -550,8 +550,8 @@ fn mk_test_module(cx: &mut TestCtxt) -> (P<ast::Item>, Option<P<ast::Item>>) { id: ast::DUMMY_NODE_ID, ident: token::special_idents::invalid, attrs: vec![], - node: ast::ItemUse(P(use_path)), - vis: ast::Inherited, + node: ast::ItemKind::Use(P(use_path)), + vis: ast::Visibility::Inherited, span: DUMMY_SP }) }); @@ -591,9 +591,9 @@ fn mk_tests(cx: &TestCtxt) -> P<ast::Item> { let static_lt = ecx.lifetime(sp, token::special_idents::static_lifetime.name); // &'static [self::test::TestDescAndFn] let static_type = ecx.ty_rptr(sp, - ecx.ty(sp, ast::TyVec(struct_type)), + ecx.ty(sp, ast::TyKind::Vec(struct_type)), Some(static_lt), - ast::MutImmutable); + ast::Mutability::Immutable); // static TESTS: $static_type = &[...]; ecx.item_const(sp, ecx.ident_of("TESTS"), @@ -613,10 +613,10 @@ fn mk_test_descs(cx: &TestCtxt) -> P<ast::Expr> { P(ast::Expr { id: ast::DUMMY_NODE_ID, - node: ast::ExprAddrOf(ast::MutImmutable, + node: ast::ExprKind::AddrOf(ast::Mutability::Immutable, P(ast::Expr { id: ast::DUMMY_NODE_ID, - node: ast::ExprVec(cx.testfns.iter().map(|test| { + node: ast::ExprKind::Vec(cx.testfns.iter().map(|test| { mk_test_desc_and_fn_rec(cx, test) }).collect()), span: DUMMY_SP, diff --git a/src/libsyntax/util/parser.rs b/src/libsyntax/util/parser.rs index 87ef96d87ff..6fb81bb6a76 100644 --- a/src/libsyntax/util/parser.rs +++ b/src/libsyntax/util/parser.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. use parse::token::{Token, BinOpToken, keywords}; -use ast; +use ast::BinOpKind; /// Associative operator with precedence. /// @@ -108,28 +108,28 @@ impl AssocOp { } } - /// Create a new AssocOp from ast::BinOp_. - pub fn from_ast_binop(op: ast::BinOp_) -> Self { + /// Create a new AssocOp from ast::BinOpKind. + pub fn from_ast_binop(op: BinOpKind) -> Self { use self::AssocOp::*; match op { - ast::BiLt => Less, - ast::BiGt => Greater, - ast::BiLe => LessEqual, - ast::BiGe => GreaterEqual, - ast::BiEq => Equal, - ast::BiNe => NotEqual, - ast::BiMul => Multiply, - ast::BiDiv => Divide, - ast::BiRem => Modulus, - ast::BiAdd => Add, - ast::BiSub => Subtract, - ast::BiShl => ShiftLeft, - ast::BiShr => ShiftRight, - ast::BiBitAnd => BitAnd, - ast::BiBitXor => BitXor, - ast::BiBitOr => BitOr, - ast::BiAnd => LAnd, - ast::BiOr => LOr + BinOpKind::Lt => Less, + BinOpKind::Gt => Greater, + BinOpKind::Le => LessEqual, + BinOpKind::Ge => GreaterEqual, + BinOpKind::Eq => Equal, + BinOpKind::Ne => NotEqual, + BinOpKind::Mul => Multiply, + BinOpKind::Div => Divide, + BinOpKind::Rem => Modulus, + BinOpKind::Add => Add, + BinOpKind::Sub => Subtract, + BinOpKind::Shl => ShiftLeft, + BinOpKind::Shr => ShiftRight, + BinOpKind::BitAnd => BitAnd, + BinOpKind::BitXor => BitXor, + BinOpKind::BitOr => BitOr, + BinOpKind::And => LAnd, + BinOpKind::Or => LOr } } @@ -185,27 +185,27 @@ impl AssocOp { } } - pub fn to_ast_binop(&self) -> Option<ast::BinOp_> { + pub fn to_ast_binop(&self) -> Option<BinOpKind> { use self::AssocOp::*; match *self { - Less => Some(ast::BiLt), - Greater => Some(ast::BiGt), - LessEqual => Some(ast::BiLe), - GreaterEqual => Some(ast::BiGe), - Equal => Some(ast::BiEq), - NotEqual => Some(ast::BiNe), - Multiply => Some(ast::BiMul), - Divide => Some(ast::BiDiv), - Modulus => Some(ast::BiRem), - Add => Some(ast::BiAdd), - Subtract => Some(ast::BiSub), - ShiftLeft => Some(ast::BiShl), - ShiftRight => Some(ast::BiShr), - BitAnd => Some(ast::BiBitAnd), - BitXor => Some(ast::BiBitXor), - BitOr => Some(ast::BiBitOr), - LAnd => Some(ast::BiAnd), - LOr => Some(ast::BiOr), + Less => Some(BinOpKind::Lt), + Greater => Some(BinOpKind::Gt), + LessEqual => Some(BinOpKind::Le), + GreaterEqual => Some(BinOpKind::Ge), + Equal => Some(BinOpKind::Eq), + NotEqual => Some(BinOpKind::Ne), + Multiply => Some(BinOpKind::Mul), + Divide => Some(BinOpKind::Div), + Modulus => Some(BinOpKind::Rem), + Add => Some(BinOpKind::Add), + Subtract => Some(BinOpKind::Sub), + ShiftLeft => Some(BinOpKind::Shl), + ShiftRight => Some(BinOpKind::Shr), + BitAnd => Some(BinOpKind::BitAnd), + BitXor => Some(BinOpKind::BitXor), + BitOr => Some(BinOpKind::BitOr), + LAnd => Some(BinOpKind::And), + LOr => Some(BinOpKind::Or), Inplace | Assign | AssignOp(_) | As | DotDot | Colon => None } } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 9b102cd99f3..66ac370c149 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -196,15 +196,15 @@ pub fn walk_lifetime_def<'v, V: Visitor<'v>>(visitor: &mut V, pub fn walk_explicit_self<'v, V: Visitor<'v>>(visitor: &mut V, explicit_self: &'v ExplicitSelf) { match explicit_self.node { - SelfStatic => {}, - SelfValue(ident) => { + SelfKind::Static => {}, + SelfKind::Value(ident) => { visitor.visit_ident(explicit_self.span, ident) } - SelfRegion(ref opt_lifetime, _, ident) => { + SelfKind::Region(ref opt_lifetime, _, ident) => { visitor.visit_ident(explicit_self.span, ident); walk_list!(visitor, visit_lifetime, opt_lifetime); } - SelfExplicit(ref typ, ident) => { + SelfKind::Explicit(ref typ, ident) => { visitor.visit_ident(explicit_self.span, ident); visitor.visit_ty(typ) } @@ -230,10 +230,10 @@ pub fn walk_trait_ref<'v,V>(visitor: &mut V, pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { visitor.visit_ident(item.span, item.ident); match item.node { - ItemExternCrate(opt_name) => { + ItemKind::ExternCrate(opt_name) => { walk_opt_name(visitor, item.span, opt_name) } - ItemUse(ref vp) => { + ItemKind::Use(ref vp) => { match vp.node { ViewPathSimple(ident, ref path) => { visitor.visit_ident(vp.span, ident); @@ -253,12 +253,12 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { } } } - ItemStatic(ref typ, _, ref expr) | - ItemConst(ref typ, ref expr) => { + ItemKind::Static(ref typ, _, ref expr) | + ItemKind::Const(ref typ, ref expr) => { visitor.visit_ty(typ); visitor.visit_expr(expr); } - ItemFn(ref declaration, unsafety, constness, abi, ref generics, ref body) => { + ItemKind::Fn(ref declaration, unsafety, constness, abi, ref generics, ref body) => { visitor.visit_fn(FnKind::ItemFn(item.ident, generics, unsafety, constness, abi, item.vis), declaration, @@ -266,24 +266,24 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { item.span, item.id) } - ItemMod(ref module) => { + ItemKind::Mod(ref module) => { visitor.visit_mod(module, item.span, item.id) } - ItemForeignMod(ref foreign_module) => { + ItemKind::ForeignMod(ref foreign_module) => { walk_list!(visitor, visit_foreign_item, &foreign_module.items); } - ItemTy(ref typ, ref type_parameters) => { + ItemKind::Ty(ref typ, ref type_parameters) => { visitor.visit_ty(typ); visitor.visit_generics(type_parameters) } - ItemEnum(ref enum_definition, ref type_parameters) => { + ItemKind::Enum(ref enum_definition, ref type_parameters) => { visitor.visit_generics(type_parameters); visitor.visit_enum_def(enum_definition, type_parameters, item.id, item.span) } - ItemDefaultImpl(_, ref trait_ref) => { + ItemKind::DefaultImpl(_, ref trait_ref) => { visitor.visit_trait_ref(trait_ref) } - ItemImpl(_, _, + ItemKind::Impl(_, _, ref type_parameters, ref opt_trait_reference, ref typ, @@ -293,17 +293,17 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { visitor.visit_ty(typ); walk_list!(visitor, visit_impl_item, impl_items); } - ItemStruct(ref struct_definition, ref generics) => { + ItemKind::Struct(ref struct_definition, ref generics) => { visitor.visit_generics(generics); visitor.visit_variant_data(struct_definition, item.ident, generics, item.id, item.span); } - ItemTrait(_, ref generics, ref bounds, ref methods) => { + ItemKind::Trait(_, ref generics, ref bounds, ref methods) => { visitor.visit_generics(generics); walk_list!(visitor, visit_ty_param_bound, bounds); walk_list!(visitor, visit_trait_item, methods); } - ItemMac(ref mac) => visitor.visit_mac(mac), + ItemKind::Mac(ref mac) => visitor.visit_mac(mac), } walk_list!(visitor, visit_attribute, &item.attrs); } @@ -328,45 +328,45 @@ pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { match typ.node { - TyVec(ref ty) | TyParen(ref ty) => { + TyKind::Vec(ref ty) | TyKind::Paren(ref ty) => { visitor.visit_ty(ty) } - TyPtr(ref mutable_type) => { + TyKind::Ptr(ref mutable_type) => { visitor.visit_ty(&mutable_type.ty) } - TyRptr(ref opt_lifetime, ref mutable_type) => { + TyKind::Rptr(ref opt_lifetime, ref mutable_type) => { walk_list!(visitor, visit_lifetime, opt_lifetime); visitor.visit_ty(&mutable_type.ty) } - TyTup(ref tuple_element_types) => { + TyKind::Tup(ref tuple_element_types) => { walk_list!(visitor, visit_ty, tuple_element_types); } - TyBareFn(ref function_declaration) => { + TyKind::BareFn(ref function_declaration) => { walk_fn_decl(visitor, &function_declaration.decl); walk_list!(visitor, visit_lifetime_def, &function_declaration.lifetimes); } - TyPath(ref maybe_qself, ref path) => { + TyKind::Path(ref maybe_qself, ref path) => { if let Some(ref qself) = *maybe_qself { visitor.visit_ty(&qself.ty); } visitor.visit_path(path, typ.id); } - TyObjectSum(ref ty, ref bounds) => { + TyKind::ObjectSum(ref ty, ref bounds) => { visitor.visit_ty(ty); walk_list!(visitor, visit_ty_param_bound, bounds); } - TyFixedLengthVec(ref ty, ref expression) => { + TyKind::FixedLengthVec(ref ty, ref expression) => { visitor.visit_ty(ty); visitor.visit_expr(expression) } - TyPolyTraitRef(ref bounds) => { + TyKind::PolyTraitRef(ref bounds) => { walk_list!(visitor, visit_ty_param_bound, bounds); } - TyTypeof(ref expression) => { + TyKind::Typeof(ref expression) => { visitor.visit_expr(expression) } - TyInfer => {} - TyMac(ref mac) => { + TyKind::Infer => {} + TyKind::Mac(ref mac) => { visitor.visit_mac(mac) } } @@ -467,11 +467,11 @@ pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, visitor.visit_ident(foreign_item.span, foreign_item.ident); match foreign_item.node { - ForeignItemFn(ref function_declaration, ref generics) => { + ForeignItemKind::Fn(ref function_declaration, ref generics) => { walk_fn_decl(visitor, function_declaration); visitor.visit_generics(generics) } - ForeignItemStatic(ref typ, _) => visitor.visit_ty(typ), + ForeignItemKind::Static(ref typ, _) => visitor.visit_ty(typ), } walk_list!(visitor, visit_attribute, &foreign_item.attrs); @@ -524,7 +524,7 @@ pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics } pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FunctionRetTy) { - if let Return(ref output_ty) = *ret_ty { + if let FunctionRetTy::Ty(ref output_ty) = *ret_ty { visitor.visit_ty(output_ty) } } @@ -565,20 +565,20 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai visitor.visit_ident(trait_item.span, trait_item.ident); walk_list!(visitor, visit_attribute, &trait_item.attrs); match trait_item.node { - ConstTraitItem(ref ty, ref default) => { + TraitItemKind::Const(ref ty, ref default) => { visitor.visit_ty(ty); walk_list!(visitor, visit_expr, default); } - MethodTraitItem(ref sig, None) => { + TraitItemKind::Method(ref sig, None) => { visitor.visit_explicit_self(&sig.explicit_self); visitor.visit_generics(&sig.generics); walk_fn_decl(visitor, &sig.decl); } - MethodTraitItem(ref sig, Some(ref body)) => { + TraitItemKind::Method(ref sig, Some(ref body)) => { visitor.visit_fn(FnKind::Method(trait_item.ident, sig, None), &sig.decl, body, trait_item.span, trait_item.id); } - TypeTraitItem(ref bounds, ref default) => { + TraitItemKind::Type(ref bounds, ref default) => { walk_list!(visitor, visit_ty_param_bound, bounds); walk_list!(visitor, visit_ty, default); } @@ -625,11 +625,11 @@ pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block) { pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) { match statement.node { - StmtDecl(ref declaration, _) => visitor.visit_decl(declaration), - StmtExpr(ref expression, _) | StmtSemi(ref expression, _) => { + StmtKind::Decl(ref declaration, _) => visitor.visit_decl(declaration), + StmtKind::Expr(ref expression, _) | StmtKind::Semi(ref expression, _) => { visitor.visit_expr(expression) } - StmtMac(ref mac, _, ref attrs) => { + StmtKind::Mac(ref mac, _, ref attrs) => { visitor.visit_mac(mac); for attr in attrs.as_attr_slice() { visitor.visit_attribute(attr); @@ -640,8 +640,8 @@ pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) { pub fn walk_decl<'v, V: Visitor<'v>>(visitor: &mut V, declaration: &'v Decl) { match declaration.node { - DeclLocal(ref local) => visitor.visit_local(local), - DeclItem(ref item) => visitor.visit_item(item), + DeclKind::Local(ref local) => visitor.visit_local(local), + DeclKind::Item(ref item) => visitor.visit_item(item), } } @@ -651,21 +651,21 @@ pub fn walk_mac<'v, V: Visitor<'v>>(_: &mut V, _: &'v Mac) { pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { match expression.node { - ExprBox(ref subexpression) => { + ExprKind::Box(ref subexpression) => { visitor.visit_expr(subexpression) } - ExprInPlace(ref place, ref subexpression) => { + ExprKind::InPlace(ref place, ref subexpression) => { visitor.visit_expr(place); visitor.visit_expr(subexpression) } - ExprVec(ref subexpressions) => { + ExprKind::Vec(ref subexpressions) => { walk_list!(visitor, visit_expr, subexpressions); } - ExprRepeat(ref element, ref count) => { + ExprKind::Repeat(ref element, ref count) => { visitor.visit_expr(element); visitor.visit_expr(count) } - ExprStruct(ref path, ref fields, ref optional_base) => { + ExprKind::Struct(ref path, ref fields, ref optional_base) => { visitor.visit_path(path, expression.id); for field in fields { visitor.visit_ident(field.ident.span, field.ident.node); @@ -673,116 +673,116 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { } walk_list!(visitor, visit_expr, optional_base); } - ExprTup(ref subexpressions) => { + ExprKind::Tup(ref subexpressions) => { walk_list!(visitor, visit_expr, subexpressions); } - ExprCall(ref callee_expression, ref arguments) => { + ExprKind::Call(ref callee_expression, ref arguments) => { walk_list!(visitor, visit_expr, arguments); visitor.visit_expr(callee_expression) } - ExprMethodCall(ref ident, ref types, ref arguments) => { + ExprKind::MethodCall(ref ident, ref types, ref arguments) => { visitor.visit_ident(ident.span, ident.node); walk_list!(visitor, visit_expr, arguments); walk_list!(visitor, visit_ty, types); } - ExprBinary(_, ref left_expression, ref right_expression) => { + ExprKind::Binary(_, ref left_expression, ref right_expression) => { visitor.visit_expr(left_expression); visitor.visit_expr(right_expression) } - ExprAddrOf(_, ref subexpression) | ExprUnary(_, ref subexpression) => { + ExprKind::AddrOf(_, ref subexpression) | ExprKind::Unary(_, ref subexpression) => { visitor.visit_expr(subexpression) } - ExprLit(_) => {} - ExprCast(ref subexpression, ref typ) | ExprType(ref subexpression, ref typ) => { + ExprKind::Lit(_) => {} + ExprKind::Cast(ref subexpression, ref typ) | ExprKind::Type(ref subexpression, ref typ) => { visitor.visit_expr(subexpression); visitor.visit_ty(typ) } - ExprIf(ref head_expression, ref if_block, ref optional_else) => { + ExprKind::If(ref head_expression, ref if_block, ref optional_else) => { visitor.visit_expr(head_expression); visitor.visit_block(if_block); walk_list!(visitor, visit_expr, optional_else); } - ExprWhile(ref subexpression, ref block, opt_ident) => { + ExprKind::While(ref subexpression, ref block, opt_ident) => { visitor.visit_expr(subexpression); visitor.visit_block(block); walk_opt_ident(visitor, expression.span, opt_ident) } - ExprIfLet(ref pattern, ref subexpression, ref if_block, ref optional_else) => { + ExprKind::IfLet(ref pattern, ref subexpression, ref if_block, ref optional_else) => { visitor.visit_pat(pattern); visitor.visit_expr(subexpression); visitor.visit_block(if_block); walk_list!(visitor, visit_expr, optional_else); } - ExprWhileLet(ref pattern, ref subexpression, ref block, opt_ident) => { + ExprKind::WhileLet(ref pattern, ref subexpression, ref block, opt_ident) => { visitor.visit_pat(pattern); visitor.visit_expr(subexpression); visitor.visit_block(block); walk_opt_ident(visitor, expression.span, opt_ident) } - ExprForLoop(ref pattern, ref subexpression, ref block, opt_ident) => { + ExprKind::ForLoop(ref pattern, ref subexpression, ref block, opt_ident) => { visitor.visit_pat(pattern); visitor.visit_expr(subexpression); visitor.visit_block(block); walk_opt_ident(visitor, expression.span, opt_ident) } - ExprLoop(ref block, opt_ident) => { + ExprKind::Loop(ref block, opt_ident) => { visitor.visit_block(block); walk_opt_ident(visitor, expression.span, opt_ident) } - ExprMatch(ref subexpression, ref arms) => { + ExprKind::Match(ref subexpression, ref arms) => { visitor.visit_expr(subexpression); walk_list!(visitor, visit_arm, arms); } - ExprClosure(_, ref function_declaration, ref body) => { + ExprKind::Closure(_, ref function_declaration, ref body) => { visitor.visit_fn(FnKind::Closure, function_declaration, body, expression.span, expression.id) } - ExprBlock(ref block) => visitor.visit_block(block), - ExprAssign(ref left_hand_expression, ref right_hand_expression) => { + ExprKind::Block(ref block) => visitor.visit_block(block), + ExprKind::Assign(ref left_hand_expression, ref right_hand_expression) => { visitor.visit_expr(right_hand_expression); visitor.visit_expr(left_hand_expression) } - ExprAssignOp(_, ref left_expression, ref right_expression) => { + ExprKind::AssignOp(_, ref left_expression, ref right_expression) => { visitor.visit_expr(right_expression); visitor.visit_expr(left_expression) } - ExprField(ref subexpression, ref ident) => { + ExprKind::Field(ref subexpression, ref ident) => { visitor.visit_expr(subexpression); visitor.visit_ident(ident.span, ident.node); } - ExprTupField(ref subexpression, _) => { + ExprKind::TupField(ref subexpression, _) => { visitor.visit_expr(subexpression); } - ExprIndex(ref main_expression, ref index_expression) => { + ExprKind::Index(ref main_expression, ref index_expression) => { visitor.visit_expr(main_expression); visitor.visit_expr(index_expression) } - ExprRange(ref start, ref end) => { + ExprKind::Range(ref start, ref end) => { walk_list!(visitor, visit_expr, start); walk_list!(visitor, visit_expr, end); } - ExprPath(ref maybe_qself, ref path) => { + ExprKind::Path(ref maybe_qself, ref path) => { if let Some(ref qself) = *maybe_qself { visitor.visit_ty(&qself.ty); } visitor.visit_path(path, expression.id) } - ExprBreak(ref opt_sp_ident) | ExprAgain(ref opt_sp_ident) => { + ExprKind::Break(ref opt_sp_ident) | ExprKind::Again(ref opt_sp_ident) => { for sp_ident in opt_sp_ident { visitor.visit_ident(sp_ident.span, sp_ident.node); } } - ExprRet(ref optional_expression) => { + ExprKind::Ret(ref optional_expression) => { walk_list!(visitor, visit_expr, optional_expression); } - ExprMac(ref mac) => visitor.visit_mac(mac), - ExprParen(ref subexpression) => { + ExprKind::Mac(ref mac) => visitor.visit_mac(mac), + ExprKind::Paren(ref subexpression) => { visitor.visit_expr(subexpression) } - ExprInlineAsm(ref ia) => { + ExprKind::InlineAsm(ref ia) => { for &(_, ref input) in &ia.inputs { visitor.visit_expr(&input) } |
