From f875f4c4c24e8a14c04bbe4eedd230c4aa3c1431 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 8 Feb 2016 13:21:29 +0100 Subject: [PATCH 01/29] [breaking-change] don't glob export ast::UnOp variants --- src/librustc_front/lowering.rs | 6 +++--- src/libsyntax/ast.rs | 15 +++++++-------- src/libsyntax/ext/build.rs | 3 ++- src/libsyntax/parse/parser.rs | 14 +++++++------- src/libsyntax_ext/deriving/cmp/partial_ord.rs | 2 +- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index f6342831143..698d82adff4 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -876,9 +876,9 @@ pub fn lower_constness(_lctx: &LoweringContext, c: Constness) -> hir::Constness pub fn lower_unop(_lctx: &LoweringContext, u: UnOp) -> hir::UnOp { match u { - UnDeref => hir::UnDeref, - UnNot => hir::UnNot, - UnNeg => hir::UnNeg, + UnOp::Deref => hir::UnDeref, + UnOp::Not => hir::UnNot, + UnOp::Neg => hir::UnNeg, } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 088f911ed8c..2b3ca63c26f 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -38,7 +38,6 @@ 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::*; @@ -723,27 +722,27 @@ pub type BinOp = Spanned; #[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 => "-", } } } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index a74c2340cec..2ce2e7f71f3 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -10,6 +10,7 @@ use abi; use ast::{Ident, Generics, Expr}; +use ast::UnOp; use ast; use attr; use codemap::{Span, respan, Spanned, DUMMY_SP, Pos}; @@ -610,7 +611,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn expr_deref(&self, sp: Span, e: P) -> P { - 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) -> P { self.expr(sp, ast::ExprUnary(op, e)) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 82bfc26ee34..c174e35d93b 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -13,13 +13,13 @@ pub use self::PathParsingMode::*; use abi; use ast::BareFnTy; use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; -use ast::{Public, Unsafety}; +use ast::{Public, Unsafety, UnOp}; 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::{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}; @@ -39,7 +39,7 @@ 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::{NamedField, NoReturn}; use ast::{Pat, PatBox, PatEnum, PatIdent, PatLit, PatQPath, PatMac, PatRange}; use ast::{PatRegion, PatStruct, PatTup, PatVec, PatWild}; use ast::{PolyTraitRef, QSelf}; @@ -1608,7 +1608,7 @@ impl<'a> Parser<'a> { 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) @@ -2740,21 +2740,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()); diff --git a/src/libsyntax_ext/deriving/cmp/partial_ord.rs b/src/libsyntax_ext/deriving/cmp/partial_ord.rs index bd825e5c8df..4c10a3a31d0 100644 --- a/src/libsyntax_ext/deriving/cmp/partial_ord.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_ord.rs @@ -211,7 +211,7 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt, let cmp = cx.expr_binary(span, op, self_f.clone(), other_f.clone()); - let not_cmp = cx.expr_unary(span, ast::UnNot, + let not_cmp = cx.expr_unary(span, ast::UnOp::Not, cx.expr_binary(span, op, other_f.clone(), self_f)); let and = cx.expr_binary(span, ast::BiAnd, not_cmp, subexpr); From 05e25de4f0add7ae3cd0e8f66cd4558c5bfa42aa Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 8 Feb 2016 13:16:12 +0100 Subject: [PATCH 02/29] [breaking-change] don't glob export ast::BinOp_ --- src/librustc_front/lowering.rs | 36 +++---- src/libsyntax/ast.rs | 93 ++++++++++--------- src/libsyntax/ext/build.rs | 4 +- src/libsyntax/parse/parser.rs | 37 ++++---- src/libsyntax/parse/token.rs | 40 ++++---- src/libsyntax/util/parser.rs | 80 ++++++++-------- src/libsyntax_ext/deriving/cmp/ord.rs | 5 +- src/libsyntax_ext/deriving/cmp/partial_eq.rs | 10 +- src/libsyntax_ext/deriving/cmp/partial_ord.rs | 11 +-- src/libsyntax_ext/deriving/generic/mod.rs | 8 +- src/test/auxiliary/custom_derive_plugin.rs | 2 +- .../auxiliary/custom_derive_plugin_attr.rs | 2 +- 12 files changed, 164 insertions(+), 164 deletions(-) diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index 698d82adff4..662eaf136c2 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -885,24 +885,24 @@ pub fn lower_unop(_lctx: &LoweringContext, u: UnOp) -> hir::UnOp { pub fn lower_binop(_lctx: &LoweringContext, b: BinOp) -> hir::BinOp { Spanned { node: match b.node { - BiAdd => hir::BiAdd, - BiSub => hir::BiSub, - BiMul => hir::BiMul, - BiDiv => hir::BiDiv, - BiRem => hir::BiRem, - BiAnd => hir::BiAnd, - BiOr => hir::BiOr, - BiBitXor => hir::BiBitXor, - BiBitAnd => hir::BiBitAnd, - BiBitOr => hir::BiBitOr, - BiShl => hir::BiShl, - BiShr => hir::BiShr, - BiEq => hir::BiEq, - BiLt => hir::BiLt, - BiLe => hir::BiLe, - BiNe => hir::BiNe, - BiGe => hir::BiGe, - BiGt => hir::BiGt, + BinOpKind::Add => hir::BiAdd, + BinOpKind::Sub => hir::BiSub, + BinOpKind::Mul => hir::BiMul, + BinOpKind::Div => hir::BiDiv, + BinOpKind::Rem => hir::BiRem, + BinOpKind::And => hir::BiAnd, + BinOpKind::Or => hir::BiOr, + BinOpKind::BitXor => hir::BiBitXor, + BinOpKind::BitAnd => hir::BiBitAnd, + BinOpKind::BitOr => hir::BiBitOr, + BinOpKind::Shl => hir::BiShl, + BinOpKind::Shr => hir::BiShr, + BinOpKind::Eq => hir::BiEq, + BinOpKind::Lt => hir::BiLt, + BinOpKind::Le => hir::BiLe, + BinOpKind::Ne => hir::BiNe, + BinOpKind::Ge => hir::BiGe, + BinOpKind::Gt => hir::BiGt, }, span: b.span, } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 2b3ca63c26f..be6d65a01b5 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,7 +10,6 @@ // The Rust abstract syntax tree. -pub use self::BinOp_::*; pub use self::BlockCheckMode::*; pub use self::CaptureClause::*; pub use self::Decl_::*; @@ -627,97 +626,99 @@ pub enum Mutability { } #[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; +pub type BinOp = Spanned; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub enum UnOp { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 2ce2e7f71f3..a5f6454cb38 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -116,7 +116,7 @@ pub trait AstBuilder { fn expr_ident(&self, span: Span, id: ast::Ident) -> P; fn expr_self(&self, span: Span) -> P; - fn expr_binary(&self, sp: Span, op: ast::BinOp_, + fn expr_binary(&self, sp: Span, op: ast::BinOpKind, lhs: P, rhs: P) -> P; fn expr_deref(&self, sp: Span, e: P) -> P; fn expr_unary(&self, sp: Span, op: ast::UnOp, e: P) -> P; @@ -605,7 +605,7 @@ 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, rhs: P) -> P { self.expr(sp, ast::ExprBinary(Spanned { node: op, span: sp }, lhs, rhs)) } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c174e35d93b..d6d0a35f2ce 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -13,13 +13,13 @@ pub use self::PathParsingMode::*; use abi; use ast::BareFnTy; use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; -use ast::{Public, Unsafety, UnOp}; -use ast::{Mod, BiAdd, Arg, Arm, Attribute, BindingMode}; -use ast::{BiBitAnd, BiBitOr, BiBitXor, BiRem, BiLt, Block}; +use ast::{Public, Unsafety}; +use ast::{Mod, Arg, Arm, Attribute, BindingMode}; +use ast::Block; use ast::{BlockCheckMode, CaptureByRef, CaptureByValue, CaptureClause}; use ast::{Constness, ConstTraitItem, Crate, CrateConfig}; use ast::{Decl, DeclItem, DeclLocal, DefaultBlock, DefaultReturn}; -use ast::{BiDiv, EMPTY_CTXT, EnumDef, ExplicitSelf}; +use ast::{EMPTY_CTXT, EnumDef, ExplicitSelf}; use ast::{Expr, Expr_, ExprAddrOf, ExprMatch, ExprAgain}; use ast::{ExprAssign, ExprAssignOp, ExprBinary, ExprBlock, ExprBox}; use ast::{ExprBreak, ExprCall, ExprCast, ExprInPlace}; @@ -38,14 +38,14 @@ 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::{MutTy, Mutability}; use ast::{NamedField, NoReturn}; 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::{Return, Stmt, StmtDecl}; use ast::{StmtExpr, StmtSemi, StmtMac, VariantData, StructField}; -use ast::{BiSub, StrStyle}; +use ast::StrStyle; use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue}; use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef}; use ast::{Ty, Ty_, TypeBinding, TyMac}; @@ -57,6 +57,7 @@ use ast::{UnnamedField, UnsafeBlock}; 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}; @@ -2925,16 +2926,16 @@ impl<'a> Parser<'a> { self.mk_expr(lhs_span.lo, rhs.span.hi, ExprInPlace(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); @@ -2961,7 +2962,7 @@ impl<'a> Parser<'a> { 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"); } 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 { + pub fn to_binop(&self) -> Option { 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/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 { + pub fn to_ast_binop(&self) -> Option { 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_ext/deriving/cmp/ord.rs b/src/libsyntax_ext/deriving/cmp/ord.rs index 95a5d184d0e..2fa847ee430 100644 --- a/src/libsyntax_ext/deriving/cmp/ord.rs +++ b/src/libsyntax_ext/deriving/cmp/ord.rs @@ -11,8 +11,7 @@ use deriving::generic::*; use deriving::generic::ty::*; -use syntax::ast; -use syntax::ast::{MetaItem, Expr}; +use syntax::ast::{MetaItem, Expr, BinOpKind, self}; use syntax::codemap::Span; use syntax::ext::base::{ExtCtxt, Annotatable}; use syntax::ext::build::AstBuilder; @@ -116,7 +115,7 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span, let assign = cx.stmt_let(span, false, test_id, new); - let cond = cx.expr_binary(span, ast::BiEq, + let cond = cx.expr_binary(span, BinOpKind::Eq, cx.expr_ident(span, test_id), cx.expr_path(equals_path.clone())); let if_ = cx.expr_if(span, diff --git a/src/libsyntax_ext/deriving/cmp/partial_eq.rs b/src/libsyntax_ext/deriving/cmp/partial_eq.rs index 29be5a7ddc3..0150a073b07 100644 --- a/src/libsyntax_ext/deriving/cmp/partial_eq.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_eq.rs @@ -11,7 +11,7 @@ use deriving::generic::*; use deriving::generic::ty::*; -use syntax::ast::{MetaItem, Expr, self}; +use syntax::ast::{MetaItem, Expr, BinOpKind}; use syntax::codemap::Span; use syntax::ext::base::{ExtCtxt, Annotatable}; use syntax::ext::build::AstBuilder; @@ -35,9 +35,9 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt, _ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`") }; - let eq = cx.expr_binary(span, ast::BiEq, self_f, other_f.clone()); + let eq = cx.expr_binary(span, BinOpKind::Eq, self_f, other_f.clone()); - cx.expr_binary(span, ast::BiAnd, subexpr, eq) + cx.expr_binary(span, BinOpKind::And, subexpr, eq) }, cx.expr_bool(span, true), Box::new(|cx, span, _, _| cx.expr_bool(span, false)), @@ -52,9 +52,9 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt, _ => cx.span_bug(span, "not exactly 2 arguments in `derive(PartialEq)`") }; - let eq = cx.expr_binary(span, ast::BiNe, self_f, other_f.clone()); + let eq = cx.expr_binary(span, BinOpKind::Ne, self_f, other_f.clone()); - cx.expr_binary(span, ast::BiOr, subexpr, eq) + cx.expr_binary(span, BinOpKind::Or, subexpr, eq) }, cx.expr_bool(span, false), Box::new(|cx, span, _, _| cx.expr_bool(span, true)), diff --git a/src/libsyntax_ext/deriving/cmp/partial_ord.rs b/src/libsyntax_ext/deriving/cmp/partial_ord.rs index 4c10a3a31d0..e857f7d52f9 100644 --- a/src/libsyntax_ext/deriving/cmp/partial_ord.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_ord.rs @@ -13,8 +13,7 @@ pub use self::OrderingOp::*; use deriving::generic::*; use deriving::generic::ty::*; -use syntax::ast; -use syntax::ast::{MetaItem, Expr}; +use syntax::ast::{MetaItem, Expr, BinOpKind, self}; use syntax::codemap::Span; use syntax::ext::base::{ExtCtxt, Annotatable}; use syntax::ext::build::AstBuilder; @@ -161,7 +160,7 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span, let assign = cx.stmt_let(span, false, test_id, new); - let cond = cx.expr_binary(span, ast::BiEq, + let cond = cx.expr_binary(span, BinOpKind::Eq, cx.expr_ident(span, test_id), equals_expr.clone()); let if_ = cx.expr_if(span, @@ -183,7 +182,7 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span, /// Strict inequality. fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P { - let op = if less {ast::BiLt} else {ast::BiGt}; + let op = if less { BinOpKind::Lt } else { BinOpKind::Gt }; cs_fold( false, // need foldr, |cx, span, subexpr, self_f, other_fs| { @@ -214,8 +213,8 @@ fn cs_op(less: bool, equal: bool, cx: &mut ExtCtxt, let not_cmp = cx.expr_unary(span, ast::UnOp::Not, cx.expr_binary(span, op, other_f.clone(), self_f)); - let and = cx.expr_binary(span, ast::BiAnd, not_cmp, subexpr); - cx.expr_binary(span, ast::BiOr, cmp, and) + let and = cx.expr_binary(span, BinOpKind::And, not_cmp, subexpr); + cx.expr_binary(span, BinOpKind::Or, cmp, and) }, cx.expr_bool(span, equal), Box::new(|cx, span, (self_args, tag_tuple), _non_self_args| { diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 3af701739b4..9eb516cd07a 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -194,8 +194,7 @@ use std::vec; use syntax::abi::Abi; use syntax::abi; -use syntax::ast; -use syntax::ast::{EnumDef, Expr, Ident, Generics, VariantData}; +use syntax::ast::{EnumDef, Expr, Ident, Generics, VariantData, BinOpKind, self}; use syntax::ast_util; use syntax::attr; use syntax::attr::AttrMetaMethods; @@ -1279,8 +1278,9 @@ impl<'a> MethodDef<'a> { Some(first) => { let first_expr = cx.expr_ident(sp, first); let id = cx.expr_ident(sp, ident); - let test = cx.expr_binary(sp, ast::BiEq, first_expr, id); - discriminant_test = cx.expr_binary(sp, ast::BiAnd, discriminant_test, test) + let test = cx.expr_binary(sp, BinOpKind::Eq, first_expr, id); + discriminant_test = cx.expr_binary(sp, BinOpKind::And, + discriminant_test, test) } None => { first_ident = Some(ident); diff --git a/src/test/auxiliary/custom_derive_plugin.rs b/src/test/auxiliary/custom_derive_plugin.rs index a3f42edbed2..5f0ef4de491 100644 --- a/src/test/auxiliary/custom_derive_plugin.rs +++ b/src/test/auxiliary/custom_derive_plugin.rs @@ -62,7 +62,7 @@ fn expand(cx: &mut ExtCtxt, let zero = cx.expr_isize(span, 0); cs_fold(false, |cx, span, subexpr, field, _| { - cx.expr_binary(span, ast::BiAdd, subexpr, + cx.expr_binary(span, ast::BinOpKind::Add, subexpr, cx.expr_method_call(span, field, token::str_to_ident("total_sum"), vec![])) }, diff --git a/src/test/auxiliary/custom_derive_plugin_attr.rs b/src/test/auxiliary/custom_derive_plugin_attr.rs index fe12d3b1f08..ba216289fd4 100644 --- a/src/test/auxiliary/custom_derive_plugin_attr.rs +++ b/src/test/auxiliary/custom_derive_plugin_attr.rs @@ -81,7 +81,7 @@ fn totalsum_substructure(cx: &mut ExtCtxt, trait_span: Span, if item.attrs.iter().find(|a| a.check_name("ignore")).is_some() { acc } else { - cx.expr_binary(item.span, ast::BiAdd, acc, + cx.expr_binary(item.span, ast::BinOpKind::Add, acc, cx.expr_method_call(item.span, item.self_.clone(), substr.method_ident, From 3b57d40fe5a813ac957667ac04938753e3100f55 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 8 Feb 2016 15:04:11 +0100 Subject: [PATCH 03/29] [breaking-change] don't glob import ast::FunctionRetTy variants --- src/librustc_front/lowering.rs | 6 +++--- src/librustc_trans/save/dump_csv.rs | 6 +++--- src/libsyntax/ast.rs | 13 ++++++------- src/libsyntax/ext/build.rs | 2 +- src/libsyntax/fold.rs | 6 +++--- src/libsyntax/parse/mod.rs | 2 +- src/libsyntax/parse/parser.rs | 14 +++++++------- src/libsyntax/print/pprust.rs | 22 +++++++++++----------- src/libsyntax/test.rs | 8 ++++---- src/libsyntax/visit.rs | 2 +- 10 files changed, 40 insertions(+), 41 deletions(-) diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index 662eaf136c2..2862a1811fb 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -450,9 +450,9 @@ pub fn lower_fn_decl(lctx: &LoweringContext, decl: &FnDecl) -> P { P(hir::FnDecl { inputs: decl.inputs.iter().map(|x| lower_arg(lctx, x)).collect(), output: match decl.output { - Return(ref ty) => hir::Return(lower_ty(lctx, ty)), - DefaultReturn(span) => hir::DefaultReturn(span), - NoReturn(span) => hir::NoReturn(span), + FunctionRetTy::Ty(ref ty) => hir::Return(lower_ty(lctx, ty)), + FunctionRetTy::Default(span) => hir::DefaultReturn(span), + FunctionRetTy::None(span) => hir::NoReturn(span), }, variadic: decl.variadic, }) diff --git a/src/librustc_trans/save/dump_csv.rs b/src/librustc_trans/save/dump_csv.rs index 25c30f2476d..9714e4f02b1 100644 --- a/src/librustc_trans/save/dump_csv.rs +++ b/src/librustc_trans/save/dump_csv.rs @@ -350,7 +350,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> { self.visit_ty(&arg.ty); } - if let ast::Return(ref ret_ty) = sig.decl.output { + if let ast::FunctionRetTy::Ty(ref ret_ty) = sig.decl.output { self.visit_ty(ret_ty); } @@ -429,7 +429,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> { self.visit_ty(&arg.ty); } - if let ast::Return(ref ret_ty) = decl.output { + if let ast::FunctionRetTy::Ty(ref ret_ty) = decl.output { self.visit_ty(&ret_ty); } @@ -1141,7 +1141,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> { self.visit_ty(&*arg.ty); } - if let ast::Return(ref ret_ty) = decl.output { + if let ast::FunctionRetTy::Ty(ref ret_ty) = decl.output { self.visit_ty(&**ret_ty); } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index be6d65a01b5..9d49fb3be4f 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -16,7 +16,6 @@ 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_::*; @@ -1727,23 +1726,23 @@ 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(P), } 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, } } } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index a5f6454cb38..91ced6eb076 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -941,7 +941,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn fn_decl(&self, inputs: Vec, output: P) -> P { P(ast::FnDecl { inputs: inputs, - output: ast::Return(output), + output: ast::FunctionRetTy::Ty(output), variadic: false }) } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 1de6d6c002f..dc96e9ecc09 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -685,9 +685,9 @@ pub fn noop_fold_fn_decl(decl: P, fld: &mut T) -> P { 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 }) diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 32372ccc13b..becce9ba7d9 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -950,7 +950,7 @@ 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, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d6d0a35f2ce..3f7173b179c 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -18,7 +18,7 @@ use ast::{Mod, Arg, Arm, Attribute, BindingMode}; use ast::Block; use ast::{BlockCheckMode, CaptureByRef, CaptureByValue, CaptureClause}; use ast::{Constness, ConstTraitItem, Crate, CrateConfig}; -use ast::{Decl, DeclItem, DeclLocal, DefaultBlock, DefaultReturn}; +use ast::{Decl, DeclItem, DeclLocal, DefaultBlock}; use ast::{EMPTY_CTXT, EnumDef, ExplicitSelf}; use ast::{Expr, Expr_, ExprAddrOf, ExprMatch, ExprAgain}; use ast::{ExprAssign, ExprAssignOp, ExprBinary, ExprBlock, ExprBox}; @@ -39,11 +39,11 @@ use ast::{LitStr, LitInt, Local}; use ast::{MacStmtWithBraces, MacStmtWithSemicolon, MacStmtWithoutBraces}; use ast::{MutImmutable, MutMutable, Mac_}; use ast::{MutTy, Mutability}; -use ast::{NamedField, NoReturn}; +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, Stmt, StmtDecl}; +use ast::{Stmt, StmtDecl}; use ast::{StmtExpr, StmtSemi, StmtMac, VariantData, StructField}; use ast::StrStyle; use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue}; @@ -1283,13 +1283,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))) } } @@ -3053,7 +3053,7 @@ impl<'a> Parser<'a> { { 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()); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 759b16c5738..4e1f761c51a 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2108,7 +2108,7 @@ impl<'a> State<'a> { try!(space(&mut self.s)); let default_return = match decl.output { - ast::DefaultReturn(..) => true, + ast::FunctionRetTy::Default(..) => true, _ => false }; @@ -2722,19 +2722,19 @@ 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) } @@ -2988,7 +2988,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 +2996,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(()) } } @@ -3155,7 +3155,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(); diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 9a6d1f8fdab..054d57e90ea 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -357,8 +357,8 @@ fn is_test_fn(cx: &TestCtxt, i: &ast::Item) -> bool { match i.node { ast::ItemFn(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::TyTup(vec![]) => true, _ => false }; if decl.inputs.is_empty() @@ -394,8 +394,8 @@ fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool { ast::ItemFn(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::TyTup(vec![]) => true, _ => false }; let tparm_cnt = generics.ty_params.len(); diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 9b102cd99f3..834291dd561 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -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) } } From 47b0784ba8e62a2e1b877750baeae10d16555fff Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 8 Feb 2016 12:44:45 +0100 Subject: [PATCH 04/29] [breaking-change] don't glob export ast::BlockCheckMode variants --- src/librustc_driver/pretty.rs | 4 ++-- src/librustc_front/lowering.rs | 4 ++-- src/libsyntax/ast.rs | 5 ++--- src/libsyntax/ext/build.rs | 6 ++---- src/libsyntax/parse/classify.rs | 4 ++-- src/libsyntax/parse/mod.rs | 2 +- src/libsyntax/parse/parser.rs | 14 +++++++------- src/libsyntax/print/pprust.rs | 8 ++++---- src/libsyntax_ext/deriving/generic/mod.rs | 4 ++-- 9 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 58043f385fe..53438e3fca4 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -30,7 +30,7 @@ use rustc_borrowck::graphviz as borrowck_dot; use rustc_resolve as resolve; use rustc_metadata::cstore::CStore; -use syntax::ast; +use syntax::ast::{self, BlockCheckMode}; use syntax::codemap; use syntax::fold::{self, Folder}; use syntax::print::{pp, pprust}; @@ -651,7 +651,7 @@ impl fold::Folder for ReplaceBodyWithLoop { if !self.within_static_or_const { - let empty_block = expr_to_block(ast::DefaultBlock, None); + let empty_block = expr_to_block(BlockCheckMode::Default, None); let loop_expr = P(ast::Expr { node: ast::ExprLoop(empty_block, None), id: ast::DUMMY_NODE_ID, diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index 2862a1811fb..0f6309cfd52 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -1571,8 +1571,8 @@ pub fn lower_visibility(_lctx: &LoweringContext, v: Visibility) -> hir::Visibili pub fn lower_block_check_mode(lctx: &LoweringContext, b: &BlockCheckMode) -> hir::BlockCheckMode { match *b { - DefaultBlock => hir::DefaultBlock, - UnsafeBlock(u) => hir::UnsafeBlock(lower_unsafe_source(lctx, u)), + BlockCheckMode::Default => hir::DefaultBlock, + BlockCheckMode::Unsafe(u) => hir::UnsafeBlock(lower_unsafe_source(lctx, u)), } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 9d49fb3be4f..994b85a4458 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,7 +10,6 @@ // The Rust abstract syntax tree. -pub use self::BlockCheckMode::*; pub use self::CaptureClause::*; pub use self::Decl_::*; pub use self::ExplicitSelf_::*; @@ -870,8 +869,8 @@ pub type SpannedIdent = Spanned; #[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)] diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 91ced6eb076..48761ce767c 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -9,9 +9,7 @@ // except according to those terms. use abi; -use ast::{Ident, Generics, Expr}; -use ast::UnOp; -use ast; +use ast::{self, Ident, Generics, Expr, BlockCheckMode, UnOp}; use attr; use codemap::{Span, respan, Spanned, DUMMY_SP, Pos}; use ext::base::ExtCtxt; @@ -575,7 +573,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { stmts: stmts, expr: expr, id: ast::DUMMY_NODE_ID, - rules: ast::DefaultBlock, + rules: BlockCheckMode::Default, span: span, }) } diff --git a/src/libsyntax/parse/classify.rs b/src/libsyntax/parse/classify.rs index 1193224bdb6..ef50b3adad3 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 @@ -37,7 +37,7 @@ pub fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool { pub fn expr_is_simple_block(e: &ast::Expr) -> bool { match e.node { - ast::ExprBlock(ref block) => block.rules == ast::DefaultBlock, + ast::ExprBlock(ref block) => block.rules == BlockCheckMode::Default, _ => false, } } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index becce9ba7d9..4c2e00341bc 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -988,7 +988,7 @@ 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, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 3f7173b179c..f8c981ce9f6 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -18,7 +18,7 @@ use ast::{Mod, Arg, Arm, Attribute, BindingMode}; use ast::Block; use ast::{BlockCheckMode, CaptureByRef, CaptureByValue, CaptureClause}; use ast::{Constness, ConstTraitItem, Crate, CrateConfig}; -use ast::{Decl, DeclItem, DeclLocal, DefaultBlock}; +use ast::{Decl, DeclItem, DeclLocal}; use ast::{EMPTY_CTXT, EnumDef, ExplicitSelf}; use ast::{Expr, Expr_, ExprAddrOf, ExprMatch, ExprAgain}; use ast::{ExprAssign, ExprAssignOp, ExprBinary, ExprBlock, ExprBox}; @@ -53,7 +53,7 @@ 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::UnnamedField; use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple}; use ast::{Visibility, WhereClause}; use attr::{ThinAttributes, ThinAttributesExt, AttributesExt}; @@ -2104,7 +2104,7 @@ impl<'a> Parser<'a> { } }, 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; @@ -2220,7 +2220,7 @@ 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) { @@ -3062,7 +3062,7 @@ impl<'a> Parser<'a> { stmts: vec![], span: body_expr.span, expr: Some(body_expr), - rules: DefaultBlock, + rules: BlockCheckMode::Default, }) } _ => { @@ -3826,7 +3826,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. @@ -3836,7 +3836,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 diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 4e1f761c51a..bf35835e3b7 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -11,7 +11,7 @@ pub use self::AnnNode::*; use abi; -use ast::{self, TokenTree}; +use ast::{self, TokenTree, BlockCheckMode}; use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; use ast::Attribute; use attr::ThinAttributesExt; @@ -1684,8 +1684,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))); @@ -2610,7 +2610,7 @@ impl<'a> State<'a> { 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, ",")); } } diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 9eb516cd07a..153e4eedcf2 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -1266,7 +1266,7 @@ impl<'a> MethodDef<'a> { stmts: vec![], expr: Some(call), id: ast::DUMMY_NODE_ID, - rules: ast::UnsafeBlock(ast::CompilerGenerated), + rules: ast::BlockCheckMode::Unsafe(ast::CompilerGenerated), span: sp })); let target_ty = cx.ty_ident(sp, cx.ident_of(target_type_name)); @@ -1302,7 +1302,7 @@ impl<'a> MethodDef<'a> { stmts: vec![], expr: Some(call), id: ast::DUMMY_NODE_ID, - rules: ast::UnsafeBlock(ast::CompilerGenerated), + rules: ast::BlockCheckMode::Unsafe(ast::CompilerGenerated), span: sp })); match_arms.push(cx.arm(sp, vec![cx.pat_wild(sp)], unreachable)); From 243a30c9319b56e1be2b9ff2f9ed9e0d7583e2d1 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Fri, 5 Feb 2016 13:13:36 +0100 Subject: [PATCH 05/29] [breaking-change] don't glob import/export syntax::abi enum variants --- src/librustc/front/map/mod.rs | 6 +- src/librustc/middle/intrinsicck.rs | 2 +- src/librustc/middle/reachable.rs | 4 +- src/librustc/middle/traits/select.rs | 4 +- src/librustc/middle/ty/context.rs | 4 +- src/librustc/util/ppaux.rs | 4 +- src/librustc_back/target/mod.rs | 10 +-- src/librustc_driver/test.rs | 5 +- src/librustc_front/print/pprust.rs | 20 ++--- src/librustc_lint/builtin.rs | 2 +- src/librustc_lint/types.rs | 13 +-- src/librustc_metadata/creader.rs | 4 +- src/librustc_metadata/decoder.rs | 4 +- src/librustc_metadata/encoder.rs | 6 +- src/librustc_trans/trans/attributes.rs | 8 +- src/librustc_trans/trans/base.rs | 20 ++--- src/librustc_trans/trans/callee.rs | 20 ++--- src/librustc_trans/trans/closure.rs | 2 +- src/librustc_trans/trans/collector.rs | 2 +- src/librustc_trans/trans/debuginfo/mod.rs | 5 +- .../trans/debuginfo/type_names.rs | 2 +- src/librustc_trans/trans/declare.rs | 4 +- src/librustc_trans/trans/foreign.rs | 11 +-- src/librustc_trans/trans/intrinsic.rs | 12 +-- src/librustc_trans/trans/monomorphize.rs | 18 ++-- src/librustc_trans/trans/type_of.rs | 8 +- src/librustc_typeck/check/closure.rs | 4 +- src/librustc_typeck/check/intrinsic.rs | 10 +-- src/librustc_typeck/check/mod.rs | 6 +- src/librustc_typeck/lib.rs | 11 +-- src/librustdoc/clean/mod.rs | 10 +-- src/libsyntax/abi.rs | 82 +++++++++---------- src/libsyntax/ext/build.rs | 4 +- src/libsyntax/parse/mod.rs | 4 +- src/libsyntax/parse/parser.rs | 24 +++--- src/libsyntax/print/pprust.rs | 16 ++-- src/libsyntax/test.rs | 2 +- src/libsyntax_ext/deriving/generic/mod.rs | 5 +- 38 files changed, 189 insertions(+), 189 deletions(-) diff --git a/src/librustc/front/map/mod.rs b/src/librustc/front/map/mod.rs index 008229aca0b..f398c465ffe 100644 --- a/src/librustc/front/map/mod.rs +++ b/src/librustc/front/map/mod.rs @@ -20,7 +20,7 @@ use middle::cstore::InlinedItem; use middle::cstore::InlinedItem as II; use middle::def_id::DefId; -use syntax::abi; +use syntax::abi::Abi; use syntax::ast::{self, Name, NodeId, DUMMY_NODE_ID}; use syntax::codemap::{Span, Spanned}; use syntax::parse::token; @@ -512,7 +512,7 @@ impl<'ast> Map<'ast> { } } - pub fn get_foreign_abi(&self, id: NodeId) -> abi::Abi { + pub fn get_foreign_abi(&self, id: NodeId) -> Abi { let parent = self.get_parent(id); let abi = match self.find_entry(parent) { Some(EntryItem(_, i)) => { @@ -522,7 +522,7 @@ impl<'ast> Map<'ast> { } } /// Wrong but OK, because the only inlined foreign items are intrinsics. - Some(RootInlinedParent(_)) => Some(abi::RustIntrinsic), + Some(RootInlinedParent(_)) => Some(Abi::RustIntrinsic), _ => None }; match abi { diff --git a/src/librustc/middle/intrinsicck.rs b/src/librustc/middle/intrinsicck.rs index 9afc1e366ee..a763677db06 100644 --- a/src/librustc/middle/intrinsicck.rs +++ b/src/librustc/middle/intrinsicck.rs @@ -17,7 +17,7 @@ use middle::ty::{self, Ty, TypeFoldable}; use std::fmt; -use syntax::abi::RustIntrinsic; +use syntax::abi::Abi::RustIntrinsic; use syntax::ast; use syntax::codemap::Span; use rustc_front::intravisit::{self, Visitor, FnKind}; diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 6dd447e3b68..d34c3b74217 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -25,7 +25,7 @@ use session::config; use util::nodemap::NodeSet; use std::collections::HashSet; -use syntax::abi; +use syntax::abi::Abi; use syntax::ast; use syntax::attr; use rustc_front::hir; @@ -236,7 +236,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { // participate in linkage after this product is produced) if let ast_map::NodeItem(item) = *node { if let hir::ItemFn(_, _, _, abi, _, _) = item.node { - if abi != abi::Rust { + if abi != Abi::Rust { self.reachable_symbols.insert(search_item); } } diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index 61418734b67..29355e0684d 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -46,7 +46,7 @@ use middle::ty::relate::TypeRelation; use std::cell::RefCell; use std::fmt; use std::rc::Rc; -use syntax::abi; +use syntax::abi::Abi; use rustc_front::hir; use util::common::ErrorReported; use util::nodemap::FnvHashMap; @@ -1288,7 +1288,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // provide an impl, but only for suitable `fn` pointers ty::TyBareFn(_, &ty::BareFnTy { unsafety: hir::Unsafety::Normal, - abi: abi::Rust, + abi: Abi::Rust, sig: ty::Binder(ty::FnSig { inputs: _, output: ty::FnConverging(_), diff --git a/src/librustc/middle/ty/context.rs b/src/librustc/middle/ty/context.rs index 071cc0cbe3d..6307ec8bbd0 100644 --- a/src/librustc/middle/ty/context.rs +++ b/src/librustc/middle/ty/context.rs @@ -44,7 +44,7 @@ use std::borrow::Borrow; use std::cell::{Cell, RefCell, Ref}; use std::hash::{Hash, Hasher}; use std::rc::Rc; -use syntax::abi; +use syntax::abi::Abi; use syntax::ast::{self, Name, NodeId}; use syntax::attr; use syntax::parse::token::special_idents; @@ -943,7 +943,7 @@ impl<'tcx> ctxt<'tcx> { let input_args = input_tys.iter().cloned().collect(); self.mk_fn(Some(def_id), self.mk_bare_fn(BareFnTy { unsafety: hir::Unsafety::Normal, - abi: abi::Rust, + abi: Abi::Rust, sig: ty::Binder(ty::FnSig { inputs: input_args, output: ty::FnConverging(output), diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 77e39bba54a..a0939dc53df 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -20,7 +20,7 @@ use middle::ty::{TyBox, TyTrait, TyInt, TyUint, TyInfer}; use middle::ty::{self, Ty, TypeFoldable}; use std::fmt; -use syntax::{abi}; +use syntax::abi::Abi; use syntax::parse::token; use syntax::ast::CRATE_NODE_ID; use rustc_front::hir; @@ -814,7 +814,7 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> { try!(write!(f, "unsafe ")); } - if bare_fn.abi != abi::Rust { + if bare_fn.abi != Abi::Rust { try!(write!(f, "extern {} ", bare_fn.abi)); } diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index 896fde50147..a6aef52caf6 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -48,7 +48,7 @@ use serialize::json::Json; use std::default::Default; use std::io::prelude::*; -use syntax::abi; +use syntax::abi::Abi; mod android_base; mod apple_base; @@ -262,13 +262,13 @@ impl Default for TargetOptions { impl Target { /// Given a function ABI, turn "System" into the correct ABI for this target. - pub fn adjust_abi(&self, abi: abi::Abi) -> abi::Abi { + pub fn adjust_abi(&self, abi: Abi) -> Abi { match abi { - abi::System => { + Abi::System => { if self.options.is_like_windows && self.arch == "x86" { - abi::Stdcall + Abi::Stdcall } else { - abi::C + Abi::C } }, abi => abi diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index 3736e045bd1..3220295d9b8 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -32,7 +32,8 @@ use rustc_metadata::cstore::CStore; use rustc::front::map as hir_map; use rustc::session::{self, config}; use std::rc::Rc; -use syntax::{abi, ast}; +use syntax::ast; +use syntax::abi::Abi; use syntax::codemap::{MultiSpan, CodeMap, DUMMY_SP}; use syntax::errors; use syntax::errors::emitter::Emitter; @@ -263,7 +264,7 @@ impl<'a, 'tcx> Env<'a, 'tcx> { self.infcx.tcx.mk_fn(None, self.infcx.tcx.mk_bare_fn(ty::BareFnTy { unsafety: hir::Unsafety::Normal, - abi: abi::Rust, + abi: Abi::Rust, sig: ty::Binder(ty::FnSig { inputs: input_args, output: ty::FnConverging(output_ty), diff --git a/src/librustc_front/print/pprust.rs b/src/librustc_front/print/pprust.rs index dd39d3b63c4..091352bb8f8 100644 --- a/src/librustc_front/print/pprust.rs +++ b/src/librustc_front/print/pprust.rs @@ -10,7 +10,7 @@ pub use self::AnnNode::*; -use syntax::abi; +use syntax::abi::Abi; use syntax::ast; use syntax::codemap::{self, CodeMap, BytePos, Spanned}; use syntax::errors; @@ -290,7 +290,7 @@ pub fn fun_to_string(decl: &hir::FnDecl, try!(s.print_fn(decl, unsafety, constness, - abi::Rust, + Abi::Rust, Some(name), generics, opt_explicit_self, @@ -569,7 +569,7 @@ impl<'a> State<'a> { try!(self.print_fn(decl, hir::Unsafety::Normal, hir::Constness::NotConst, - abi::Rust, + Abi::Rust, Some(item.name), generics, None, @@ -1916,7 +1916,7 @@ impl<'a> State<'a> { decl: &hir::FnDecl, unsafety: hir::Unsafety, constness: hir::Constness, - abi: abi::Abi, + abi: Abi, name: Option, generics: &hir::Generics, opt_explicit_self: Option<&hir::ExplicitSelf_>, @@ -2250,7 +2250,7 @@ impl<'a> State<'a> { } pub fn print_ty_fn(&mut self, - abi: abi::Abi, + abi: Abi, unsafety: hir::Unsafety, decl: &hir::FnDecl, name: Option, @@ -2331,10 +2331,10 @@ impl<'a> State<'a> { } pub fn print_opt_abi_and_extern_if_nondefault(&mut self, - opt_abi: Option) + opt_abi: Option) -> 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()) @@ -2343,7 +2343,7 @@ impl<'a> State<'a> { } } - pub fn print_extern_opt_abi(&mut self, opt_abi: Option) -> io::Result<()> { + pub fn print_extern_opt_abi(&mut self, opt_abi: Option) -> io::Result<()> { match opt_abi { Some(abi) => { try!(self.word_nbsp("extern")); @@ -2356,7 +2356,7 @@ impl<'a> State<'a> { pub fn print_fn_header_info(&mut self, unsafety: hir::Unsafety, constness: hir::Constness, - abi: abi::Abi, + abi: Abi, vis: hir::Visibility) -> io::Result<()> { try!(word(&mut self.s, &visibility_qualified(vis, ""))); @@ -2367,7 +2367,7 @@ impl<'a> State<'a> { hir::Constness::Const => try!(self.word_nbsp("const")), } - if abi != abi::Rust { + if abi != Abi::Rust { try!(self.word_nbsp("extern")); try!(self.word_nbsp(&abi.to_string())); } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 9e3ca70e5e4..09cdab33c84 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1039,7 +1039,7 @@ impl LintPass for MutableTransmutes { impl LateLintPass for MutableTransmutes { fn check_expr(&mut self, cx: &LateContext, expr: &hir::Expr) { - use syntax::abi::RustIntrinsic; + use syntax::abi::Abi::RustIntrinsic; let msg = "mutating transmuted &mut T from &T may cause undefined behavior,\ consider instead using an UnsafeCell"; diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 2688d549d4f..fae40d7224b 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -23,7 +23,8 @@ use lint::{LintPass, LateLintPass}; use std::cmp; use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64}; -use syntax::{abi, ast}; +use syntax::ast; +use syntax::abi::Abi; use syntax::attr::{self, AttrMetaMethods}; use syntax::codemap::{self, Span}; @@ -558,10 +559,10 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { ty::TyBareFn(None, bare_fn) => { match bare_fn.abi { - abi::Rust | - abi::RustIntrinsic | - abi::PlatformIntrinsic | - abi::RustCall => { + Abi::Rust | + Abi::RustIntrinsic | + Abi::PlatformIntrinsic | + Abi::RustCall => { return FfiUnsafe( "found function pointer with Rust calling \ convention in foreign module; consider using an \ @@ -677,7 +678,7 @@ impl LateLintPass for ImproperCTypes { } if let hir::ItemForeignMod(ref nmod) = it.node { - if nmod.abi != abi::RustIntrinsic && nmod.abi != abi::PlatformIntrinsic { + if nmod.abi != Abi::RustIntrinsic && nmod.abi != Abi::PlatformIntrinsic { for ni in &nmod.items { match ni.node { hir::ForeignItemFn(ref decl, _) => check_foreign_fn(cx, &**decl), diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 7b094a5900a..d5aa091886e 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -31,7 +31,7 @@ use std::rc::Rc; use std::fs; use syntax::ast; -use syntax::abi; +use syntax::abi::Abi; use syntax::codemap::{self, Span, mk_sp, Pos}; use syntax::parse; use syntax::attr; @@ -784,7 +784,7 @@ impl<'a, 'b> LocalCrateReader<'a, 'b> { } fn process_foreign_mod(&mut self, i: &hir::Item, fm: &hir::ForeignMod) { - if fm.abi == abi::Rust || fm.abi == abi::RustIntrinsic || fm.abi == abi::PlatformIntrinsic { + if fm.abi == Abi::Rust || fm.abi == Abi::RustIntrinsic || fm.abi == Abi::PlatformIntrinsic { return; } diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 2cdce7ae784..f73d6f0de2c 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -51,7 +51,7 @@ use syntax::attr; use syntax::parse::token::{IdentInterner, special_idents}; use syntax::parse::token; use syntax::ast; -use syntax::abi; +use syntax::abi::Abi; use syntax::codemap::{self, Span, BytePos, NO_EXPANSION}; use syntax::print::pprust; use syntax::ptr::P; @@ -1701,7 +1701,7 @@ pub fn is_extern_fn(cdata: Cmd, id: DefIndex, tcx: &ty::ctxt) -> bool { if let Fn = item_family(item_doc) { let ty::TypeScheme { generics, ty } = get_type(cdata, id, tcx); generics.types.is_empty() && match ty.sty { - ty::TyBareFn(_, fn_ty) => fn_ty.abi != abi::Rust, + ty::TyBareFn(_, fn_ty) => fn_ty.abi != Abi::Rust, _ => false, } } else { diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 50030ced0ab..bcc506e96bb 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -40,7 +40,7 @@ use std::io::prelude::*; use std::io::{Cursor, SeekFrom}; use std::rc::Rc; use std::u32; -use syntax::abi; +use syntax::abi::Abi; use syntax::ast::{self, NodeId, Name, CRATE_NODE_ID, CrateNum}; use syntax::codemap::BytePos; use syntax::attr; @@ -1381,7 +1381,7 @@ fn encode_info_for_foreign_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, nitem: &hir::ForeignItem, index: &mut CrateIndex<'tcx>, path: PathElems, - abi: abi::Abi) { + abi: Abi) { let def_id = ecx.tcx.map.local_def_id(nitem.id); index.record(def_id, rbml_w); @@ -1393,7 +1393,7 @@ fn encode_info_for_foreign_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>, encode_family(rbml_w, FN_FAMILY); encode_bounds_and_type_for_item(rbml_w, ecx, index, nitem.id); encode_name(rbml_w, nitem.name); - if abi == abi::RustIntrinsic || abi == abi::PlatformIntrinsic { + if abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic { encode_inlined_item(ecx, rbml_w, InlinedItemRef::Foreign(nitem)); } encode_attributes(rbml_w, &*nitem.attrs); diff --git a/src/librustc_trans/trans/attributes.rs b/src/librustc_trans/trans/attributes.rs index 28dfa4e07e6..be0c62f511f 100644 --- a/src/librustc_trans/trans/attributes.rs +++ b/src/librustc_trans/trans/attributes.rs @@ -14,7 +14,7 @@ use llvm::{self, ValueRef, AttrHelper}; use middle::ty; use middle::infer; use session::config::NoDebugInfo; -use syntax::abi; +use syntax::abi::Abi; pub use syntax::attr::InlineAttr; use syntax::ast; use rustc_front::hir; @@ -136,7 +136,7 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx let infcx = infer::normalizing_infer_ctxt(ccx.tcx(), &ccx.tcx().tables); function_type = infcx.closure_type(closure_did, substs); let self_type = base::self_type_for_closure(ccx, closure_did, fn_type); - (&function_type.sig, abi::RustCall, Some(self_type)) + (&function_type.sig, Abi::RustCall, Some(self_type)) } _ => ccx.sess().bug("expected closure or function.") }; @@ -151,7 +151,7 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx // unpack the input ty's let input_tys = match fn_type.sty { ty::TyClosure(..) => { - assert!(abi == abi::RustCall); + assert!(abi == Abi::RustCall); match fn_sig.inputs[0].sty { ty::TyTuple(ref inputs) => { @@ -162,7 +162,7 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx _ => ccx.sess().bug("expected tuple'd inputs") } }, - ty::TyBareFn(..) if abi == abi::RustCall => { + ty::TyBareFn(..) if abi == Abi::RustCall => { let mut inputs = vec![fn_sig.inputs[0]]; match fn_sig.inputs[1].sty { diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index 720ec3f1689..911229ded3d 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -100,7 +100,7 @@ use std::cell::{Cell, RefCell}; use std::collections::{HashMap, HashSet}; use std::str; use std::{i8, i16, i32, i64}; -use syntax::abi::{Rust, RustCall, RustIntrinsic, PlatformIntrinsic, Abi}; +use syntax::abi::Abi; use syntax::codemap::{Span, DUMMY_SP}; use syntax::parse::token::InternedString; use syntax::attr::AttrMetaMethods; @@ -911,10 +911,10 @@ pub fn trans_external_path<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, match t.sty { ty::TyBareFn(_, ref fn_ty) => { match ccx.sess().target.target.adjust_abi(fn_ty.abi) { - Rust | RustCall => { + Abi::Rust | Abi::RustCall => { get_extern_rust_fn(ccx, t, &name[..], did) } - RustIntrinsic | PlatformIntrinsic => { + Abi::RustIntrinsic | Abi::PlatformIntrinsic => { ccx.sess().bug("unexpected intrinsic in trans_external_path") } _ => { @@ -2031,7 +2031,7 @@ pub fn trans_closure<'a, 'b, 'tcx>(ccx: &CrateContext<'a, 'tcx>, bcx.fcx.ccx.tn().val_to_string(bcx.fcx.llfn)); let has_tupled_arg = match closure_env { - closure::ClosureEnv::NotClosure => abi == RustCall, + closure::ClosureEnv::NotClosure => abi == Abi::RustCall, _ => false, }; @@ -2503,7 +2503,7 @@ pub fn trans_item(ccx: &CrateContext, item: &hir::Item) { for (ref ccx, is_origin) in ccx.maybe_iter(!from_external && trans_everywhere) { let llfn = get_item_val(ccx, item.id); let empty_substs = ccx.tcx().mk_substs(Substs::trans_empty()); - if abi != Rust { + if abi != Abi::Rust { foreign::trans_rust_fn_with_foreign_abi(ccx, &**decl, &**body, @@ -2607,12 +2607,12 @@ fn register_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, node_type: Ty<'tcx>) -> ValueRef { if let ty::TyBareFn(_, ref f) = node_type.sty { - if f.abi != Rust && f.abi != RustCall { + if f.abi != Abi::Rust && f.abi != Abi::RustCall { ccx.sess().span_bug(sp, &format!("only the `{}` or `{}` calling conventions are valid \ for this function; `{}` was specified", - Rust.name(), - RustCall.name(), + Abi::Rust.name(), + Abi::RustCall.name(), f.abi.name())); } } else { @@ -2790,7 +2790,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef { hir::ItemFn(_, _, _, abi, _, _) => { let sym = sym(); - let llfn = if abi == Rust { + let llfn = if abi == Abi::Rust { register_fn(ccx, i.span, sym, i.id, ty) } else { foreign::register_rust_fn_with_foreign_abi(ccx, i.span, sym, i.id) @@ -2913,7 +2913,7 @@ fn register_method(ccx: &CrateContext, let sym = exported_name(ccx, id, mty, &attrs); if let ty::TyBareFn(_, ref f) = mty.sty { - let llfn = if f.abi == Rust || f.abi == RustCall { + let llfn = if f.abi == Abi::Rust || f.abi == Abi::RustCall { register_fn(ccx, span, sym, id, mty) } else { foreign::register_rust_fn_with_foreign_abi(ccx, span, sym, id) diff --git a/src/librustc_trans/trans/callee.rs b/src/librustc_trans/trans/callee.rs index 2651b3576fe..29821384ae9 100644 --- a/src/librustc_trans/trans/callee.rs +++ b/src/librustc_trans/trans/callee.rs @@ -55,7 +55,7 @@ use middle::ty::{self, Ty, TypeFoldable}; use middle::ty::MethodCall; use rustc_front::hir; -use syntax::abi as synabi; +use syntax::abi::Abi; use syntax::ast; use syntax::errors; use syntax::ptr::P; @@ -157,8 +157,8 @@ fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &hir::Expr) } } Def::Fn(did) if match expr_ty.sty { - ty::TyBareFn(_, ref f) => f.abi == synabi::RustIntrinsic || - f.abi == synabi::PlatformIntrinsic, + ty::TyBareFn(_, ref f) => f.abi == Abi::RustIntrinsic || + f.abi == Abi::PlatformIntrinsic, _ => false } => { let substs = common::node_id_substs(bcx.ccx(), @@ -294,7 +294,7 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>( match bare_fn_ty.sty { ty::TyBareFn(opt_def_id, &ty::BareFnTy { unsafety: hir::Unsafety::Normal, - abi: synabi::Rust, + abi: Abi::Rust, ref sig }) => { (opt_def_id, sig) } @@ -310,7 +310,7 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>( let tuple_fn_ty = tcx.mk_fn(opt_def_id, tcx.mk_bare_fn(ty::BareFnTy { unsafety: hir::Unsafety::Normal, - abi: synabi::RustCall, + abi: Abi::RustCall, sig: ty::Binder(ty::FnSig { inputs: vec![bare_fn_ty_maybe_ref, tuple_input_ty], @@ -622,7 +622,7 @@ pub fn trans_call_inner<'a, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>, (d.llfn, Some(d.llself)) } Intrinsic(node, substs) => { - assert!(abi == synabi::RustIntrinsic || abi == synabi::PlatformIntrinsic); + assert!(abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic); assert!(dest.is_some()); let call_info = match debug_loc { @@ -652,9 +652,9 @@ pub fn trans_call_inner<'a, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>, // Intrinsics should not become actual functions. // We trans them in place in `trans_intrinsic_call` - assert!(abi != synabi::RustIntrinsic && abi != synabi::PlatformIntrinsic); + assert!(abi != Abi::RustIntrinsic && abi != Abi::PlatformIntrinsic); - let is_rust_fn = abi == synabi::Rust || abi == synabi::RustCall; + let is_rust_fn = abi == Abi::Rust || abi == Abi::RustCall; // Generate a location to store the result. If the user does // not care about the result, just make a stack slot. @@ -936,7 +936,7 @@ pub fn trans_args<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>, llargs: &mut Vec, arg_cleanup_scope: cleanup::ScopeId, ignore_self: bool, - abi: synabi::Abi) + abi: Abi) -> Block<'blk, 'tcx> { debug!("trans_args(abi={})", abi); @@ -953,7 +953,7 @@ pub fn trans_args<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>, // to cast her view of the arguments to the caller's view. match args { ArgExprs(arg_exprs) => { - if abi == synabi::RustCall { + if abi == Abi::RustCall { // This is only used for direct calls to the `call`, // `call_mut` or `call_once` functions. return trans_args_under_call_abi(cx, diff --git a/src/librustc_trans/trans/closure.rs b/src/librustc_trans/trans/closure.rs index c2d6422e3b0..7c978cb275e 100644 --- a/src/librustc_trans/trans/closure.rs +++ b/src/librustc_trans/trans/closure.rs @@ -30,7 +30,7 @@ use trans::Disr; use middle::ty; use session::config::FullDebugInfo; -use syntax::abi::RustCall; +use syntax::abi::Abi::RustCall; use syntax::ast; use syntax::attr::{ThinAttributes, ThinAttributesExt}; diff --git a/src/librustc_trans/trans/collector.rs b/src/librustc_trans/trans/collector.rs index df86685e236..ae4f7461a26 100644 --- a/src/librustc_trans/trans/collector.rs +++ b/src/librustc_trans/trans/collector.rs @@ -1294,7 +1294,7 @@ pub fn push_unique_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, output.push_str("unsafe "); } - if abi != ::syntax::abi::Rust { + if abi != ::syntax::abi::Abi::Rust { output.push_str("extern \""); output.push_str(abi.name()); output.push_str("\" "); diff --git a/src/librustc_trans/trans/debuginfo/mod.rs b/src/librustc_trans/trans/debuginfo/mod.rs index f0b48ddd5c3..702721157be 100644 --- a/src/librustc_trans/trans/debuginfo/mod.rs +++ b/src/librustc_trans/trans/debuginfo/mod.rs @@ -48,7 +48,8 @@ use std::ptr; use std::rc::Rc; use syntax::codemap::{Span, Pos}; -use syntax::{abi, ast, codemap}; +use syntax::{ast, codemap}; +use syntax::abi::Abi; use syntax::attr::IntType; use syntax::parse::token::{self, special_idents}; @@ -455,7 +456,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, ty::FnDiverging => diverging_type_metadata(cx) }); - let inputs = &if abi == abi::RustCall { + let inputs = &if abi == Abi::RustCall { type_of::untuple_arguments(cx, &sig.inputs) } else { sig.inputs diff --git a/src/librustc_trans/trans/debuginfo/type_names.rs b/src/librustc_trans/trans/debuginfo/type_names.rs index 9f20131f9aa..f243b1e3bfa 100644 --- a/src/librustc_trans/trans/debuginfo/type_names.rs +++ b/src/librustc_trans/trans/debuginfo/type_names.rs @@ -106,7 +106,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, output.push_str("unsafe "); } - if abi != ::syntax::abi::Rust { + if abi != ::syntax::abi::Abi::Rust { output.push_str("extern \""); output.push_str(abi.name()); output.push_str("\" "); diff --git a/src/librustc_trans/trans/declare.rs b/src/librustc_trans/trans/declare.rs index b9e74beaf55..75b60be02f7 100644 --- a/src/librustc_trans/trans/declare.rs +++ b/src/librustc_trans/trans/declare.rs @@ -22,7 +22,7 @@ use llvm::{self, ValueRef}; use middle::ty; use middle::infer; -use syntax::abi; +use syntax::abi::Abi; use trans::attributes; use trans::base; use trans::context::CrateContext; @@ -116,7 +116,7 @@ pub fn declare_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, name: &str, let llenvironment_type = type_of::type_of_explicit_arg(ccx, self_type); debug!("declare_rust_fn function_type={:?} self_type={:?}", function_type, self_type); - (&function_type.sig, abi::RustCall, Some(llenvironment_type)) + (&function_type.sig, Abi::RustCall, Some(llenvironment_type)) } _ => ccx.sess().bug("expected closure or fn") }; diff --git a/src/librustc_trans/trans/foreign.rs b/src/librustc_trans/trans/foreign.rs index 3689f30e38f..5a909888bd8 100644 --- a/src/librustc_trans/trans/foreign.rs +++ b/src/librustc_trans/trans/foreign.rs @@ -34,9 +34,7 @@ use middle::subst::Substs; use std::cmp; use std::iter::once; use libc::c_uint; -use syntax::abi::{Cdecl, Aapcs, C, Win64, Abi}; -use syntax::abi::{PlatformIntrinsic, RustIntrinsic, Rust, RustCall, Stdcall}; -use syntax::abi::{Fastcall, Vectorcall, System}; +use syntax::abi::Abi; use syntax::attr; use syntax::codemap::Span; use syntax::parse::token::{InternedString, special_idents}; @@ -80,6 +78,7 @@ struct LlvmSignature { pub fn llvm_calling_convention(ccx: &CrateContext, abi: Abi) -> CallConv { + use syntax::abi::Abi::*; match ccx.sess().target.target.adjust_abi(abi) { RustIntrinsic => { // Intrinsics are emitted at the call site @@ -488,7 +487,7 @@ pub fn trans_foreign_mod(ccx: &CrateContext, foreign_mod: &hir::ForeignMod) { if let hir::ForeignItemFn(ref decl, _) = foreign_item.node { match foreign_mod.abi { - Rust | RustIntrinsic | PlatformIntrinsic => {} + Abi::Rust | Abi::RustIntrinsic | Abi::PlatformIntrinsic => {} abi => { let ty = ccx.tcx().node_id_to_type(foreign_item.id); match ty.sty { @@ -626,7 +625,9 @@ pub fn trans_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, // normal Rust function. This will be the type of the wrappee fn. match t.sty { ty::TyBareFn(_, ref f) => { - assert!(f.abi != Rust && f.abi != RustIntrinsic && f.abi != PlatformIntrinsic); + assert!(f.abi != Abi::Rust); + assert!(f.abi != Abi::RustIntrinsic); + assert!(f.abi != Abi::PlatformIntrinsic); } _ => { ccx.sess().bug(&format!("build_rust_fn: extern fn {} has ty {:?}, \ diff --git a/src/librustc_trans/trans/intrinsic.rs b/src/librustc_trans/trans/intrinsic.rs index c6fb119ff0b..3e5cd7389c4 100644 --- a/src/librustc_trans/trans/intrinsic.rs +++ b/src/librustc_trans/trans/intrinsic.rs @@ -40,7 +40,7 @@ use trans::Disr; use middle::subst::Substs; use rustc::dep_graph::DepNode; use rustc_front::hir; -use syntax::abi::{self, RustIntrinsic}; +use syntax::abi::Abi; use syntax::ast; use syntax::ptr::P; use syntax::parse::token; @@ -365,7 +365,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, &mut llargs, cleanup::CustomScope(cleanup_scope), false, - RustIntrinsic); + Abi::RustIntrinsic); fcx.scopes.borrow_mut().last_mut().unwrap().drop_non_lifetime_clean(); @@ -1261,7 +1261,7 @@ fn get_rust_try_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>, let i8p = tcx.mk_mut_ptr(tcx.types.i8); let fn_ty = tcx.mk_bare_fn(ty::BareFnTy { unsafety: hir::Unsafety::Unsafe, - abi: abi::Rust, + abi: Abi::Rust, sig: ty::Binder(ty::FnSig { inputs: vec![i8p], output: ty::FnOutput::FnConverging(tcx.mk_nil()), @@ -1272,7 +1272,7 @@ fn get_rust_try_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>, let output = ty::FnOutput::FnConverging(tcx.types.i32); let try_fn_ty = tcx.mk_bare_fn(ty::BareFnTy { unsafety: hir::Unsafety::Unsafe, - abi: abi::Rust, + abi: Abi::Rust, sig: ty::Binder(ty::FnSig { inputs: vec![fn_ty, i8p, i8p], output: output, @@ -1350,7 +1350,7 @@ fn generate_filter_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>, // just do the same. let filter_fn_ty = tcx.mk_bare_fn(ty::BareFnTy { unsafety: hir::Unsafety::Unsafe, - abi: abi::Rust, + abi: Abi::Rust, sig: ty::Binder(ty::FnSig { inputs: vec![], output: output, @@ -1370,7 +1370,7 @@ fn generate_filter_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>, // those along. let filter_fn_ty = tcx.mk_bare_fn(ty::BareFnTy { unsafety: hir::Unsafety::Unsafe, - abi: abi::Rust, + abi: Abi::Rust, sig: ty::Binder(ty::FnSig { inputs: vec![i8p, i8p], output: output, diff --git a/src/librustc_trans/trans/monomorphize.rs b/src/librustc_trans/trans/monomorphize.rs index 62e69cbb85e..cda62c23847 100644 --- a/src/librustc_trans/trans/monomorphize.rs +++ b/src/librustc_trans/trans/monomorphize.rs @@ -29,7 +29,7 @@ use rustc::front::map as hir_map; use rustc_front::hir; -use syntax::abi; +use syntax::abi::Abi; use syntax::ast; use syntax::attr; use syntax::errors; @@ -96,7 +96,7 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, if let hir_map::NodeForeignItem(_) = map_node { let abi = ccx.tcx().map.get_foreign_abi(fn_node_id); - if abi != abi::RustIntrinsic && abi != abi::PlatformIntrinsic { + if abi != Abi::RustIntrinsic && abi != Abi::PlatformIntrinsic { // Foreign externs don't have to be monomorphized. return (get_item_val(ccx, fn_node_id), mono_ty, true); } @@ -139,8 +139,8 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, // This shouldn't need to option dance. let mut hash_id = Some(hash_id); - let mut mk_lldecl = |abi: abi::Abi| { - let lldecl = if abi != abi::Rust { + let mut mk_lldecl = |abi: Abi| { + let lldecl = if abi != Abi::Rust { foreign::decl_rust_fn_with_foreign_abi(ccx, mono_ty, &s) } else { // FIXME(nagisa): perhaps needs a more fine grained selection? See @@ -181,7 +181,7 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, let d = mk_lldecl(abi); let needs_body = setup_lldecl(d, &i.attrs); if needs_body { - if abi != abi::Rust { + if abi != Abi::Rust { foreign::trans_rust_fn_with_foreign_abi( ccx, &**decl, &**body, &[], d, psubsts, fn_node_id, Some(&hash[..])); @@ -206,7 +206,7 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, hir_map::NodeVariant(v) => { let variant = inlined_variant_def(ccx, fn_node_id); assert_eq!(v.node.name, variant.name); - let d = mk_lldecl(abi::Rust); + let d = mk_lldecl(Abi::Rust); attributes::inline(d, attributes::InlineAttr::Hint); trans_enum_variant(ccx, fn_node_id, Disr::from(variant.disr_val), psubsts, d); d @@ -214,7 +214,7 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, hir_map::NodeImplItem(impl_item) => { match impl_item.node { hir::ImplItemKind::Method(ref sig, ref body) => { - let d = mk_lldecl(abi::Rust); + let d = mk_lldecl(Abi::Rust); let needs_body = setup_lldecl(d, &impl_item.attrs); if needs_body { trans_fn(ccx, @@ -236,7 +236,7 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, hir_map::NodeTraitItem(trait_item) => { match trait_item.node { hir::MethodTraitItem(ref sig, Some(ref body)) => { - let d = mk_lldecl(abi::Rust); + let d = mk_lldecl(Abi::Rust); let needs_body = setup_lldecl(d, &trait_item.attrs); if needs_body { trans_fn(ccx, @@ -256,7 +256,7 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, } } hir_map::NodeStructCtor(struct_def) => { - let d = mk_lldecl(abi::Rust); + let d = mk_lldecl(Abi::Rust); attributes::inline(d, attributes::InlineAttr::Hint); if struct_def.is_struct() { panic!("ast-mapped struct didn't have a ctor id") diff --git a/src/librustc_trans/trans/type_of.rs b/src/librustc_trans/trans/type_of.rs index 8696bdd60e2..d9400073685 100644 --- a/src/librustc_trans/trans/type_of.rs +++ b/src/librustc_trans/trans/type_of.rs @@ -21,7 +21,7 @@ use middle::ty::{self, Ty, TypeFoldable}; use trans::type_::Type; -use syntax::abi; +use syntax::abi::Abi; use syntax::ast; // LLVM doesn't like objects that are too big. Issue #17913 @@ -91,7 +91,7 @@ pub fn untuple_arguments<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, pub fn type_of_rust_fn<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, llenvironment_type: Option, sig: &ty::FnSig<'tcx>, - abi: abi::Abi) + abi: Abi) -> Type { debug!("type_of_rust_fn(sig={:?},abi={:?})", @@ -104,7 +104,7 @@ pub fn type_of_rust_fn<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, // First, munge the inputs, if this has the `rust-call` ABI. let inputs_temp; - let inputs = if abi == abi::RustCall { + let inputs = if abi == Abi::RustCall { inputs_temp = untuple_arguments(cx, &sig.inputs); &inputs_temp } else { @@ -156,7 +156,7 @@ pub fn type_of_fn_from_ty<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, fty: Ty<'tcx>) ty::TyBareFn(_, ref f) => { // FIXME(#19925) once fn item types are // zero-sized, we'll need to do something here - if f.abi == abi::Rust || f.abi == abi::RustCall { + if f.abi == Abi::Rust || f.abi == Abi::RustCall { let sig = cx.tcx().erase_late_bound_regions(&f.sig); let sig = infer::normalize_associated_type(cx.tcx(), &sig); type_of_rust_fn(cx, None, &sig, f.abi) diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index 3b7cb2bd4b4..7fd35cf159f 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -16,7 +16,7 @@ use astconv; use middle::subst; use middle::ty::{self, ToPolyTraitRef, Ty}; use std::cmp; -use syntax::abi; +use syntax::abi::Abi; use rustc_front::hir; pub fn check_expr_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>, @@ -54,7 +54,7 @@ fn check_closure<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>, let mut fn_ty = astconv::ty_of_closure(fcx, hir::Unsafety::Normal, decl, - abi::RustCall, + Abi::RustCall, expected_sig); // Create type variables (for now) to represent the transformed diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 61d468c59ce..248a2341c2b 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -20,7 +20,7 @@ use middle::ty::fold::TypeFolder; use {CrateCtxt, require_same_types}; use std::collections::{HashMap}; -use syntax::abi; +use syntax::abi::Abi; use syntax::ast; use syntax::attr::AttrMetaMethods; use syntax::codemap::Span; @@ -30,7 +30,7 @@ use rustc_front::hir; fn equate_intrinsic_type<'a, 'tcx>(tcx: &ty::ctxt<'tcx>, it: &hir::ForeignItem, n_tps: usize, - abi: abi::Abi, + abi: Abi, inputs: Vec>, output: ty::FnOutput<'tcx>) { let fty = tcx.mk_fn(None, tcx.mk_bare_fn(ty::BareFnTy { @@ -285,7 +285,7 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &hir::ForeignItem) { let mut_u8 = tcx.mk_mut_ptr(tcx.types.u8); let fn_ty = ty::BareFnTy { unsafety: hir::Unsafety::Normal, - abi: abi::Rust, + abi: Abi::Rust, sig: ty::Binder(FnSig { inputs: vec![mut_u8], output: ty::FnOutput::FnConverging(tcx.mk_nil()), @@ -308,7 +308,7 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &hir::ForeignItem) { tcx, it, n_tps, - abi::RustIntrinsic, + Abi::RustIntrinsic, inputs, output ) @@ -398,7 +398,7 @@ pub fn check_platform_intrinsic_type(ccx: &CrateCtxt, tcx, it, n_tps, - abi::PlatformIntrinsic, + Abi::PlatformIntrinsic, inputs, ty::FnConverging(output) ) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index a476f9e1a80..a1280d0f7e4 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -115,7 +115,7 @@ use util::nodemap::{DefIdMap, FnvHashMap, NodeMap}; use std::cell::{Cell, Ref, RefCell}; use std::collections::{HashSet}; use std::mem::replace; -use syntax::abi; +use syntax::abi::Abi; use syntax::ast; use syntax::attr; use syntax::attr::AttrMetaMethods; @@ -691,11 +691,11 @@ pub fn check_item_type<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx hir::Item) { check_bounds_are_used(ccx, &generics.ty_params, pty_ty); } hir::ItemForeignMod(ref m) => { - if m.abi == abi::RustIntrinsic { + if m.abi == Abi::RustIntrinsic { for item in &m.items { intrinsic::check_intrinsic_type(ccx, item); } - } else if m.abi == abi::PlatformIntrinsic { + } else if m.abi == Abi::PlatformIntrinsic { for item in &m.items { intrinsic::check_platform_intrinsic_type(ccx, item); } diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 083eeff9f90..0c8ad5abe6f 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -111,7 +111,8 @@ use util::common::time; use rustc_front::hir; use syntax::codemap::Span; -use syntax::{ast, abi}; +use syntax::ast; +use syntax::abi::Abi; use std::cell::RefCell; @@ -175,9 +176,9 @@ fn lookup_full_def(tcx: &ty::ctxt, sp: Span, id: ast::NodeId) -> Def { fn require_c_abi_if_variadic(tcx: &ty::ctxt, decl: &hir::FnDecl, - abi: abi::Abi, + abi: Abi, span: Span) { - if decl.variadic && abi != abi::C { + if decl.variadic && abi != Abi::C { span_err!(tcx.sess, span, E0045, "variadic function must have C calling convention"); } @@ -238,7 +239,7 @@ fn check_main_fn_ty(ccx: &CrateCtxt, let main_def_id = tcx.map.local_def_id(main_id); let se_ty = tcx.mk_fn(Some(main_def_id), tcx.mk_bare_fn(ty::BareFnTy { unsafety: hir::Unsafety::Normal, - abi: abi::Rust, + abi: Abi::Rust, sig: ty::Binder(ty::FnSig { inputs: Vec::new(), output: ty::FnConverging(tcx.mk_nil()), @@ -285,7 +286,7 @@ fn check_start_fn_ty(ccx: &CrateCtxt, let se_ty = tcx.mk_fn(Some(ccx.tcx.map.local_def_id(start_id)), tcx.mk_bare_fn(ty::BareFnTy { unsafety: hir::Unsafety::Normal, - abi: abi::Rust, + abi: Abi::Rust, sig: ty::Binder(ty::FnSig { inputs: vec!( tcx.types.isize, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 5e8b1194da0..d7fb789ada1 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -25,7 +25,7 @@ pub use self::SelfTy::*; pub use self::FunctionRetTy::*; use syntax; -use syntax::abi; +use syntax::abi::Abi; use syntax::ast; use syntax::attr; use syntax::attr::{AttributeMethods, AttrMetaMethods}; @@ -993,7 +993,7 @@ pub struct Method { pub unsafety: hir::Unsafety, pub constness: hir::Constness, pub decl: FnDecl, - pub abi: abi::Abi + pub abi: Abi, } impl Clean for hir::MethodSig { @@ -1028,7 +1028,7 @@ pub struct TyMethod { pub decl: FnDecl, pub generics: Generics, pub self_: SelfTy, - pub abi: abi::Abi + pub abi: Abi, } impl Clean for hir::MethodSig { @@ -1082,7 +1082,7 @@ pub struct Function { pub generics: Generics, pub unsafety: hir::Unsafety, pub constness: hir::Constness, - pub abi: abi::Abi, + pub abi: Abi, } impl Clean for doctree::Function { @@ -2486,7 +2486,7 @@ impl Clean for hir::ForeignItem { decl: decl.clean(cx), generics: generics.clean(cx), unsafety: hir::Unsafety::Unsafe, - abi: abi::Rust, + abi: Abi::Rust, constness: hir::Constness::NotConst, }) } 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/ext/build.rs b/src/libsyntax/ext/build.rs index 48761ce767c..6da9a208f37 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use abi; +use abi::Abi; use ast::{self, Ident, Generics, Expr, BlockCheckMode, UnOp}; use attr; use codemap::{Span, respan, Spanned, DUMMY_SP, Pos}; @@ -971,7 +971,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ast::ItemFn(self.fn_decl(inputs, output), ast::Unsafety::Normal, ast::Constness::NotConst, - abi::Rust, + Abi::Rust, generics, body)) } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 4c2e00341bc..a47ca51a98a 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -684,7 +684,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; @@ -955,7 +955,7 @@ mod tests { }), 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(), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index f8c981ce9f6..b10c42c4b0e 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -10,7 +10,7 @@ pub use self::PathParsingMode::*; -use abi; +use abi::{self, Abi}; use ast::BareFnTy; use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; use ast::{Public, Unsafety}; @@ -1127,9 +1127,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)); @@ -4647,12 +4647,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) }; @@ -5350,7 +5350,7 @@ impl<'a> Parser<'a> { -> PResult<'a, P> { 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())); @@ -5522,7 +5522,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; @@ -5565,7 +5565,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, @@ -5630,7 +5630,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, @@ -5645,9 +5645,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) = diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index bf35835e3b7..9d5bd798ec7 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -10,7 +10,7 @@ pub use self::AnnNode::*; -use abi; +use abi::{self, Abi}; use ast::{self, TokenTree, BlockCheckMode}; use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; use ast::Attribute; @@ -387,7 +387,7 @@ pub fn fun_to_string(decl: &ast::FnDecl, -> String { to_string(|s| { try!(s.head("")); - try!(s.print_fn(decl, unsafety, constness, abi::Rust, Some(name), + try!(s.print_fn(decl, unsafety, constness, Abi::Rust, Some(name), generics, opt_explicit_self, ast::Inherited)); try!(s.end()); // Close the head box s.end() // Close the outer box @@ -1058,7 +1058,7 @@ impl<'a> State<'a> { 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, ";")); @@ -3086,10 +3086,10 @@ impl<'a> State<'a> { } pub fn print_opt_abi_and_extern_if_nondefault(&mut self, - opt_abi: Option) + opt_abi: Option) -> 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 +3099,7 @@ impl<'a> State<'a> { } pub fn print_extern_opt_abi(&mut self, - opt_abi: Option) -> io::Result<()> { + opt_abi: Option) -> io::Result<()> { match opt_abi { Some(abi) => { try!(self.word_nbsp("extern")); @@ -3112,7 +3112,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 +3123,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())); } diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 054d57e90ea..8b2d9bd9aaf 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -499,7 +499,7 @@ fn mk_main(cx: &mut TestCtxt) -> P { let main = ast::ItemFn(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], diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 153e4eedcf2..1faada13e2f 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -193,7 +193,6 @@ use std::collections::HashSet; use std::vec; use syntax::abi::Abi; -use syntax::abi; use syntax::ast::{EnumDef, Expr, Ident, Generics, VariantData, BinOpKind, self}; use syntax::ast_util; use syntax::attr; @@ -681,7 +680,7 @@ impl<'a> TraitDef<'a> { self, type_ident, generics, - abi::Rust, + Abi::Rust, explicit_self, tys, body) @@ -730,7 +729,7 @@ impl<'a> TraitDef<'a> { self, type_ident, generics, - abi::Rust, + Abi::Rust, explicit_self, tys, body) From 8516ba367d1f51318ce373fe9b60650c82ded1e9 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 8 Feb 2016 15:27:08 +0100 Subject: [PATCH 06/29] [breaking-change] don't glob export ast::CaptureClause variants --- src/librustc_front/lowering.rs | 6 +++--- src/libsyntax/ast.rs | 10 +++++----- src/libsyntax/ext/build.rs | 4 ++-- src/libsyntax/parse/parser.rs | 8 ++++---- src/libsyntax/print/pprust.rs | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index 0f6309cfd52..11bbc14b7b7 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -1555,10 +1555,10 @@ pub fn lower_stmt(lctx: &LoweringContext, s: &Stmt) -> hir::Stmt { } } -pub fn lower_capture_clause(_lctx: &LoweringContext, c: CaptureClause) -> hir::CaptureClause { +pub fn lower_capture_clause(_lctx: &LoweringContext, c: CaptureBy) -> hir::CaptureClause { match c { - CaptureByValue => hir::CaptureByValue, - CaptureByRef => hir::CaptureByRef, + CaptureBy::Value => hir::CaptureByValue, + CaptureBy::Ref => hir::CaptureByRef, } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 994b85a4458..209ed014ea2 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,7 +10,6 @@ // The Rust abstract syntax tree. -pub use self::CaptureClause::*; pub use self::Decl_::*; pub use self::ExplicitSelf_::*; pub use self::Expr_::*; @@ -973,7 +972,7 @@ pub enum Expr_ { /// A `match` block. ExprMatch(P, Vec), /// A closure (for example, `move |a, b, c| {a + b + c}`) - ExprClosure(CaptureClause, P, P), + ExprClosure(CaptureBy, P, P), /// A block (`{ ... }`) ExprBlock(P), @@ -1052,10 +1051,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 diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 6da9a208f37..5980cf3abcc 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -883,14 +883,14 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn lambda_fn_decl(&self, span: Span, fn_decl: P, blk: P) -> P { - self.expr(span, ast::ExprClosure(ast::CaptureByRef, fn_decl, blk)) + self.expr(span, ast::ExprClosure(ast::CaptureBy::Ref, fn_decl, blk)) } fn lambda(&self, span: Span, ids: Vec, blk: P) -> P { 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::ExprClosure(ast::CaptureBy::Ref, fn_decl, blk)) } fn lambda0(&self, span: Span, blk: P) -> P { self.lambda(span, Vec::new(), blk) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index b10c42c4b0e..c149f1f62b0 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -16,7 +16,7 @@ use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; use ast::{Public, Unsafety}; use ast::{Mod, Arg, Arm, Attribute, BindingMode}; use ast::Block; -use ast::{BlockCheckMode, CaptureByRef, CaptureByValue, CaptureClause}; +use ast::{BlockCheckMode, CaptureBy}; use ast::{Constness, ConstTraitItem, Crate, CrateConfig}; use ast::{Decl, DeclItem, DeclLocal}; use ast::{EMPTY_CTXT, EnumDef, ExplicitSelf}; @@ -2108,7 +2108,7 @@ impl<'a> Parser<'a> { }, 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, @@ -2167,7 +2167,7 @@ impl<'a> Parser<'a> { } 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); @@ -3047,7 +3047,7 @@ impl<'a> Parser<'a> { // `|args| expr` pub fn parse_lambda_expr(&mut self, lo: BytePos, - capture_clause: CaptureClause, + capture_clause: CaptureBy, attrs: ThinAttributes) -> PResult<'a, P> { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 9d5bd798ec7..9b8e16bbd38 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2741,11 +2741,11 @@ impl<'a> State<'a> { } } - 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(()), } } From 79fa657abc6b8885ceb4023099b4e0026c5ef28f Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 8 Feb 2016 15:34:47 +0100 Subject: [PATCH 07/29] [breaking-change] don't glob export ast::Decl_ variants --- src/librustc_front/lowering.rs | 4 ++-- src/librustc_lint/unused.rs | 2 +- src/librustc_passes/const_fn.rs | 4 ++-- src/libsyntax/ast.rs | 13 ++++++------- src/libsyntax/attr.rs | 6 +++--- src/libsyntax/config.rs | 2 +- src/libsyntax/ext/build.rs | 6 +++--- src/libsyntax/ext/expand.rs | 6 +++--- src/libsyntax/fold.rs | 8 ++++---- src/libsyntax/parse/classify.rs | 4 ++-- src/libsyntax/parse/parser.rs | 8 ++++---- src/libsyntax/print/pprust.rs | 4 ++-- src/libsyntax/visit.rs | 4 ++-- src/libsyntax_ext/deriving/debug.rs | 2 +- src/libsyntax_ext/format.rs | 2 +- 15 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index 11bbc14b7b7..165982abc05 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -247,11 +247,11 @@ pub fn lower_arm(lctx: &LoweringContext, arm: &Arm) -> hir::Arm { pub fn lower_decl(lctx: &LoweringContext, d: &Decl) -> P { match d.node { - DeclLocal(ref l) => P(Spanned { + DeclKind::Local(ref l) => P(Spanned { node: hir::DeclLocal(lower_local(lctx, l)), span: d.span, }), - DeclItem(ref it) => P(Spanned { + DeclKind::Item(ref it) => P(Spanned { node: hir::DeclItem(lower_item_id(lctx, it)), span: d.span, }), diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 18a3a96069e..628dcb9217a 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -365,7 +365,7 @@ impl EarlyLintPass for UnusedParens { fn check_stmt(&mut self, cx: &EarlyContext, s: &ast::Stmt) { let (value, msg) = match s.node { ast::StmtDecl(ref decl, _) => match decl.node { - ast::DeclLocal(ref local) => match local.init { + ast::DeclKind::Local(ref local) => match local.init { Some(ref value) => (value, "assigned value"), None => return }, diff --git a/src/librustc_passes/const_fn.rs b/src/librustc_passes/const_fn.rs index f924210da9f..6d9c03bc824 100644 --- a/src/librustc_passes/const_fn.rs +++ b/src/librustc_passes/const_fn.rs @@ -59,10 +59,10 @@ fn check_block(sess: &Session, b: &ast::Block, kind: &'static str) { let span = match stmt.node { ast::StmtDecl(ref decl, _) => { match decl.node { - ast::DeclLocal(_) => decl.span, + ast::DeclKind::Local(_) => decl.span, // Item statements are allowed - ast::DeclItem(_) => continue, + ast::DeclKind::Item(_) => continue, } } ast::StmtExpr(ref expr, _) => expr.span, diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 209ed014ea2..9f013ad5ae7 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,7 +10,6 @@ // The Rust abstract syntax tree. -pub use self::Decl_::*; pub use self::ExplicitSelf_::*; pub use self::Expr_::*; pub use self::FloatTy::*; @@ -829,21 +828,21 @@ impl Local { } } -pub type Decl = Spanned; +pub type Decl = Spanned; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum Decl_ { +pub enum DeclKind { /// A local (let) binding: - DeclLocal(P), + Local(P), /// An item binding: - DeclItem(P), + Item(P), } 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(), } } } diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 96d0052cf18..746f728e096 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -16,7 +16,7 @@ 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::{Stmt, StmtDecl, StmtExpr, StmtMac, StmtSemi, DeclKind}; use ast::{Expr, Item, Local, Decl}; use codemap::{Span, Spanned, spanned, dummy_spanned}; use codemap::BytePos; @@ -933,8 +933,8 @@ impl WithAttrs for P { 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)), } } }) diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index 64b16538f05..e849de0b1c6 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -373,7 +373,7 @@ impl<'v, 'a, 'b> visit::Visitor<'v> for StmtExprAttrFeatureVisitor<'a, 'b> { 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::DeclKind::Item(_) = decl.node { visit::walk_stmt(self, s); return; } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 5980cf3abcc..3a69b84ab3c 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -524,7 +524,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { span: sp, attrs: None, }); - let decl = respan(sp, ast::DeclLocal(local)); + let decl = respan(sp, ast::DeclKind::Local(local)); P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID))) } @@ -548,7 +548,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { span: sp, attrs: None, }); - let decl = respan(sp, ast::DeclLocal(local)); + let decl = respan(sp, ast::DeclKind::Local(local)); P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID))) } @@ -558,7 +558,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn stmt_item(&self, sp: Span, item: P) -> P { - let decl = respan(sp, ast::DeclItem(item)); + let decl = respan(sp, ast::DeclKind::Item(item)); P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID))) } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 72537f6c7b2..460d564a70e 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -8,7 +8,7 @@ // 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}; @@ -559,7 +559,7 @@ fn expand_non_macro_stmt(Spanned {node, span: stmt_span}: Stmt, fld: &mut MacroE // is it a let? match node { StmtDecl(decl, node_id) => decl.and_then(|Spanned {node: decl, span}| match decl { - DeclLocal(local) => { + 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 @@ -597,7 +597,7 @@ 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: DeclKind::Local(rewritten_local), span: span }), node_id), diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index dc96e9ecc09..233bcbf4650 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -356,12 +356,12 @@ pub fn noop_fold_arm(Arm {attrs, pats, guard, body}: Arm, fld: &mut T pub fn noop_fold_decl(d: P, fld: &mut T) -> SmallVector> { 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() }) diff --git a/src/libsyntax/parse/classify.rs b/src/libsyntax/parse/classify.rs index ef50b3adad3..82b8730e10f 100644 --- a/src/libsyntax/parse/classify.rs +++ b/src/libsyntax/parse/classify.rs @@ -49,8 +49,8 @@ pub fn stmt_ends_with_semi(stmt: &ast::Stmt_) -> bool { match *stmt { ast::StmtDecl(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), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c149f1f62b0..8bdd9a8f539 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -18,7 +18,7 @@ use ast::{Mod, Arg, Arm, Attribute, BindingMode}; use ast::Block; use ast::{BlockCheckMode, CaptureBy}; use ast::{Constness, ConstTraitItem, Crate, CrateConfig}; -use ast::{Decl, DeclItem, DeclLocal}; +use ast::{Decl, DeclKind}; use ast::{EMPTY_CTXT, EnumDef, ExplicitSelf}; use ast::{Expr, Expr_, ExprAddrOf, ExprMatch, ExprAgain}; use ast::{ExprAssign, ExprAssignOp, ExprBinary, ExprBlock, ExprBox}; @@ -3636,7 +3636,7 @@ impl<'a> Parser<'a> { fn parse_let(&mut self, attrs: ThinAttributes) -> PResult<'a, P> { 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 @@ -3759,7 +3759,7 @@ impl<'a> Parser<'a> { } } spanned(lo, hi, StmtDecl( - P(spanned(lo, hi, DeclItem( + P(spanned(lo, hi, DeclKind::Item( self.mk_item( lo, hi, id /*id is good here*/, ItemMac(spanned(lo, hi, @@ -3772,7 +3772,7 @@ 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))); + let decl = P(spanned(lo, hi, DeclKind::Item(i))); spanned(lo, hi, StmtDecl(decl, ast::DUMMY_NODE_ID)) } None => { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 9b8e16bbd38..421225f279d 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2299,7 +2299,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 +2315,7 @@ impl<'a> State<'a> { } self.end() } - ast::DeclItem(ref item) => self.print_item(&**item) + ast::DeclKind::Item(ref item) => self.print_item(&**item) } } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 834291dd561..d12a5f353e7 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -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), } } diff --git a/src/libsyntax_ext/deriving/debug.rs b/src/libsyntax_ext/deriving/debug.rs index 008067f39a3..3c36ce57d18 100644 --- a/src/libsyntax_ext/deriving/debug.rs +++ b/src/libsyntax_ext/deriving/debug.rs @@ -151,6 +151,6 @@ fn stmt_let_undescore(cx: &mut ExtCtxt, span: sp, attrs: None, }); - let decl = respan(sp, ast::DeclLocal(local)); + let decl = respan(sp, ast::DeclKind::Local(local)); P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID))) } diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index 77bf90abbcc..449be3bc50c 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -457,7 +457,7 @@ impl<'a, 'b> Context<'a, 'b> { let name = ecx.ident_of(name); let item = ecx.item(sp, name, vec![], st); - let decl = respan(sp, ast::DeclItem(item)); + let decl = respan(sp, ast::DeclKind::Item(item)); // Wrap the declaration in a block so that it forms a single expression. ecx.expr_block(ecx.block(sp, From 1c4d43715843a5ff5af4657c798b5d5cc85ca523 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 8 Feb 2016 15:43:56 +0100 Subject: [PATCH 08/29] [breaking-change] don't glob export ast::ExplicitSelf_ variants --- src/librustc_front/lowering.rs | 10 +++---- src/libsyntax/ast.rs | 13 ++++---- src/libsyntax/fold.rs | 20 ++++++------- src/libsyntax/parse/parser.rs | 36 +++++++++++------------ src/libsyntax/print/pprust.rs | 24 +++++++-------- src/libsyntax/visit.rs | 8 ++--- src/libsyntax_ext/deriving/generic/mod.rs | 4 +-- src/libsyntax_ext/deriving/generic/ty.rs | 4 +-- 8 files changed, 59 insertions(+), 60 deletions(-) diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index 165982abc05..de2da35f856 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -408,17 +408,17 @@ pub fn lower_local(lctx: &LoweringContext, l: &Local) -> P { } pub fn lower_explicit_self_underscore(lctx: &LoweringContext, - es: &ExplicitSelf_) + es: &SelfKind) -> hir::ExplicitSelf_ { match *es { - SelfStatic => hir::SelfStatic, - SelfValue(v) => hir::SelfValue(v.name), - SelfRegion(ref lifetime, m, ident) => { + SelfKind::Static => hir::SelfStatic, + SelfKind::Value(v) => hir::SelfValue(v.name), + SelfKind::Region(ref lifetime, m, ident) => { hir::SelfRegion(lower_opt_lifetime(lctx, lifetime), lower_mutability(lctx, m), ident.name) } - SelfExplicit(ref typ, ident) => { + SelfKind::Explicit(ref typ, ident) => { hir::SelfExplicit(lower_ty(lctx, typ), ident.name) } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 9f013ad5ae7..979c8568712 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,7 +10,6 @@ // The Rust abstract syntax tree. -pub use self::ExplicitSelf_::*; pub use self::Expr_::*; pub use self::FloatTy::*; pub use self::ForeignItem_::*; @@ -1747,18 +1746,18 @@ impl FunctionRetTy { /// 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, Mutability, Ident), + Region(Option, Mutability, Ident), /// `self: TYPE` - SelfExplicit(P, Ident), + Explicit(P, Ident), } -pub type ExplicitSelf = Spanned; +pub type ExplicitSelf = Spanned; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Mod { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 233bcbf4650..3332941d0ad 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -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 { @@ -520,15 +520,15 @@ pub fn noop_fold_attribute(at: Attribute, fld: &mut T) -> Option(es: ExplicitSelf_, fld: &mut T) - -> ExplicitSelf_ { +pub fn noop_fold_explicit_self_kind(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(es: ExplicitSelf_, fld: &mu pub fn noop_fold_explicit_self(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) } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8bdd9a8f539..98b1cc21ef8 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -46,7 +46,7 @@ use ast::{PolyTraitRef, QSelf}; use ast::{Stmt, StmtDecl}; use ast::{StmtExpr, StmtSemi, StmtMac, VariantData, StructField}; use ast::StrStyle; -use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue}; +use ast::SelfKind; use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef}; use ast::{Ty, Ty_, TypeBinding, TyMac}; use ast::{TyFixedLengthVec, TyBareFn, TyTypeof, TyInfer}; @@ -4411,7 +4411,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) @@ -4423,26 +4423,26 @@ 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, MutImmutable, 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()))) + Ok(SelfKind::Region(Some(lifetime), MutImmutable, try!(this.expect_self_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) } } @@ -4477,7 +4477,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() { @@ -4486,9 +4486,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)) { @@ -4498,15 +4498,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); @@ -4542,14 +4542,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), }; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 421225f279d..68e9266a2b0 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -382,7 +382,7 @@ 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| { @@ -416,7 +416,7 @@ 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 { +pub fn explicit_self_to_string(explicit_self: &ast::SelfKind) -> String { to_string(|s| s.print_explicit_self(explicit_self, ast::MutImmutable).map(|_| {})) } @@ -2625,21 +2625,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 { 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 +2655,7 @@ impl<'a> State<'a> { abi: abi::Abi, name: Option, 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 +2669,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,7 +2677,7 @@ 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::MutImmutable, _ => match decl.inputs[0].pat.node { ast::PatIdent(ast::BindingMode::ByValue(m), _, _) => m, _ => ast::MutImmutable @@ -2702,7 +2702,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)); @@ -3016,7 +3016,7 @@ impl<'a> State<'a> { decl: &ast::FnDecl, name: Option, 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() { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index d12a5f353e7..e38997931aa 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) } diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 1faada13e2f..3903f6a8085 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -821,7 +821,7 @@ impl<'a> MethodDef<'a> { explicit_self } - None => codemap::respan(trait_.span, ast::SelfStatic), + None => codemap::respan(trait_.span, ast::SelfKind::Static), }; for (i, ty) in self.args.iter().enumerate() { @@ -862,7 +862,7 @@ impl<'a> MethodDef<'a> { let fn_generics = self.generics.to_generics(cx, trait_.span, type_ident, generics); let self_arg = match explicit_self.node { - ast::SelfStatic => None, + ast::SelfKind::Static => None, // creating fresh self id _ => Some(ast::Arg::new_self(trait_.span, ast::MutImmutable, special_idents::self_)) }; diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index 10564b5f698..543beeb5da0 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -264,7 +264,7 @@ pub fn get_explicit_self(cx: &ExtCtxt, span: Span, self_ptr: &Option) let self_path = cx.expr_self(span); match *self_ptr { None => { - (self_path, respan(span, ast::SelfValue(special_idents::self_))) + (self_path, respan(span, ast::SelfKind::Value(special_idents::self_))) } Some(ref ptr) => { let self_ty = respan( @@ -272,7 +272,7 @@ pub fn get_explicit_self(cx: &ExtCtxt, span: Span, self_ptr: &Option) match *ptr { Borrowed(ref lt, mutbl) => { let lt = lt.map(|s| cx.lifetime(span, cx.ident_of(s).name)); - ast::SelfRegion(lt, mutbl, special_idents::self_) + ast::SelfKind::Region(lt, mutbl, special_idents::self_) } Raw(_) => cx.span_bug(span, "attempted to use *self in deriving definition") }); From 80bf9ae18a133571d694aa866b824dcaea875d32 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 8 Feb 2016 16:05:05 +0100 Subject: [PATCH 09/29] [breaking-change] don't glob export ast::Expr_ variants --- src/librustc_driver/pretty.rs | 2 +- src/librustc_front/lowering.rs | 74 +++++------ src/librustc_lint/unused.rs | 45 +++---- src/librustc_passes/const_fn.rs | 2 +- src/librustc_passes/no_asm.rs | 4 +- src/librustc_trans/save/dump_csv.rs | 20 +-- src/librustc_trans/save/mod.rs | 8 +- src/libsyntax/ast.rs | 79 ++++++------ src/libsyntax/ast_util.rs | 2 +- src/libsyntax/config.rs | 4 +- src/libsyntax/ext/base.rs | 6 +- src/libsyntax/ext/build.rs | 52 ++++---- src/libsyntax/ext/expand.rs | 40 +++--- src/libsyntax/ext/quote.rs | 2 +- src/libsyntax/feature_gate.rs | 8 +- src/libsyntax/fold.rs | 126 +++++++++---------- src/libsyntax/parse/classify.rs | 18 +-- src/libsyntax/parse/mod.rs | 14 +-- src/libsyntax/parse/parser.rs | 142 +++++++++++----------- src/libsyntax/print/pprust.rs | 96 +++++++-------- src/libsyntax/ptr.rs | 2 +- src/libsyntax/test.rs | 4 +- src/libsyntax/visit.rs | 66 +++++----- src/libsyntax_ext/asm.rs | 2 +- src/libsyntax_ext/concat.rs | 2 +- src/libsyntax_ext/concat_idents.rs | 2 +- src/libsyntax_ext/deriving/encodable.rs | 16 ++- src/libsyntax_ext/deriving/generic/mod.rs | 8 +- src/libsyntax_ext/format.rs | 2 +- 29 files changed, 420 insertions(+), 428 deletions(-) diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 53438e3fca4..0f6ba63d54b 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -653,7 +653,7 @@ impl fold::Folder for ReplaceBodyWithLoop { let empty_block = expr_to_block(BlockCheckMode::Default, None); let loop_expr = P(ast::Expr { - node: ast::ExprLoop(empty_block, None), + node: ast::ExprKind::Loop(empty_block, None), id: ast::DUMMY_NODE_ID, span: codemap::DUMMY_SP, attrs: None, diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index de2da35f856..fe44ba7a646 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -986,12 +986,12 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { // } // // But for now there are type-inference issues doing that. - ExprBox(ref e) => { + ExprKind::Box(ref e) => { hir::ExprBox(lower_expr(lctx, e)) } // Desugar ExprBox: `in (PLACE) EXPR` - ExprInPlace(ref placer, ref value_expr) => { + ExprKind::InPlace(ref placer, ref value_expr) => { // to: // // let p = PLACE; @@ -1099,57 +1099,57 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { }); } - ExprVec(ref exprs) => { + ExprKind::Vec(ref exprs) => { hir::ExprVec(exprs.iter().map(|x| lower_expr(lctx, x)).collect()) } - ExprRepeat(ref expr, ref count) => { + ExprKind::Repeat(ref expr, ref count) => { let expr = lower_expr(lctx, expr); let count = lower_expr(lctx, count); hir::ExprRepeat(expr, count) } - ExprTup(ref elts) => { + ExprKind::Tup(ref elts) => { hir::ExprTup(elts.iter().map(|x| lower_expr(lctx, x)).collect()) } - ExprCall(ref f, ref args) => { + ExprKind::Call(ref f, ref args) => { let f = lower_expr(lctx, f); hir::ExprCall(f, args.iter().map(|x| lower_expr(lctx, x)).collect()) } - ExprMethodCall(i, ref tps, ref args) => { + ExprKind::MethodCall(i, ref tps, ref args) => { let tps = tps.iter().map(|x| lower_ty(lctx, x)).collect(); let args = args.iter().map(|x| lower_expr(lctx, x)).collect(); hir::ExprMethodCall(respan(i.span, i.node.name), tps, args) } - ExprBinary(binop, ref lhs, ref rhs) => { + ExprKind::Binary(binop, ref lhs, ref rhs) => { let binop = lower_binop(lctx, binop); let lhs = lower_expr(lctx, lhs); let rhs = lower_expr(lctx, rhs); hir::ExprBinary(binop, lhs, rhs) } - ExprUnary(op, ref ohs) => { + ExprKind::Unary(op, ref ohs) => { let op = lower_unop(lctx, op); let ohs = lower_expr(lctx, ohs); hir::ExprUnary(op, ohs) } - ExprLit(ref l) => hir::ExprLit(P((**l).clone())), - ExprCast(ref expr, ref ty) => { + ExprKind::Lit(ref l) => hir::ExprLit(P((**l).clone())), + ExprKind::Cast(ref expr, ref ty) => { let expr = lower_expr(lctx, expr); hir::ExprCast(expr, lower_ty(lctx, ty)) } - ExprType(ref expr, ref ty) => { + ExprKind::Type(ref expr, ref ty) => { let expr = lower_expr(lctx, expr); hir::ExprType(expr, lower_ty(lctx, ty)) } - ExprAddrOf(m, ref ohs) => { + ExprKind::AddrOf(m, ref ohs) => { let m = lower_mutability(lctx, m); let ohs = lower_expr(lctx, ohs); hir::ExprAddrOf(m, ohs) } // More complicated than you might expect because the else branch // might be `if let`. - ExprIf(ref cond, ref blk, ref else_opt) => { + ExprKind::If(ref cond, ref blk, ref else_opt) => { let else_opt = else_opt.as_ref().map(|els| { match els.node { - ExprIfLet(..) => { + ExprKind::IfLet(..) => { cache_ids(lctx, e.id, |lctx| { // wrap the if-let expr in a block let span = els.span; @@ -1171,47 +1171,47 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { hir::ExprIf(lower_expr(lctx, cond), lower_block(lctx, blk), else_opt) } - ExprWhile(ref cond, ref body, opt_ident) => { + ExprKind::While(ref cond, ref body, opt_ident) => { hir::ExprWhile(lower_expr(lctx, cond), lower_block(lctx, body), opt_ident.map(|ident| lower_ident(lctx, ident))) } - ExprLoop(ref body, opt_ident) => { + ExprKind::Loop(ref body, opt_ident) => { hir::ExprLoop(lower_block(lctx, body), opt_ident.map(|ident| lower_ident(lctx, ident))) } - ExprMatch(ref expr, ref arms) => { + ExprKind::Match(ref expr, ref arms) => { hir::ExprMatch(lower_expr(lctx, expr), arms.iter().map(|x| lower_arm(lctx, x)).collect(), hir::MatchSource::Normal) } - ExprClosure(capture_clause, ref decl, ref body) => { + ExprKind::Closure(capture_clause, ref decl, ref body) => { hir::ExprClosure(lower_capture_clause(lctx, capture_clause), lower_fn_decl(lctx, decl), lower_block(lctx, body)) } - ExprBlock(ref blk) => hir::ExprBlock(lower_block(lctx, blk)), - ExprAssign(ref el, ref er) => { + ExprKind::Block(ref blk) => hir::ExprBlock(lower_block(lctx, blk)), + ExprKind::Assign(ref el, ref er) => { hir::ExprAssign(lower_expr(lctx, el), lower_expr(lctx, er)) } - ExprAssignOp(op, ref el, ref er) => { + ExprKind::AssignOp(op, ref el, ref er) => { hir::ExprAssignOp(lower_binop(lctx, op), lower_expr(lctx, el), lower_expr(lctx, er)) } - ExprField(ref el, ident) => { + ExprKind::Field(ref el, ident) => { hir::ExprField(lower_expr(lctx, el), respan(ident.span, ident.node.name)) } - ExprTupField(ref el, ident) => { + ExprKind::TupField(ref el, ident) => { hir::ExprTupField(lower_expr(lctx, el), ident) } - ExprIndex(ref el, ref er) => { + ExprKind::Index(ref el, ref er) => { hir::ExprIndex(lower_expr(lctx, el), lower_expr(lctx, er)) } - ExprRange(ref e1, ref e2) => { + ExprKind::Range(ref e1, ref e2) => { hir::ExprRange(e1.as_ref().map(|x| lower_expr(lctx, x)), e2.as_ref().map(|x| lower_expr(lctx, x))) } - ExprPath(ref qself, ref path) => { + ExprKind::Path(ref qself, ref path) => { let hir_qself = qself.as_ref().map(|&QSelf { ref ty, position }| { hir::QSelf { ty: lower_ty(lctx, ty), @@ -1220,14 +1220,14 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { }); hir::ExprPath(hir_qself, lower_path_full(lctx, path, qself.is_none())) } - ExprBreak(opt_ident) => hir::ExprBreak(opt_ident.map(|sp_ident| { + ExprKind::Break(opt_ident) => hir::ExprBreak(opt_ident.map(|sp_ident| { respan(sp_ident.span, lower_ident(lctx, sp_ident.node)) })), - ExprAgain(opt_ident) => hir::ExprAgain(opt_ident.map(|sp_ident| { + ExprKind::Again(opt_ident) => hir::ExprAgain(opt_ident.map(|sp_ident| { respan(sp_ident.span, lower_ident(lctx, sp_ident.node)) })), - ExprRet(ref e) => hir::ExprRet(e.as_ref().map(|x| lower_expr(lctx, x))), - ExprInlineAsm(InlineAsm { + ExprKind::Ret(ref e) => hir::ExprRet(e.as_ref().map(|x| lower_expr(lctx, x))), + ExprKind::InlineAsm(InlineAsm { ref inputs, ref outputs, ref asm, @@ -1259,12 +1259,12 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { dialect: dialect, expn_id: expn_id, }), - ExprStruct(ref path, ref fields, ref maybe_expr) => { + ExprKind::Struct(ref path, ref fields, ref maybe_expr) => { hir::ExprStruct(lower_path(lctx, path), fields.iter().map(|x| lower_field(lctx, x)).collect(), maybe_expr.as_ref().map(|x| lower_expr(lctx, x))) } - ExprParen(ref ex) => { + ExprKind::Paren(ref ex) => { // merge attributes into the inner expression. return lower_expr(lctx, ex).map(|mut ex| { ex.attrs.update(|attrs| { @@ -1276,7 +1276,7 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { // Desugar ExprIfLet // From: `if let = []` - ExprIfLet(ref pat, ref sub_expr, ref body, ref else_opt) => { + ExprKind::IfLet(ref pat, ref sub_expr, ref body, ref else_opt) => { // to: // // match { @@ -1364,7 +1364,7 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { // Desugar ExprWhileLet // From: `[opt_ident]: while let = ` - ExprWhileLet(ref pat, ref sub_expr, ref body, opt_ident) => { + ExprKind::WhileLet(ref pat, ref sub_expr, ref body, opt_ident) => { // to: // // [opt_ident]: loop { @@ -1410,7 +1410,7 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { // Desugar ExprForLoop // From: `[opt_ident]: for in ` - ExprForLoop(ref pat, ref head, ref body, opt_ident) => { + ExprKind::ForLoop(ref pat, ref head, ref body, opt_ident) => { // to: // // { @@ -1524,7 +1524,7 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { }); } - ExprMac(_) => panic!("Shouldn't exist here"), + ExprKind::Mac(_) => panic!("Shouldn't exist here"), }, span: e.span, attrs: e.attrs.clone(), diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 628dcb9217a..bbd714fad06 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -293,7 +293,7 @@ pub struct UnusedParens; impl UnusedParens { fn check_unused_parens_core(&self, cx: &EarlyContext, value: &ast::Expr, msg: &str, struct_lit_needs_parens: bool) { - if let ast::ExprParen(ref inner) = value.node { + if let ast::ExprKind::Paren(ref inner) = value.node { let necessary = struct_lit_needs_parens && contains_exterior_struct_lit(&**inner); if !necessary { cx.span_lint(UNUSED_PARENS, value.span, @@ -308,26 +308,26 @@ impl UnusedParens { /// y: 1 }) == foo` does not. fn contains_exterior_struct_lit(value: &ast::Expr) -> bool { match value.node { - ast::ExprStruct(..) => true, + ast::ExprKind::Struct(..) => true, - ast::ExprAssign(ref lhs, ref rhs) | - ast::ExprAssignOp(_, ref lhs, ref rhs) | - ast::ExprBinary(_, ref lhs, ref rhs) => { + ast::ExprKind::Assign(ref lhs, ref rhs) | + ast::ExprKind::AssignOp(_, ref lhs, ref rhs) | + ast::ExprKind::Binary(_, ref lhs, ref rhs) => { // X { y: 1 } + X { y: 2 } contains_exterior_struct_lit(&**lhs) || contains_exterior_struct_lit(&**rhs) } - ast::ExprUnary(_, ref x) | - ast::ExprCast(ref x, _) | - ast::ExprType(ref x, _) | - ast::ExprField(ref x, _) | - ast::ExprTupField(ref x, _) | - ast::ExprIndex(ref x, _) => { + ast::ExprKind::Unary(_, ref x) | + ast::ExprKind::Cast(ref x, _) | + ast::ExprKind::Type(ref x, _) | + ast::ExprKind::Field(ref x, _) | + ast::ExprKind::TupField(ref x, _) | + ast::ExprKind::Index(ref x, _) => { // &X { y: 1 }, X { y: 1 }.y contains_exterior_struct_lit(&**x) } - ast::ExprMethodCall(_, _, ref exprs) => { + ast::ExprKind::MethodCall(_, _, ref exprs) => { // X { y: 1 }.bar(...) contains_exterior_struct_lit(&*exprs[0]) } @@ -346,17 +346,18 @@ impl LintPass for UnusedParens { impl EarlyLintPass for UnusedParens { fn check_expr(&mut self, cx: &EarlyContext, e: &ast::Expr) { + use syntax::ast::ExprKind::*; let (value, msg, struct_lit_needs_parens) = match e.node { - ast::ExprIf(ref cond, _, _) => (cond, "`if` condition", true), - ast::ExprWhile(ref cond, _, _) => (cond, "`while` condition", true), - ast::ExprIfLet(_, ref cond, _, _) => (cond, "`if let` head expression", true), - ast::ExprWhileLet(_, ref cond, _, _) => (cond, "`while let` head expression", true), - ast::ExprForLoop(_, ref cond, _, _) => (cond, "`for` head expression", true), - ast::ExprMatch(ref head, _) => (head, "`match` head expression", true), - ast::ExprRet(Some(ref value)) => (value, "`return` value", false), - ast::ExprAssign(_, ref value) => (value, "assigned value", false), - ast::ExprAssignOp(_, _, ref value) => (value, "assigned value", false), - ast::ExprInPlace(_, ref value) => (value, "emplacement value", false), + If(ref cond, _, _) => (cond, "`if` condition", true), + While(ref cond, _, _) => (cond, "`while` condition", true), + IfLet(_, ref cond, _, _) => (cond, "`if let` head expression", true), + WhileLet(_, ref cond, _, _) => (cond, "`while let` head expression", true), + ForLoop(_, ref cond, _, _) => (cond, "`for` head expression", true), + Match(ref head, _) => (head, "`match` head expression", true), + Ret(Some(ref value)) => (value, "`return` value", false), + Assign(_, ref value) => (value, "assigned value", false), + AssignOp(_, _, ref value) => (value, "assigned value", false), + InPlace(_, ref value) => (value, "emplacement value", false), _ => return }; self.check_unused_parens_core(cx, &**value, msg, struct_lit_needs_parens); diff --git a/src/librustc_passes/const_fn.rs b/src/librustc_passes/const_fn.rs index 6d9c03bc824..5ec00439df2 100644 --- a/src/librustc_passes/const_fn.rs +++ b/src/librustc_passes/const_fn.rs @@ -38,7 +38,7 @@ impl<'a, 'v> Visitor<'v> for CheckBlock<'a> { CheckConstFn{ sess: self.sess}.visit_block(block); } fn visit_expr(&mut self, e: &'v ast::Expr) { - if let ast::ExprClosure(..) = e.node { + if let ast::ExprKind::Closure(..) = e.node { CheckConstFn{ sess: self.sess}.visit_expr(e); } else { visit::walk_expr(self, e); diff --git a/src/librustc_passes/no_asm.rs b/src/librustc_passes/no_asm.rs index 3022d9fb9e3..90f92c25b05 100644 --- a/src/librustc_passes/no_asm.rs +++ b/src/librustc_passes/no_asm.rs @@ -32,8 +32,8 @@ struct CheckNoAsm<'a> { impl<'a, 'v> Visitor<'v> for CheckNoAsm<'a> { fn visit_expr(&mut self, e: &ast::Expr) { match e.node { - ast::ExprInlineAsm(_) => span_err!(self.sess, e.span, E0472, - "asm! is unsupported on this target"), + ast::ExprKind::InlineAsm(_) => span_err!(self.sess, e.span, E0472, + "asm! is unsupported on this target"), _ => {}, } visit::walk_expr(self, e) diff --git a/src/librustc_trans/save/dump_csv.rs b/src/librustc_trans/save/dump_csv.rs index 9714e4f02b1..e8a0e4a8d42 100644 --- a/src/librustc_trans/save/dump_csv.rs +++ b/src/librustc_trans/save/dump_csv.rs @@ -1083,23 +1083,23 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> { fn visit_expr(&mut self, ex: &ast::Expr) { self.process_macro_use(ex.span, ex.id); match ex.node { - ast::ExprCall(ref _f, ref _args) => { + ast::ExprKind::Call(ref _f, ref _args) => { // Don't need to do anything for function calls, // because just walking the callee path does what we want. visit::walk_expr(self, ex); } - ast::ExprPath(_, ref path) => { + ast::ExprKind::Path(_, ref path) => { self.process_path(ex.id, path, None); visit::walk_expr(self, ex); } - ast::ExprStruct(ref path, ref fields, ref base) => { + ast::ExprKind::Struct(ref path, ref fields, ref base) => { let hir_expr = lower_expr(self.save_ctxt.lcx, ex); let adt = self.tcx.expr_ty(&hir_expr).ty_adt_def().unwrap(); let def = self.tcx.resolve_expr(&hir_expr); self.process_struct_lit(ex, path, fields, adt.variant_of_def(def), base) } - ast::ExprMethodCall(_, _, ref args) => self.process_method_call(ex, args), - ast::ExprField(ref sub_ex, _) => { + ast::ExprKind::MethodCall(_, _, ref args) => self.process_method_call(ex, args), + ast::ExprKind::Field(ref sub_ex, _) => { self.visit_expr(&sub_ex); if let Some(field_data) = self.save_ctxt.get_expr_data(ex) { @@ -1111,7 +1111,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> { field_data.scope); } } - ast::ExprTupField(ref sub_ex, idx) => { + ast::ExprKind::TupField(ref sub_ex, idx) => { self.visit_expr(&**sub_ex); let hir_node = lower_expr(self.save_ctxt.lcx, sub_ex); @@ -1131,7 +1131,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> { ty)), } } - ast::ExprClosure(_, ref decl, ref body) => { + ast::ExprKind::Closure(_, ref decl, ref body) => { let mut id = String::from("$"); id.push_str(&ex.id.to_string()); self.process_formals(&decl.inputs, &id); @@ -1148,14 +1148,14 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> { // walk the body self.nest(ex.id, |v| v.visit_block(&**body)); } - ast::ExprForLoop(ref pattern, ref subexpression, ref block, _) | - ast::ExprWhileLet(ref pattern, ref subexpression, ref block, _) => { + ast::ExprKind::ForLoop(ref pattern, ref subexpression, ref block, _) | + ast::ExprKind::WhileLet(ref pattern, ref subexpression, ref block, _) => { let value = self.span.snippet(mk_sp(ex.span.lo, subexpression.span.hi)); self.process_var_decl(pattern, value); visit::walk_expr(self, subexpression); visit::walk_block(self, block); } - ast::ExprIfLet(ref pattern, ref subexpression, ref block, ref opt_else) => { + ast::ExprKind::IfLet(ref pattern, ref subexpression, ref block, ref opt_else) => { let value = self.span.snippet(mk_sp(ex.span.lo, subexpression.span.hi)); self.process_var_decl(pattern, value); visit::walk_expr(self, subexpression); diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs index 11c82d30246..116051f6fe5 100644 --- a/src/librustc_trans/save/mod.rs +++ b/src/librustc_trans/save/mod.rs @@ -487,7 +487,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { return None; } match expr.node { - ast::ExprField(ref sub_ex, ident) => { + ast::ExprKind::Field(ref sub_ex, ident) => { let hir_node = lowering::lower_expr(self.lcx, sub_ex); match self.tcx.expr_ty_adjusted(&hir_node).sty { ty::TyStruct(def, _) => { @@ -507,7 +507,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { } } } - ast::ExprStruct(ref path, _, _) => { + ast::ExprKind::Struct(ref path, _, _) => { let hir_node = lowering::lower_expr(self.lcx, expr); match self.tcx.expr_ty_adjusted(&hir_node).sty { ty::TyStruct(def, _) => { @@ -527,7 +527,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { } } } - ast::ExprMethodCall(..) => { + ast::ExprKind::MethodCall(..) => { let method_call = ty::MethodCall::expr(expr.id); let method_id = self.tcx.tables.borrow().method_map[&method_call].def_id; let (def_id, decl_id) = match self.tcx.impl_or_trait_item(method_id).container() { @@ -544,7 +544,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { decl_id: decl_id, })) } - ast::ExprPath(_, ref path) => { + ast::ExprKind::Path(_, ref path) => { self.get_path_data(expr.id, path) } _ => { diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 979c8568712..36543bd35ca 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,7 +10,6 @@ // The Rust abstract syntax tree. -pub use self::Expr_::*; pub use self::FloatTy::*; pub use self::ForeignItem_::*; pub use self::IntTy::*; @@ -880,7 +879,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 } @@ -901,18 +900,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), + Box(P), /// First expr is the place; second expr is the value. - ExprInPlace(P, P), + InPlace(P, P), /// An array (`[a, b, c, d]`) - ExprVec(Vec>), + Vec(Vec>), /// A function call /// /// The first field resolves to the function itself, /// and the second field is the list of arguments - ExprCall(P, Vec>), + Call(P, Vec>), /// A method call (`x.foo::(a, b, c, d)`) /// /// The `SpannedIdent` is the identifier for the method name. @@ -924,109 +923,109 @@ pub enum Expr_ { /// and the remaining elements are the rest of the arguments. /// /// Thus, `x.foo::(a, b, c, d)` is represented as - /// `ExprMethodCall(foo, [Bar, Baz], [x, a, b, c, d])`. - ExprMethodCall(SpannedIdent, Vec>, Vec>), + /// `ExprKind::MethodCall(foo, [Bar, Baz], [x, a, b, c, d])`. + MethodCall(SpannedIdent, Vec>, Vec>), /// A tuple (`(a, b, c ,d)`) - ExprTup(Vec>), + Tup(Vec>), /// A binary operation (For example: `a + b`, `a * b`) - ExprBinary(BinOp, P, P), + Binary(BinOp, P, P), /// A unary operation (For example: `!x`, `*x`) - ExprUnary(UnOp, P), + Unary(UnOp, P), /// A literal (For example: `1u8`, `"foo"`) - ExprLit(P), + Lit(P), /// A cast (`foo as f64`) - ExprCast(P, P), - ExprType(P, P), + Cast(P, P), + Type(P, P), /// An `if` block, with an optional else block /// /// `if expr { block } else { expr }` - ExprIf(P, P, Option>), + If(P, P, Option>), /// 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, P, P, Option>), + IfLet(P, P, P, Option>), /// A while loop, with an optional label /// /// `'label: while expr { block }` - ExprWhile(P, P, Option), + While(P, P, Option), /// 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, P, P, Option), + WhileLet(P, P, P, Option), /// 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, P, P, Option), + ForLoop(P, P, P, Option), /// Conditionless loop (can be exited with break, continue, or return) /// /// `'label: loop { block }` - ExprLoop(P, Option), + Loop(P, Option), /// A `match` block. - ExprMatch(P, Vec), + Match(P, Vec), /// A closure (for example, `move |a, b, c| {a + b + c}`) - ExprClosure(CaptureBy, P, P), + Closure(CaptureBy, P, P), /// A block (`{ ... }`) - ExprBlock(P), + Block(P), /// An assignment (`a = foo()`) - ExprAssign(P, P), + Assign(P, P), /// An assignment with an operator /// /// For example, `a += 1`. - ExprAssignOp(BinOp, P, P), + AssignOp(BinOp, P, P), /// Access of a named struct field (`obj.foo`) - ExprField(P, SpannedIdent), + Field(P, SpannedIdent), /// Access of an unnamed field of a struct or tuple-struct /// /// For example, `foo.0`. - ExprTupField(P, Spanned), + TupField(P, Spanned), /// An indexing operation (`foo[2]`) - ExprIndex(P, P), + Index(P, P), /// A range (`1..2`, `1..`, or `..2`) - ExprRange(Option>, Option>), + Range(Option>, Option>), /// Variable reference, possibly containing `::` and/or type /// parameters, e.g. foo::bar::. /// /// Optionally "qualified", /// e.g. ` as SomeTrait>::SomeType`. - ExprPath(Option, Path), + Path(Option, Path), /// A referencing operation (`&a` or `&mut a`) - ExprAddrOf(Mutability, P), + AddrOf(Mutability, P), /// A `break`, with an optional label to break - ExprBreak(Option), + Break(Option), /// A `continue`, with an optional label - ExprAgain(Option), + Again(Option), /// A `return`, with an optional value to be returned - ExprRet(Option>), + Ret(Option>), /// 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`. - ExprStruct(Path, Vec, Option>), + Struct(Path, Vec, Option>), /// 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, P), + Repeat(P, P), /// No-op: used solely so we can pretty-print faithfully - ExprParen(P) + Paren(P), } /// The explicit Self type in a "qualified path". The actual diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 03dc25e1b3c..8ccff527b88 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) -> bool { - match e.node { ExprPath(..) => true, _ => false } + match e.node { ExprKind::Path(..) => true, _ => false } } diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index e849de0b1c6..8d74990fc32 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -212,8 +212,8 @@ fn fold_expr(cx: &mut Context, expr: P) -> P 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()) } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 107626c54cc..33414a697a7 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -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 { 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::LitBool(false)))), span: sp, attrs: None, }) @@ -773,7 +773,7 @@ pub fn expr_to_string(cx: &mut ExtCtxt, expr: P, 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::ExprKind::Lit(ref l) => match l.node { ast::LitStr(ref s, style) => return Some(((*s).clone(), style)), _ => cx.span_err(l.span, err_msg) }, diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 3a69b84ab3c..446c90f310d 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -108,7 +108,7 @@ pub trait AstBuilder { expr: Option>) -> P; // expressions - fn expr(&self, span: Span, node: ast::Expr_) -> P; + fn expr(&self, span: Span, node: ast::ExprKind) -> P; fn expr_path(&self, path: ast::Path) -> P; fn expr_qpath(&self, span: Span, qself: ast::QSelf, path: ast::Path) -> P; fn expr_ident(&self, span: Span, id: ast::Ident) -> P; @@ -578,7 +578,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { }) } - fn expr(&self, span: Span, node: ast::Expr_) -> P { + fn expr(&self, span: Span, node: ast::ExprKind) -> P { P(ast::Expr { id: ast::DUMMY_NODE_ID, node: node, @@ -588,12 +588,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn expr_path(&self, path: ast::Path) -> P { - 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 { - 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 { @@ -605,14 +605,14 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn expr_binary(&self, sp: Span, op: ast::BinOpKind, lhs: P, rhs: P) -> P { - 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) -> P { self.expr_unary(sp, UnOp::Deref, e) } fn expr_unary(&self, sp: Span, op: ast::UnOp, e: P) -> P { - self.expr(sp, ast::ExprUnary(op, e)) + self.expr(sp, ast::ExprKind::Unary(op, e)) } fn expr_field_access(&self, sp: Span, expr: P, ident: ast::Ident) -> P { @@ -623,7 +623,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, idx: usize) -> P { let field_span = Span { @@ -633,21 +633,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) -> P { - self.expr(sp, ast::ExprAddrOf(ast::MutImmutable, e)) + self.expr(sp, ast::ExprKind::AddrOf(ast::MutImmutable, e)) } fn expr_mut_addr_of(&self, sp: Span, e: P) -> P { - self.expr(sp, ast::ExprAddrOf(ast::MutMutable, e)) + self.expr(sp, ast::ExprKind::AddrOf(ast::MutMutable, e)) } fn expr_call(&self, span: Span, expr: P, args: Vec>) -> P { - 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 { - 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 , args: Vec> ) -> P { @@ -660,16 +660,16 @@ impl<'a> AstBuilder for ExtCtxt<'a> { mut args: Vec> ) -> P { 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) -> P { - 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::Field { ast::Field { ident: respan(span, name), expr: e, span: span } } fn expr_struct(&self, span: Span, path: ast::Path, fields: Vec) -> P { - 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) -> P { @@ -677,7 +677,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn expr_lit(&self, sp: Span, lit: ast::Lit_) -> P { - self.expr(sp, ast::ExprLit(P(respan(sp, lit)))) + self.expr(sp, ast::ExprKind::Lit(P(respan(sp, lit)))) } fn expr_usize(&self, span: Span, i: usize) -> P { self.expr_lit(span, ast::LitInt(i as u64, ast::UnsignedIntLit(ast::TyUs))) @@ -697,7 +697,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn expr_vec(&self, sp: Span, exprs: Vec>) -> P { - self.expr(sp, ast::ExprVec(exprs)) + self.expr(sp, ast::ExprKind::Vec(exprs)) } fn expr_vec_ng(&self, sp: Span) -> P { self.expr_call_global(sp, self.std_path(&["vec", "Vec", "new"]), @@ -711,7 +711,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn expr_cast(&self, sp: Span, expr: P, ty: P) -> P { - self.expr(sp, ast::ExprCast(expr, ty)) + self.expr(sp, ast::ExprKind::Cast(expr, ty)) } @@ -728,12 +728,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn expr_break(&self, sp: Span) -> P { - self.expr(sp, ast::ExprBreak(None)) + self.expr(sp, ast::ExprKind::Break(None)) } fn expr_tuple(&self, sp: Span, exprs: Vec>) -> P { - self.expr(sp, ast::ExprTup(exprs)) + self.expr(sp, ast::ExprKind::Tup(exprs)) } fn expr_fail(&self, span: Span, msg: InternedString) -> P { @@ -785,7 +785,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); @@ -868,29 +868,29 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn expr_match(&self, span: Span, arg: P, arms: Vec) -> P { - self.expr(span, ast::ExprMatch(arg, arms)) + self.expr(span, ast::ExprKind::Match(arg, arms)) } fn expr_if(&self, span: Span, cond: P, then: P, els: Option>) -> P { 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) -> P { - 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, blk: P) -> P { - self.expr(span, ast::ExprClosure(ast::CaptureBy::Ref, fn_decl, blk)) + self.expr(span, ast::ExprKind::Closure(ast::CaptureBy::Ref, fn_decl, blk)) } fn lambda(&self, span: Span, ids: Vec, blk: P) -> P { 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::CaptureBy::Ref, fn_decl, blk)) + self.expr(span, ast::ExprKind::Closure(ast::CaptureBy::Ref, fn_decl, blk)) } fn lambda0(&self, span: Span, blk: P) -> P { self.lambda(span, Vec::new(), blk) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 460d564a70e..69b932aa72b 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -42,7 +42,7 @@ pub fn expand_expr(e: P, fld: &mut MacroExpander) -> P { // 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 +69,7 @@ pub fn expand_expr(e: P, fld: &mut MacroExpander) -> P { }) } - 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 +78,18 @@ pub fn expand_expr(e: P, fld: &mut MacroExpander) -> P { 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 +103,17 @@ pub fn expand_expr(e: P, fld: &mut MacroExpander) -> P { }); 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 +127,11 @@ pub fn expand_expr(e: P, fld: &mut MacroExpander) -> P { 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 +146,14 @@ pub fn expand_expr(e: P, fld: &mut MacroExpander) -> P { 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), @@ -1427,7 +1427,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 +1694,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..d7a47b40506 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -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) diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 55087c25703..17eb43e2068 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); } @@ -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"); } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 3332941d0ad..8cd2d24102f 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -1168,131 +1168,131 @@ pub fn noop_fold_expr(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(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(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)), diff --git a/src/libsyntax/parse/classify.rs b/src/libsyntax/parse/classify.rs index 82b8730e10f..325fe64203c 100644 --- a/src/libsyntax/parse/classify.rs +++ b/src/libsyntax/parse/classify.rs @@ -23,21 +23,21 @@ use ast::{self, BlockCheckMode}; /// 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 == BlockCheckMode::Default, + ast::ExprKind::Block(ref block) => block.rules == BlockCheckMode::Default, _ => false, } } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index a47ca51a98a..9ad5dafbf8b 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -703,7 +703,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 +722,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 +852,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!( @@ -877,7 +877,7 @@ mod tests { Some(P(Spanned{ node: ast::StmtExpr(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!( @@ -968,7 +968,7 @@ mod tests { stmts: vec!(P(Spanned{ node: ast::StmtSemi(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, @@ -1110,7 +1110,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 98b1cc21ef8..df73e8815ed 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -20,14 +20,8 @@ use ast::{BlockCheckMode, CaptureBy}; use ast::{Constness, ConstTraitItem, Crate, CrateConfig}; use ast::{Decl, DeclKind}; use ast::{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::{Expr, ExprKind}; +use ast::{Field, FnDecl}; use ast::{ForeignItem, ForeignItemStatic, ForeignItemFn, FunctionRetTy}; use ast::{Ident, Inherited, ImplItem, Item, Item_, ItemStatic}; use ast::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl, ItemConst}; @@ -140,7 +134,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, @@ -150,7 +144,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 }; @@ -508,7 +502,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() @@ -1529,7 +1523,7 @@ impl<'a> Parser<'a> { 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); } } } @@ -1605,7 +1599,7 @@ 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; @@ -1957,7 +1951,7 @@ impl<'a> Parser<'a> { } pub fn mk_expr(&mut self, lo: BytePos, hi: BytePos, - node: Expr_, attrs: ThinAttributes) -> P { + node: ExprKind, attrs: ThinAttributes) -> P { P(Expr { id: ast::DUMMY_NODE_ID, node: node, @@ -1966,55 +1960,55 @@ impl<'a> Parser<'a> { }) } - pub fn mk_unary(&mut self, unop: ast::UnOp, expr: P) -> ast::Expr_ { - ExprUnary(unop, expr) + pub fn mk_unary(&mut self, unop: ast::UnOp, expr: P) -> ast::ExprKind { + ExprKind::Unary(unop, expr) } - pub fn mk_binary(&mut self, binop: ast::BinOp, lhs: P, rhs: P) -> ast::Expr_ { - ExprBinary(binop, lhs, rhs) + pub fn mk_binary(&mut self, binop: ast::BinOp, lhs: P, rhs: P) -> ast::ExprKind { + ExprKind::Binary(binop, lhs, rhs) } - pub fn mk_call(&mut self, f: P, args: Vec>) -> ast::Expr_ { - ExprCall(f, args) + pub fn mk_call(&mut self, f: P, args: Vec>) -> ast::ExprKind { + ExprKind::Call(f, args) } fn mk_method_call(&mut self, ident: ast::SpannedIdent, tps: Vec>, args: Vec>) - -> ast::Expr_ { - ExprMethodCall(ident, tps, args) + -> ast::ExprKind { + ExprKind::MethodCall(ident, tps, args) } - pub fn mk_index(&mut self, expr: P, idx: P) -> ast::Expr_ { - ExprIndex(expr, idx) + pub fn mk_index(&mut self, expr: P, idx: P) -> ast::ExprKind { + ExprKind::Index(expr, idx) } pub fn mk_range(&mut self, start: Option>, end: Option>) - -> ast::Expr_ { - ExprRange(start, end) + -> ast::ExprKind { + ExprKind::Range(start, end) } - pub fn mk_field(&mut self, expr: P, ident: ast::SpannedIdent) -> ast::Expr_ { - ExprField(expr, ident) + pub fn mk_field(&mut self, expr: P, ident: ast::SpannedIdent) -> ast::ExprKind { + ExprKind::Field(expr, ident) } - pub fn mk_tup_field(&mut self, expr: P, idx: codemap::Spanned) -> ast::Expr_ { - ExprTupField(expr, idx) + pub fn mk_tup_field(&mut self, expr: P, idx: codemap::Spanned) -> ast::ExprKind { + ExprKind::TupField(expr, idx) } pub fn mk_assign_op(&mut self, binop: ast::BinOp, - lhs: P, rhs: P) -> ast::Expr_ { - ExprAssignOp(binop, lhs, rhs) + lhs: P, rhs: P) -> ast::ExprKind { + ExprKind::AssignOp(binop, lhs, rhs) } pub fn mk_mac_expr(&mut self, lo: BytePos, hi: BytePos, m: Mac_, attrs: ThinAttributes) -> P { 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, }) @@ -2029,7 +2023,7 @@ impl<'a> Parser<'a> { P(Expr { id: ast::DUMMY_NODE_ID, - node: ExprLit(lv_lit), + node: ExprKind::Lit(lv_lit), span: *span, attrs: attrs, }) @@ -2066,7 +2060,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 { @@ -2098,9 +2092,9 @@ 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) => { @@ -2116,7 +2110,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) => { @@ -2129,7 +2123,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()); @@ -2138,7 +2132,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(); @@ -2149,11 +2143,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; @@ -2163,7 +2157,7 @@ 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; @@ -2202,14 +2196,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)); @@ -2227,19 +2221,19 @@ impl<'a> Parser<'a> { 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) { @@ -2302,18 +2296,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)); } } } @@ -2343,7 +2337,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 @@ -2370,7 +2364,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; @@ -2763,7 +2757,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(); @@ -2774,16 +2768,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)) }; @@ -2850,12 +2844,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 @@ -2921,9 +2915,9 @@ 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 => BinOpKind::Add, @@ -2957,7 +2951,7 @@ 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, @@ -3024,7 +3018,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) @@ -3042,7 +3036,7 @@ 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` @@ -3075,7 +3069,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 @@ -3084,7 +3078,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)); } } @@ -3103,7 +3097,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)) } @@ -3118,7 +3112,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)); } @@ -3133,7 +3127,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 @@ -3143,7 +3137,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 @@ -3167,7 +3161,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> { @@ -3407,7 +3401,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() } @@ -3509,7 +3503,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); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 68e9266a2b0..736af70091a 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -441,10 +441,10 @@ pub fn visibility_qualified(vis: ast::Visibility, s: &str) -> 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, } } @@ -1713,7 +1713,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 +1723,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 +1736,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 +1803,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 +1985,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 +2032,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 +2053,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 +2066,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 +2079,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 +2088,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,7 +2101,7 @@ 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)); @@ -2118,7 +2118,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 +2135,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 +2180,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 +2194,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 +2202,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 +2212,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)); @@ -2275,8 +2275,8 @@ impl<'a> State<'a> { 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)); @@ -2605,7 +2605,7 @@ 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)); 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/test.rs b/src/libsyntax/test.rs index 8b2d9bd9aaf..dbdc1bfcbaa 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -613,10 +613,10 @@ fn mk_test_descs(cx: &TestCtxt) -> P { P(ast::Expr { id: ast::DUMMY_NODE_ID, - node: ast::ExprAddrOf(ast::MutImmutable, + node: ast::ExprKind::AddrOf(ast::MutImmutable, 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/visit.rs b/src/libsyntax/visit.rs index e38997931aa..90cc403961e 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -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) } diff --git a/src/libsyntax_ext/asm.rs b/src/libsyntax_ext/asm.rs index 2f50f610d2b..b9ba1f107ad 100644 --- a/src/libsyntax_ext/asm.rs +++ b/src/libsyntax_ext/asm.rs @@ -247,7 +247,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) MacEager::expr(P(ast::Expr { id: ast::DUMMY_NODE_ID, - node: ast::ExprInlineAsm(ast::InlineAsm { + node: ast::ExprKind::InlineAsm(ast::InlineAsm { asm: token::intern_and_get_ident(&asm), asm_str_style: asm_str_style.unwrap(), outputs: outputs, diff --git a/src/libsyntax_ext/concat.rs b/src/libsyntax_ext/concat.rs index de913fe0431..f5c2805c4ca 100644 --- a/src/libsyntax_ext/concat.rs +++ b/src/libsyntax_ext/concat.rs @@ -27,7 +27,7 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, let mut accumulator = String::new(); for e in es { match e.node { - ast::ExprLit(ref lit) => { + ast::ExprKind::Lit(ref lit) => { match lit.node { ast::LitStr(ref s, _) | ast::LitFloat(ref s, _) | diff --git a/src/libsyntax_ext/concat_idents.rs b/src/libsyntax_ext/concat_idents.rs index 9702b24ffd4..85453f6dfcb 100644 --- a/src/libsyntax_ext/concat_idents.rs +++ b/src/libsyntax_ext/concat_idents.rs @@ -54,7 +54,7 @@ pub fn expand_syntax_ext<'cx>(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) let e = P(ast::Expr { id: ast::DUMMY_NODE_ID, - node: ast::ExprPath(None, + node: ast::ExprKind::Path(None, ast::Path { span: sp, global: false, diff --git a/src/libsyntax_ext/deriving/encodable.rs b/src/libsyntax_ext/deriving/encodable.rs index 02747d38c00..14631659b0b 100644 --- a/src/libsyntax_ext/deriving/encodable.rs +++ b/src/libsyntax_ext/deriving/encodable.rs @@ -91,7 +91,7 @@ use deriving::generic::*; use deriving::generic::ty::*; -use syntax::ast::{MetaItem, Expr, ExprRet, MutMutable}; +use syntax::ast::{MetaItem, Expr, ExprKind, MutMutable}; use syntax::codemap::Span; use syntax::ext::base::{ExtCtxt,Annotatable}; use syntax::ext::build::AstBuilder; @@ -208,16 +208,15 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span, let call = if i != last { cx.expr_try(span, call) } else { - cx.expr(span, ExprRet(Some(call))) + cx.expr(span, ExprKind::Ret(Some(call))) }; stmts.push(cx.stmt_expr(call)); } // unit structs have no fields and need to return Ok() if stmts.is_empty() { - let ret_ok = cx.expr(trait_span, - ExprRet(Some(cx.expr_ok(trait_span, - cx.expr_tuple(trait_span, vec![]))))); + let ok = cx.expr_ok(trait_span, cx.expr_tuple(trait_span, vec![])); + let ret_ok = cx.expr(trait_span, ExprKind::Ret(Some(ok))); stmts.push(cx.stmt_expr(ret_ok)); } @@ -254,14 +253,13 @@ fn encodable_substructure(cx: &mut ExtCtxt, trait_span: Span, let call = if i != last { cx.expr_try(span, call) } else { - cx.expr(span, ExprRet(Some(call))) + cx.expr(span, ExprKind::Ret(Some(call))) }; stmts.push(cx.stmt_expr(call)); } } else { - let ret_ok = cx.expr(trait_span, - ExprRet(Some(cx.expr_ok(trait_span, - cx.expr_tuple(trait_span, vec![]))))); + let ok = cx.expr_ok(trait_span, cx.expr_tuple(trait_span, vec![])); + let ret_ok = cx.expr(trait_span, ExprKind::Ret(Some(ok))); stmts.push(cx.stmt_expr(ret_ok)); } diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 3903f6a8085..82002b0be29 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -1311,7 +1311,7 @@ impl<'a> MethodDef<'a> { // expression; here add a layer of borrowing, turning // `(*self, *__arg_0, ...)` into `(&*self, &*__arg_0, ...)`. let borrowed_self_args = self_args.move_map(|self_arg| cx.expr_addr_of(sp, self_arg)); - let match_arg = cx.expr(sp, ast::ExprTup(borrowed_self_args)); + let match_arg = cx.expr(sp, ast::ExprKind::Tup(borrowed_self_args)); //Lastly we create an expression which branches on all discriminants being equal // if discriminant_test { @@ -1389,7 +1389,7 @@ impl<'a> MethodDef<'a> { // expression; here add a layer of borrowing, turning // `(*self, *__arg_0, ...)` into `(&*self, &*__arg_0, ...)`. let borrowed_self_args = self_args.move_map(|self_arg| cx.expr_addr_of(sp, self_arg)); - let match_arg = cx.expr(sp, ast::ExprTup(borrowed_self_args)); + let match_arg = cx.expr(sp, ast::ExprKind::Tup(borrowed_self_args)); cx.expr_match(sp, match_arg, match_arms) } } @@ -1509,8 +1509,8 @@ impl<'a> TraitDef<'a> { }; let ident = cx.ident_of(&format!("{}_{}", prefix, i)); paths.push(codemap::Spanned{span: sp, node: ident}); - let val = cx.expr( - sp, ast::ExprParen(cx.expr_deref(sp, cx.expr_path(cx.path_ident(sp,ident))))); + let val = cx.expr_deref(sp, cx.expr_path(cx.path_ident(sp,ident))); + let val = cx.expr(sp, ast::ExprKind::Paren(val)); ident_expr.push((sp, opt_id, val, &struct_field.node.attrs[..])); } diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index 449be3bc50c..986cdef49b2 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -559,7 +559,7 @@ impl<'a, 'b> Context<'a, 'b> { // as series of let's; the first approach does. let pat = self.ecx.pat_tuple(self.fmtsp, pats); let arm = self.ecx.arm(self.fmtsp, vec!(pat), args_array); - let head = self.ecx.expr(self.fmtsp, ast::ExprTup(heads)); + let head = self.ecx.expr(self.fmtsp, ast::ExprKind::Tup(heads)); let result = self.ecx.expr_match(self.fmtsp, head, vec!(arm)); let args_slice = self.ecx.expr_addr_of(self.fmtsp, result); From ccf48bcd4054ecb4e205a18b1ac582ef3ac3a905 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 8 Feb 2016 16:09:01 +0100 Subject: [PATCH 10/29] [breaking-change] don't glob export ast::FloatTy variants --- src/librustc/middle/const_eval.rs | 4 ++-- src/librustc/middle/ty/context.rs | 8 ++++---- src/librustc_lint/types.rs | 4 ++-- src/librustc_metadata/tyencode.rs | 4 ++-- src/librustc_resolve/lib.rs | 8 ++++---- src/librustc_trans/trans/collector.rs | 4 ++-- src/librustc_trans/trans/type_.rs | 4 ++-- src/librustc_typeck/check/intrinsic.rs | 4 ++-- src/librustc_typeck/check/method/probe.rs | 4 ++-- src/librustc_typeck/check/mod.rs | 2 +- src/librustc_typeck/coherence/orphan.rs | 4 ++-- src/librustdoc/clean/mod.rs | 8 ++++---- src/libsyntax/ast.rs | 13 ++++++------- src/libsyntax/parse/mod.rs | 4 ++-- 14 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index e5fc83cc5f3..4b4f9eefe22 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -1314,8 +1314,8 @@ fn cast_const<'tcx>(tcx: &ty::ctxt<'tcx>, val: ConstVal, ty: Ty) -> CastResult { ty::TyUint(ast::TyU32) => convert_val!(u32, Uint, u64), ty::TyUint(ast::TyU64) => convert_val!(u64, Uint, u64), - ty::TyFloat(ast::TyF32) => convert_val!(f32, Float, f64), - ty::TyFloat(ast::TyF64) => convert_val!(f64, Float, f64), + ty::TyFloat(ast::FloatTy::F32) => convert_val!(f32, Float, f64), + ty::TyFloat(ast::FloatTy::F64) => convert_val!(f64, Float, f64), _ => Err(ErrKind::CannotCast), } } diff --git a/src/librustc/middle/ty/context.rs b/src/librustc/middle/ty/context.rs index 6307ec8bbd0..ac924962485 100644 --- a/src/librustc/middle/ty/context.rs +++ b/src/librustc/middle/ty/context.rs @@ -202,8 +202,8 @@ impl<'tcx> CommonTypes<'tcx> { u16: mk(TyUint(ast::TyU16)), u32: mk(TyUint(ast::TyU32)), u64: mk(TyUint(ast::TyU64)), - f32: mk(TyFloat(ast::TyF32)), - f64: mk(TyFloat(ast::TyF64)), + f32: mk(TyFloat(ast::FloatTy::F32)), + f64: mk(TyFloat(ast::FloatTy::F64)), } } } @@ -860,8 +860,8 @@ impl<'tcx> ctxt<'tcx> { pub fn mk_mach_float(&self, tm: ast::FloatTy) -> Ty<'tcx> { match tm { - ast::TyF32 => self.types.f32, - ast::TyF64 => self.types.f64, + ast::FloatTy::F32 => self.types.f32, + ast::FloatTy::F64 => self.types.f64, } } diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index fae40d7224b..6adec347ac6 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -267,8 +267,8 @@ impl LateLintPass for TypeLimits { fn float_ty_range(float_ty: ast::FloatTy) -> (f64, f64) { match float_ty { - ast::TyF32 => (f32::MIN as f64, f32::MAX as f64), - ast::TyF64 => (f64::MIN, f64::MAX) + ast::FloatTy::F32 => (f32::MIN as f64, f32::MAX as f64), + ast::FloatTy::F64 => (f64::MIN, f64::MAX) } } diff --git a/src/librustc_metadata/tyencode.rs b/src/librustc_metadata/tyencode.rs index f03c25d698f..d4060165c1d 100644 --- a/src/librustc_metadata/tyencode.rs +++ b/src/librustc_metadata/tyencode.rs @@ -94,8 +94,8 @@ pub fn enc_ty<'a, 'tcx>(w: &mut Cursor>, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx } ty::TyFloat(t) => { match t { - ast::TyF32 => write!(w, "Mf"), - ast::TyF64 => write!(w, "MF"), + ast::FloatTy::F32 => write!(w, "Mf"), + ast::FloatTy::F64 => write!(w, "MF"), }; } ty::TyEnum(def, substs) => { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 5fbe06a868f..573bc91bbcb 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -60,9 +60,9 @@ use rustc::middle::subst::{ParamSpace, FnSpace, TypeSpace}; use rustc::middle::ty::{Freevar, FreevarMap, TraitMap, GlobMap}; use rustc::util::nodemap::{NodeMap, DefIdSet, FnvHashMap}; -use syntax::ast; +use syntax::ast::{self, FloatTy}; use syntax::ast::{CRATE_NODE_ID, Name, NodeId, CrateNum, TyIs, TyI8, TyI16, TyI32, TyI64}; -use syntax::ast::{TyUs, TyU8, TyU16, TyU32, TyU64, TyF64, TyF32}; +use syntax::ast::{TyUs, TyU8, TyU16, TyU32, TyU64}; use syntax::attr::AttrMetaMethods; use syntax::codemap::{self, Span, Pos}; use syntax::errors::DiagnosticBuilder; @@ -1074,8 +1074,8 @@ impl PrimitiveTypeTable { table.intern("bool", TyBool); table.intern("char", TyChar); - table.intern("f32", TyFloat(TyF32)); - table.intern("f64", TyFloat(TyF64)); + table.intern("f32", TyFloat(FloatTy::F32)); + table.intern("f64", TyFloat(FloatTy::F64)); table.intern("isize", TyInt(TyIs)); table.intern("i8", TyInt(TyI8)); table.intern("i16", TyInt(TyI16)); diff --git a/src/librustc_trans/trans/collector.rs b/src/librustc_trans/trans/collector.rs index ae4f7461a26..1c127b90f27 100644 --- a/src/librustc_trans/trans/collector.rs +++ b/src/librustc_trans/trans/collector.rs @@ -1230,8 +1230,8 @@ pub fn push_unique_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, ty::TyUint(ast::TyU16) => output.push_str("u16"), ty::TyUint(ast::TyU32) => output.push_str("u32"), ty::TyUint(ast::TyU64) => output.push_str("u64"), - ty::TyFloat(ast::TyF32) => output.push_str("f32"), - ty::TyFloat(ast::TyF64) => output.push_str("f64"), + ty::TyFloat(ast::FloatTy::F32) => output.push_str("f32"), + ty::TyFloat(ast::FloatTy::F64) => output.push_str("f64"), ty::TyStruct(adt_def, substs) | ty::TyEnum(adt_def, substs) => { push_item_name(cx, adt_def.did, output); diff --git a/src/librustc_trans/trans/type_.rs b/src/librustc_trans/trans/type_.rs index c635d1ba233..5d5aa5240d6 100644 --- a/src/librustc_trans/trans/type_.rs +++ b/src/librustc_trans/trans/type_.rs @@ -147,8 +147,8 @@ impl Type { pub fn float_from_ty(ccx: &CrateContext, t: ast::FloatTy) -> Type { match t { - ast::TyF32 => Type::f32(ccx), - ast::TyF64 => Type::f64(ccx), + ast::FloatTy::F32 => Type::f32(ccx), + ast::FloatTy::F64 => Type::f64(ccx), } } diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 248a2341c2b..0f3cce18ea2 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -443,8 +443,8 @@ fn match_intrinsic_type_to_type<'tcx, 'a>( n = bits)), }, Float(bits) => match (bits, &t.sty) { - (32, &ty::TyFloat(ast::FloatTy::TyF32)) | - (64, &ty::TyFloat(ast::FloatTy::TyF64)) => {}, + (32, &ty::TyFloat(ast::FloatTy::F32)) | + (64, &ty::TyFloat(ast::FloatTy::F64)) => {}, _ => simple_error(&format!("`{}`", t), &format!("`f{n}`", n = bits)), }, diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 44dd0ef7b17..becb0c93b26 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -357,11 +357,11 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { let lang_def_id = self.tcx().lang_items.usize_impl(); self.assemble_inherent_impl_for_primitive(lang_def_id); } - ty::TyFloat(ast::TyF32) => { + ty::TyFloat(ast::FloatTy::F32) => { let lang_def_id = self.tcx().lang_items.f32_impl(); self.assemble_inherent_impl_for_primitive(lang_def_id); } - ty::TyFloat(ast::TyF64) => { + ty::TyFloat(ast::FloatTy::F64) => { let lang_def_id = self.tcx().lang_items.f64_impl(); self.assemble_inherent_impl_for_primitive(lang_def_id); } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index a1280d0f7e4..7a38a4a0cbf 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2556,7 +2556,7 @@ fn check_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, let arg_ty = structurally_resolved_type(fcx, arg.span, fcx.expr_ty(&**arg)); match arg_ty.sty { - ty::TyFloat(ast::TyF32) => { + ty::TyFloat(ast::FloatTy::F32) => { fcx.type_error_message(arg.span, |t| { format!("can't pass an {} to variadic \ diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index fb257f0e673..e03bbfd09f2 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -191,14 +191,14 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> { "usize", item.span); } - ty::TyFloat(ast::TyF32) => { + ty::TyFloat(ast::FloatTy::F32) => { self.check_primitive_impl(def_id, self.tcx.lang_items.f32_impl(), "f32", "f32", item.span); } - ty::TyFloat(ast::TyF64) => { + ty::TyFloat(ast::FloatTy::F64) => { self.check_primitive_impl(def_id, self.tcx.lang_items.f64_impl(), "f64", diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index d7fb789ada1..254106434fa 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1650,8 +1650,8 @@ impl<'tcx> Clean for ty::Ty<'tcx> { ty::TyUint(ast::TyU16) => Primitive(U16), ty::TyUint(ast::TyU32) => Primitive(U32), ty::TyUint(ast::TyU64) => Primitive(U64), - ty::TyFloat(ast::TyF32) => Primitive(F32), - ty::TyFloat(ast::TyF64) => Primitive(F64), + ty::TyFloat(ast::FloatTy::F32) => Primitive(F32), + ty::TyFloat(ast::FloatTy::F64) => Primitive(F64), ty::TyStr => Primitive(Str), ty::TyBox(t) => { let box_did = cx.tcx_opt().and_then(|tcx| { @@ -2629,8 +2629,8 @@ fn resolve_type(cx: &DocContext, hir::TyUint(ast::TyU16) => return Primitive(U16), hir::TyUint(ast::TyU32) => return Primitive(U32), hir::TyUint(ast::TyU64) => return Primitive(U64), - hir::TyFloat(ast::TyF32) => return Primitive(F32), - hir::TyFloat(ast::TyF64) => return Primitive(F64), + hir::TyFloat(ast::FloatTy::F32) => return Primitive(F32), + hir::TyFloat(ast::FloatTy::F64) => return Primitive(F64), }, Def::SelfTy(..) if path.segments.len() == 1 => { return Generic(special_idents::type_self.name.to_string()); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 36543bd35ca..a43874f9990 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,7 +10,6 @@ // The Rust abstract syntax tree. -pub use self::FloatTy::*; pub use self::ForeignItem_::*; pub use self::IntTy::*; pub use self::Item_::*; @@ -1509,8 +1508,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 { @@ -1528,15 +1527,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, } } } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 9ad5dafbf8b..bbcb0c70ff4 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -452,8 +452,8 @@ fn filtered_float_lit(data: token::InternedString, suffix: Option<&str>, sd: &Handler, sp: Span) -> ast::Lit_ { 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::LitFloat(data, ast::FloatTy::F32), + Some("f64") => ast::LitFloat(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. From 625e78b7001c6e20f29928a5da8c9d21e9aed6c5 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 8 Feb 2016 16:20:57 +0100 Subject: [PATCH 11/29] [breaking-change] don't glob export ast::{UintTy, IntTy} variants --- src/librustc/middle/const_eval.rs | 56 +++++----- src/librustc/middle/ty/contents.rs | 2 +- src/librustc/middle/ty/context.rs | 40 +++---- src/librustc/middle/ty/sty.rs | 6 +- src/librustc/middle/ty/util.rs | 126 +++++++++++----------- src/librustc/session/config.rs | 4 +- src/librustc_lint/types.rs | 44 ++++---- src/librustc_metadata/tyencode.rs | 20 ++-- src/librustc_resolve/lib.rs | 23 ++-- src/librustc_trans/trans/_match.rs | 2 +- src/librustc_trans/trans/adt.rs | 18 ++-- src/librustc_trans/trans/base.rs | 12 +-- src/librustc_trans/trans/collector.rs | 20 ++-- src/librustc_trans/trans/consts.rs | 2 +- src/librustc_trans/trans/expr.rs | 60 +++++------ src/librustc_trans/trans/intrinsic.rs | 20 ++-- src/librustc_trans/trans/meth.rs | 2 +- src/librustc_trans/trans/type_.rs | 20 ++-- src/librustc_trans/trans/type_of.rs | 2 +- src/librustc_typeck/check/cast.rs | 2 +- src/librustc_typeck/check/intrinsic.rs | 16 +-- src/librustc_typeck/check/method/probe.rs | 20 ++-- src/librustc_typeck/check/mod.rs | 26 ++--- src/librustc_typeck/coherence/orphan.rs | 20 ++-- src/librustdoc/clean/mod.rs | 40 +++---- src/libsyntax/ast.rs | 78 +++++++------- src/libsyntax/attr.rs | 30 +++--- src/libsyntax/ext/build.rs | 8 +- src/libsyntax/ext/quote.rs | 20 ++-- src/libsyntax/parse/mod.rs | 20 ++-- src/libsyntax/parse/parser.rs | 6 +- src/libsyntax/print/pprust.rs | 4 +- src/libsyntax_ext/deriving/generic/mod.rs | 20 ++-- 33 files changed, 393 insertions(+), 396 deletions(-) diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 4b4f9eefe22..5e3cfff086c 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -545,34 +545,34 @@ pub enum UintTy { U8, U16, U32, U64 } impl IntTy { pub fn from(tcx: &ty::ctxt, t: ast::IntTy) -> IntTy { - let t = if let ast::TyIs = t { + let t = if let ast::IntTy::Is = t { tcx.sess.target.int_type } else { t }; match t { - ast::TyIs => unreachable!(), - ast::TyI8 => IntTy::I8, - ast::TyI16 => IntTy::I16, - ast::TyI32 => IntTy::I32, - ast::TyI64 => IntTy::I64, + ast::IntTy::Is => unreachable!(), + ast::IntTy::I8 => IntTy::I8, + ast::IntTy::I16 => IntTy::I16, + ast::IntTy::I32 => IntTy::I32, + ast::IntTy::I64 => IntTy::I64, } } } impl UintTy { pub fn from(tcx: &ty::ctxt, t: ast::UintTy) -> UintTy { - let t = if let ast::TyUs = t { + let t = if let ast::UintTy::Us = t { tcx.sess.target.uint_type } else { t }; match t { - ast::TyUs => unreachable!(), - ast::TyU8 => UintTy::U8, - ast::TyU16 => UintTy::U16, - ast::TyU32 => UintTy::U32, - ast::TyU64 => UintTy::U64, + ast::UintTy::Us => unreachable!(), + ast::UintTy::U8 => UintTy::U8, + ast::UintTy::U16 => UintTy::U16, + ast::UintTy::U32 => UintTy::U32, + ast::UintTy::U64 => UintTy::U64, } } } @@ -1289,30 +1289,30 @@ fn cast_const<'tcx>(tcx: &ty::ctxt<'tcx>, val: ConstVal, ty: Ty) -> CastResult { // Issue #23890: If isize/usize, then dispatch to appropriate target representation type match (&ty.sty, tcx.sess.target.int_type, tcx.sess.target.uint_type) { - (&ty::TyInt(ast::TyIs), ast::TyI32, _) => return convert_val!(i32, Int, i64), - (&ty::TyInt(ast::TyIs), ast::TyI64, _) => return convert_val!(i64, Int, i64), - (&ty::TyInt(ast::TyIs), _, _) => panic!("unexpected target.int_type"), + (&ty::TyInt(ast::IntTy::Is), ast::IntTy::I32, _) => return convert_val!(i32, Int, i64), + (&ty::TyInt(ast::IntTy::Is), ast::IntTy::I64, _) => return convert_val!(i64, Int, i64), + (&ty::TyInt(ast::IntTy::Is), _, _) => panic!("unexpected target.int_type"), - (&ty::TyUint(ast::TyUs), _, ast::TyU32) => return convert_val!(u32, Uint, u64), - (&ty::TyUint(ast::TyUs), _, ast::TyU64) => return convert_val!(u64, Uint, u64), - (&ty::TyUint(ast::TyUs), _, _) => panic!("unexpected target.uint_type"), + (&ty::TyUint(ast::UintTy::Us), _, ast::UintTy::U32) => return convert_val!(u32, Uint, u64), + (&ty::TyUint(ast::UintTy::Us), _, ast::UintTy::U64) => return convert_val!(u64, Uint, u64), + (&ty::TyUint(ast::UintTy::Us), _, _) => panic!("unexpected target.uint_type"), _ => {} } match ty.sty { - ty::TyInt(ast::TyIs) => unreachable!(), - ty::TyUint(ast::TyUs) => unreachable!(), + ty::TyInt(ast::IntTy::Is) => unreachable!(), + ty::TyUint(ast::UintTy::Us) => unreachable!(), - ty::TyInt(ast::TyI8) => convert_val!(i8, Int, i64), - ty::TyInt(ast::TyI16) => convert_val!(i16, Int, i64), - ty::TyInt(ast::TyI32) => convert_val!(i32, Int, i64), - ty::TyInt(ast::TyI64) => convert_val!(i64, Int, i64), + ty::TyInt(ast::IntTy::I8) => convert_val!(i8, Int, i64), + ty::TyInt(ast::IntTy::I16) => convert_val!(i16, Int, i64), + ty::TyInt(ast::IntTy::I32) => convert_val!(i32, Int, i64), + ty::TyInt(ast::IntTy::I64) => convert_val!(i64, Int, i64), - ty::TyUint(ast::TyU8) => convert_val!(u8, Uint, u64), - ty::TyUint(ast::TyU16) => convert_val!(u16, Uint, u64), - ty::TyUint(ast::TyU32) => convert_val!(u32, Uint, u64), - ty::TyUint(ast::TyU64) => convert_val!(u64, Uint, u64), + ty::TyUint(ast::UintTy::U8) => convert_val!(u8, Uint, u64), + ty::TyUint(ast::UintTy::U16) => convert_val!(u16, Uint, u64), + ty::TyUint(ast::UintTy::U32) => convert_val!(u32, Uint, u64), + ty::TyUint(ast::UintTy::U64) => convert_val!(u64, Uint, u64), ty::TyFloat(ast::FloatTy::F32) => convert_val!(f32, Float, f64), ty::TyFloat(ast::FloatTy::F64) => convert_val!(f64, Float, f64), diff --git a/src/librustc/middle/ty/contents.rs b/src/librustc/middle/ty/contents.rs index 619201a4a9f..3a42e8e9bfa 100644 --- a/src/librustc/middle/ty/contents.rs +++ b/src/librustc/middle/ty/contents.rs @@ -180,7 +180,7 @@ impl<'tcx> ty::TyS<'tcx> { let result = match ty.sty { // usize and isize are ffi-unsafe - ty::TyUint(ast::TyUs) | ty::TyInt(ast::TyIs) => { + ty::TyUint(ast::UintTy::Us) | ty::TyInt(ast::IntTy::Is) => { TC::None } diff --git a/src/librustc/middle/ty/context.rs b/src/librustc/middle/ty/context.rs index ac924962485..1d071cd604d 100644 --- a/src/librustc/middle/ty/context.rs +++ b/src/librustc/middle/ty/context.rs @@ -192,16 +192,16 @@ impl<'tcx> CommonTypes<'tcx> { bool: mk(TyBool), char: mk(TyChar), err: mk(TyError), - isize: mk(TyInt(ast::TyIs)), - i8: mk(TyInt(ast::TyI8)), - i16: mk(TyInt(ast::TyI16)), - i32: mk(TyInt(ast::TyI32)), - i64: mk(TyInt(ast::TyI64)), - usize: mk(TyUint(ast::TyUs)), - u8: mk(TyUint(ast::TyU8)), - u16: mk(TyUint(ast::TyU16)), - u32: mk(TyUint(ast::TyU32)), - u64: mk(TyUint(ast::TyU64)), + isize: mk(TyInt(ast::IntTy::Is)), + i8: mk(TyInt(ast::IntTy::I8)), + i16: mk(TyInt(ast::IntTy::I16)), + i32: mk(TyInt(ast::IntTy::I32)), + i64: mk(TyInt(ast::IntTy::I64)), + usize: mk(TyUint(ast::UintTy::Us)), + u8: mk(TyUint(ast::UintTy::U8)), + u16: mk(TyUint(ast::UintTy::U16)), + u32: mk(TyUint(ast::UintTy::U32)), + u64: mk(TyUint(ast::UintTy::U64)), f32: mk(TyFloat(ast::FloatTy::F32)), f64: mk(TyFloat(ast::FloatTy::F64)), } @@ -840,21 +840,21 @@ impl<'tcx> ctxt<'tcx> { pub fn mk_mach_int(&self, tm: ast::IntTy) -> Ty<'tcx> { match tm { - ast::TyIs => self.types.isize, - ast::TyI8 => self.types.i8, - ast::TyI16 => self.types.i16, - ast::TyI32 => self.types.i32, - ast::TyI64 => self.types.i64, + ast::IntTy::Is => self.types.isize, + ast::IntTy::I8 => self.types.i8, + ast::IntTy::I16 => self.types.i16, + ast::IntTy::I32 => self.types.i32, + ast::IntTy::I64 => self.types.i64, } } pub fn mk_mach_uint(&self, tm: ast::UintTy) -> Ty<'tcx> { match tm { - ast::TyUs => self.types.usize, - ast::TyU8 => self.types.u8, - ast::TyU16 => self.types.u16, - ast::TyU32 => self.types.u32, - ast::TyU64 => self.types.u64, + ast::UintTy::Us => self.types.usize, + ast::UintTy::U8 => self.types.u8, + ast::UintTy::U16 => self.types.u16, + ast::UintTy::U32 => self.types.u32, + ast::UintTy::U64 => self.types.u64, } } diff --git a/src/librustc/middle/ty/sty.rs b/src/librustc/middle/ty/sty.rs index 6d40d377b78..2a13c47895e 100644 --- a/src/librustc/middle/ty/sty.rs +++ b/src/librustc/middle/ty/sty.rs @@ -977,7 +977,7 @@ impl<'tcx> TyS<'tcx> { pub fn sequence_element_type(&self, cx: &ty::ctxt<'tcx>) -> Ty<'tcx> { match self.sty { TyArray(ty, _) | TySlice(ty) => ty, - TyStr => cx.mk_mach_uint(ast::TyU8), + TyStr => cx.mk_mach_uint(ast::UintTy::U8), _ => cx.sess.bug(&format!("sequence_element_type called on non-sequence value: {}", self)), } @@ -1068,7 +1068,7 @@ impl<'tcx> TyS<'tcx> { pub fn is_uint(&self) -> bool { match self.sty { - TyInfer(IntVar(_)) | TyUint(ast::TyUs) => true, + TyInfer(IntVar(_)) | TyUint(ast::UintTy::Us) => true, _ => false } } @@ -1114,7 +1114,7 @@ impl<'tcx> TyS<'tcx> { pub fn is_machine(&self) -> bool { match self.sty { - TyInt(ast::TyIs) | TyUint(ast::TyUs) => false, + TyInt(ast::IntTy::Is) | TyUint(ast::UintTy::Us) => false, TyInt(..) | TyUint(..) | TyFloat(..) => true, _ => false } diff --git a/src/librustc/middle/ty/util.rs b/src/librustc/middle/ty/util.rs index 8cfd27843ae..0b5c0d147cb 100644 --- a/src/librustc/middle/ty/util.rs +++ b/src/librustc/middle/ty/util.rs @@ -44,48 +44,48 @@ pub trait IntTypeExt { impl IntTypeExt for attr::IntType { fn to_ty<'tcx>(&self, cx: &ty::ctxt<'tcx>) -> Ty<'tcx> { match *self { - SignedInt(ast::TyI8) => cx.types.i8, - SignedInt(ast::TyI16) => cx.types.i16, - SignedInt(ast::TyI32) => cx.types.i32, - SignedInt(ast::TyI64) => cx.types.i64, - SignedInt(ast::TyIs) => cx.types.isize, - UnsignedInt(ast::TyU8) => cx.types.u8, - UnsignedInt(ast::TyU16) => cx.types.u16, - UnsignedInt(ast::TyU32) => cx.types.u32, - UnsignedInt(ast::TyU64) => cx.types.u64, - UnsignedInt(ast::TyUs) => cx.types.usize, + SignedInt(ast::IntTy::I8) => cx.types.i8, + SignedInt(ast::IntTy::I16) => cx.types.i16, + SignedInt(ast::IntTy::I32) => cx.types.i32, + SignedInt(ast::IntTy::I64) => cx.types.i64, + SignedInt(ast::IntTy::Is) => cx.types.isize, + UnsignedInt(ast::UintTy::U8) => cx.types.u8, + UnsignedInt(ast::UintTy::U16) => cx.types.u16, + UnsignedInt(ast::UintTy::U32) => cx.types.u32, + UnsignedInt(ast::UintTy::U64) => cx.types.u64, + UnsignedInt(ast::UintTy::Us) => cx.types.usize, } } fn i64_to_disr(&self, val: i64) -> Option { match *self { - SignedInt(ast::TyI8) => val.to_i8() .map(|v| v as Disr), - SignedInt(ast::TyI16) => val.to_i16() .map(|v| v as Disr), - SignedInt(ast::TyI32) => val.to_i32() .map(|v| v as Disr), - SignedInt(ast::TyI64) => val.to_i64() .map(|v| v as Disr), - UnsignedInt(ast::TyU8) => val.to_u8() .map(|v| v as Disr), - UnsignedInt(ast::TyU16) => val.to_u16() .map(|v| v as Disr), - UnsignedInt(ast::TyU32) => val.to_u32() .map(|v| v as Disr), - UnsignedInt(ast::TyU64) => val.to_u64() .map(|v| v as Disr), + SignedInt(ast::IntTy::I8) => val.to_i8() .map(|v| v as Disr), + SignedInt(ast::IntTy::I16) => val.to_i16() .map(|v| v as Disr), + SignedInt(ast::IntTy::I32) => val.to_i32() .map(|v| v as Disr), + SignedInt(ast::IntTy::I64) => val.to_i64() .map(|v| v as Disr), + UnsignedInt(ast::UintTy::U8) => val.to_u8() .map(|v| v as Disr), + UnsignedInt(ast::UintTy::U16) => val.to_u16() .map(|v| v as Disr), + UnsignedInt(ast::UintTy::U32) => val.to_u32() .map(|v| v as Disr), + UnsignedInt(ast::UintTy::U64) => val.to_u64() .map(|v| v as Disr), - UnsignedInt(ast::TyUs) | - SignedInt(ast::TyIs) => unreachable!(), + UnsignedInt(ast::UintTy::Us) | + SignedInt(ast::IntTy::Is) => unreachable!(), } } fn u64_to_disr(&self, val: u64) -> Option { match *self { - SignedInt(ast::TyI8) => val.to_i8() .map(|v| v as Disr), - SignedInt(ast::TyI16) => val.to_i16() .map(|v| v as Disr), - SignedInt(ast::TyI32) => val.to_i32() .map(|v| v as Disr), - SignedInt(ast::TyI64) => val.to_i64() .map(|v| v as Disr), - UnsignedInt(ast::TyU8) => val.to_u8() .map(|v| v as Disr), - UnsignedInt(ast::TyU16) => val.to_u16() .map(|v| v as Disr), - UnsignedInt(ast::TyU32) => val.to_u32() .map(|v| v as Disr), - UnsignedInt(ast::TyU64) => val.to_u64() .map(|v| v as Disr), + SignedInt(ast::IntTy::I8) => val.to_i8() .map(|v| v as Disr), + SignedInt(ast::IntTy::I16) => val.to_i16() .map(|v| v as Disr), + SignedInt(ast::IntTy::I32) => val.to_i32() .map(|v| v as Disr), + SignedInt(ast::IntTy::I64) => val.to_i64() .map(|v| v as Disr), + UnsignedInt(ast::UintTy::U8) => val.to_u8() .map(|v| v as Disr), + UnsignedInt(ast::UintTy::U16) => val.to_u16() .map(|v| v as Disr), + UnsignedInt(ast::UintTy::U32) => val.to_u32() .map(|v| v as Disr), + UnsignedInt(ast::UintTy::U64) => val.to_u64() .map(|v| v as Disr), - UnsignedInt(ast::TyUs) | - SignedInt(ast::TyIs) => unreachable!(), + UnsignedInt(ast::UintTy::Us) | + SignedInt(ast::IntTy::Is) => unreachable!(), } } @@ -97,18 +97,18 @@ impl IntTypeExt for attr::IntType { // SignedInt repr means we *want* to reinterpret the bits // treating the highest bit of Disr as a sign-bit, so // cast to i64 before range-checking. - SignedInt(ast::TyI8) => add1!((val as i64).to_i8()), - SignedInt(ast::TyI16) => add1!((val as i64).to_i16()), - SignedInt(ast::TyI32) => add1!((val as i64).to_i32()), - SignedInt(ast::TyI64) => add1!(Some(val as i64)), + SignedInt(ast::IntTy::I8) => add1!((val as i64).to_i8()), + SignedInt(ast::IntTy::I16) => add1!((val as i64).to_i16()), + SignedInt(ast::IntTy::I32) => add1!((val as i64).to_i32()), + SignedInt(ast::IntTy::I64) => add1!(Some(val as i64)), - UnsignedInt(ast::TyU8) => add1!(val.to_u8()), - UnsignedInt(ast::TyU16) => add1!(val.to_u16()), - UnsignedInt(ast::TyU32) => add1!(val.to_u32()), - UnsignedInt(ast::TyU64) => add1!(Some(val)), + UnsignedInt(ast::UintTy::U8) => add1!(val.to_u8()), + UnsignedInt(ast::UintTy::U16) => add1!(val.to_u16()), + UnsignedInt(ast::UintTy::U32) => add1!(val.to_u32()), + UnsignedInt(ast::UintTy::U64) => add1!(Some(val)), - UnsignedInt(ast::TyUs) | - SignedInt(ast::TyIs) => unreachable!(), + UnsignedInt(ast::UintTy::Us) | + SignedInt(ast::IntTy::Is) => unreachable!(), } } @@ -117,17 +117,17 @@ impl IntTypeExt for attr::IntType { // full range from `i64::MIN` through `u64::MAX`. fn disr_string(&self, val: Disr) -> String { match *self { - SignedInt(ast::TyI8) => format!("{}", val as i8 ), - SignedInt(ast::TyI16) => format!("{}", val as i16), - SignedInt(ast::TyI32) => format!("{}", val as i32), - SignedInt(ast::TyI64) => format!("{}", val as i64), - UnsignedInt(ast::TyU8) => format!("{}", val as u8 ), - UnsignedInt(ast::TyU16) => format!("{}", val as u16), - UnsignedInt(ast::TyU32) => format!("{}", val as u32), - UnsignedInt(ast::TyU64) => format!("{}", val as u64), + SignedInt(ast::IntTy::I8) => format!("{}", val as i8 ), + SignedInt(ast::IntTy::I16) => format!("{}", val as i16), + SignedInt(ast::IntTy::I32) => format!("{}", val as i32), + SignedInt(ast::IntTy::I64) => format!("{}", val as i64), + UnsignedInt(ast::UintTy::U8) => format!("{}", val as u8 ), + UnsignedInt(ast::UintTy::U16) => format!("{}", val as u16), + UnsignedInt(ast::UintTy::U32) => format!("{}", val as u32), + UnsignedInt(ast::UintTy::U64) => format!("{}", val as u64), - UnsignedInt(ast::TyUs) | - SignedInt(ast::TyIs) => unreachable!(), + UnsignedInt(ast::UintTy::Us) | + SignedInt(ast::IntTy::Is) => unreachable!(), } } @@ -137,17 +137,17 @@ impl IntTypeExt for attr::IntType { } let val = val.unwrap_or(ty::INITIAL_DISCRIMINANT_VALUE); match *self { - SignedInt(ast::TyI8) => add1!(val as i8 ), - SignedInt(ast::TyI16) => add1!(val as i16), - SignedInt(ast::TyI32) => add1!(val as i32), - SignedInt(ast::TyI64) => add1!(val as i64), - UnsignedInt(ast::TyU8) => add1!(val as u8 ), - UnsignedInt(ast::TyU16) => add1!(val as u16), - UnsignedInt(ast::TyU32) => add1!(val as u32), - UnsignedInt(ast::TyU64) => add1!(val as u64), + SignedInt(ast::IntTy::I8) => add1!(val as i8 ), + SignedInt(ast::IntTy::I16) => add1!(val as i16), + SignedInt(ast::IntTy::I32) => add1!(val as i32), + SignedInt(ast::IntTy::I64) => add1!(val as i64), + UnsignedInt(ast::UintTy::U8) => add1!(val as u8 ), + UnsignedInt(ast::UintTy::U16) => add1!(val as u16), + UnsignedInt(ast::UintTy::U32) => add1!(val as u32), + UnsignedInt(ast::UintTy::U64) => add1!(val as u64), - UnsignedInt(ast::TyUs) | - SignedInt(ast::TyIs) => unreachable!(), + UnsignedInt(ast::UintTy::Us) | + SignedInt(ast::IntTy::Is) => unreachable!(), } } } @@ -279,14 +279,14 @@ impl<'tcx> ty::ctxt<'tcx> { // // NB. Historically `fn enum_variants` generate i64 here, while // rustc_typeck::check would generate isize. - _ => SignedInt(ast::TyIs), + _ => SignedInt(ast::IntTy::Is), }; let repr_type_ty = repr_type.to_ty(self); let repr_type = match repr_type { - SignedInt(ast::TyIs) => + SignedInt(ast::IntTy::Is) => SignedInt(self.sess.target.int_type), - UnsignedInt(ast::TyUs) => + UnsignedInt(ast::UintTy::Us) => UnsignedInt(self.sess.target.uint_type), other => other }; diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index f6079217829..20860b5a1e6 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -728,8 +728,8 @@ pub fn build_target_config(opts: &Options, sp: &Handler) -> Config { }; let (int_type, uint_type) = match &target.target_pointer_width[..] { - "32" => (ast::TyI32, ast::TyU32), - "64" => (ast::TyI64, ast::TyU64), + "32" => (ast::IntTy::I32, ast::UintTy::U32), + "64" => (ast::IntTy::I64, ast::UintTy::U64), w => panic!(sp.fatal(&format!("target specification was invalid: \ unrecognized target-pointer-width {}", w))), }; diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 6adec347ac6..bd5f237cbfb 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -161,7 +161,7 @@ impl LateLintPass for TypeLimits { match lit.node { ast::LitInt(v, ast::SignedIntLit(_, ast::Plus)) | ast::LitInt(v, ast::UnsuffixedIntLit(ast::Plus)) => { - let int_type = if let ast::TyIs = t { + let int_type = if let ast::IntTy::Is = t { cx.sess().target.int_type } else { t @@ -182,7 +182,7 @@ impl LateLintPass for TypeLimits { }; }, ty::TyUint(t) => { - let uint_type = if let ast::TyUs = t { + let uint_type = if let ast::UintTy::Us = t { cx.sess().target.uint_type } else { t @@ -247,21 +247,21 @@ impl LateLintPass for TypeLimits { // warnings are consistent between 32- and 64-bit platforms fn int_ty_range(int_ty: ast::IntTy) -> (i64, i64) { match int_ty { - ast::TyIs => (i64::MIN, i64::MAX), - ast::TyI8 => (i8::MIN as i64, i8::MAX as i64), - ast::TyI16 => (i16::MIN as i64, i16::MAX as i64), - ast::TyI32 => (i32::MIN as i64, i32::MAX as i64), - ast::TyI64 => (i64::MIN, i64::MAX) + ast::IntTy::Is => (i64::MIN, i64::MAX), + ast::IntTy::I8 => (i8::MIN as i64, i8::MAX as i64), + ast::IntTy::I16 => (i16::MIN as i64, i16::MAX as i64), + ast::IntTy::I32 => (i32::MIN as i64, i32::MAX as i64), + ast::IntTy::I64 => (i64::MIN, i64::MAX) } } fn uint_ty_range(uint_ty: ast::UintTy) -> (u64, u64) { match uint_ty { - ast::TyUs => (u64::MIN, u64::MAX), - ast::TyU8 => (u8::MIN as u64, u8::MAX as u64), - ast::TyU16 => (u16::MIN as u64, u16::MAX as u64), - ast::TyU32 => (u32::MIN as u64, u32::MAX as u64), - ast::TyU64 => (u64::MIN, u64::MAX) + ast::UintTy::Us => (u64::MIN, u64::MAX), + ast::UintTy::U8 => (u8::MIN as u64, u8::MAX as u64), + ast::UintTy::U16 => (u16::MIN as u64, u16::MAX as u64), + ast::UintTy::U32 => (u32::MIN as u64, u32::MAX as u64), + ast::UintTy::U64 => (u64::MIN, u64::MAX) } } @@ -274,21 +274,21 @@ impl LateLintPass for TypeLimits { fn int_ty_bits(int_ty: ast::IntTy, target_int_ty: ast::IntTy) -> u64 { match int_ty { - ast::TyIs => int_ty_bits(target_int_ty, target_int_ty), - ast::TyI8 => 8, - ast::TyI16 => 16 as u64, - ast::TyI32 => 32, - ast::TyI64 => 64, + ast::IntTy::Is => int_ty_bits(target_int_ty, target_int_ty), + ast::IntTy::I8 => 8, + ast::IntTy::I16 => 16 as u64, + ast::IntTy::I32 => 32, + ast::IntTy::I64 => 64, } } fn uint_ty_bits(uint_ty: ast::UintTy, target_uint_ty: ast::UintTy) -> u64 { match uint_ty { - ast::TyUs => uint_ty_bits(target_uint_ty, target_uint_ty), - ast::TyU8 => 8, - ast::TyU16 => 16, - ast::TyU32 => 32, - ast::TyU64 => 64, + ast::UintTy::Us => uint_ty_bits(target_uint_ty, target_uint_ty), + ast::UintTy::U8 => 8, + ast::UintTy::U16 => 16, + ast::UintTy::U32 => 32, + ast::UintTy::U64 => 64, } } diff --git a/src/librustc_metadata/tyencode.rs b/src/librustc_metadata/tyencode.rs index d4060165c1d..b41ff5977fe 100644 --- a/src/librustc_metadata/tyencode.rs +++ b/src/librustc_metadata/tyencode.rs @@ -76,20 +76,20 @@ pub fn enc_ty<'a, 'tcx>(w: &mut Cursor>, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx ty::TyChar => { write!(w, "c"); } ty::TyInt(t) => { match t { - ast::TyIs => write!(w, "is"), - ast::TyI8 => write!(w, "MB"), - ast::TyI16 => write!(w, "MW"), - ast::TyI32 => write!(w, "ML"), - ast::TyI64 => write!(w, "MD") + ast::IntTy::Is => write!(w, "is"), + ast::IntTy::I8 => write!(w, "MB"), + ast::IntTy::I16 => write!(w, "MW"), + ast::IntTy::I32 => write!(w, "ML"), + ast::IntTy::I64 => write!(w, "MD") }; } ty::TyUint(t) => { match t { - ast::TyUs => write!(w, "us"), - ast::TyU8 => write!(w, "Mb"), - ast::TyU16 => write!(w, "Mw"), - ast::TyU32 => write!(w, "Ml"), - ast::TyU64 => write!(w, "Md") + ast::UintTy::Us => write!(w, "us"), + ast::UintTy::U8 => write!(w, "Mb"), + ast::UintTy::U16 => write!(w, "Mw"), + ast::UintTy::U32 => write!(w, "Ml"), + ast::UintTy::U64 => write!(w, "Md") }; } ty::TyFloat(t) => { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 573bc91bbcb..a3082cb698a 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -61,8 +61,7 @@ use rustc::middle::ty::{Freevar, FreevarMap, TraitMap, GlobMap}; use rustc::util::nodemap::{NodeMap, DefIdSet, FnvHashMap}; use syntax::ast::{self, FloatTy}; -use syntax::ast::{CRATE_NODE_ID, Name, NodeId, CrateNum, TyIs, TyI8, TyI16, TyI32, TyI64}; -use syntax::ast::{TyUs, TyU8, TyU16, TyU32, TyU64}; +use syntax::ast::{CRATE_NODE_ID, Name, NodeId, CrateNum, IntTy, UintTy}; use syntax::attr::AttrMetaMethods; use syntax::codemap::{self, Span, Pos}; use syntax::errors::DiagnosticBuilder; @@ -1076,17 +1075,17 @@ impl PrimitiveTypeTable { table.intern("char", TyChar); table.intern("f32", TyFloat(FloatTy::F32)); table.intern("f64", TyFloat(FloatTy::F64)); - table.intern("isize", TyInt(TyIs)); - table.intern("i8", TyInt(TyI8)); - table.intern("i16", TyInt(TyI16)); - table.intern("i32", TyInt(TyI32)); - table.intern("i64", TyInt(TyI64)); + table.intern("isize", TyInt(IntTy::Is)); + table.intern("i8", TyInt(IntTy::I8)); + table.intern("i16", TyInt(IntTy::I16)); + table.intern("i32", TyInt(IntTy::I32)); + table.intern("i64", TyInt(IntTy::I64)); table.intern("str", TyStr); - table.intern("usize", TyUint(TyUs)); - table.intern("u8", TyUint(TyU8)); - table.intern("u16", TyUint(TyU16)); - table.intern("u32", TyUint(TyU32)); - table.intern("u64", TyUint(TyU64)); + table.intern("usize", TyUint(UintTy::Us)); + table.intern("u8", TyUint(UintTy::U8)); + table.intern("u16", TyUint(UintTy::U16)); + table.intern("u32", TyUint(UintTy::U32)); + table.intern("u64", TyUint(UintTy::U64)); table } diff --git a/src/librustc_trans/trans/_match.rs b/src/librustc_trans/trans/_match.rs index 851ff33cf93..28731aa950b 100644 --- a/src/librustc_trans/trans/_match.rs +++ b/src/librustc_trans/trans/_match.rs @@ -921,7 +921,7 @@ fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>, compare_str(cx, lhs_data, lhs_len, rhs_data, rhs_len, rhs_t, debug_loc) } ty::TyArray(ty, _) | ty::TySlice(ty) => match ty.sty { - ty::TyUint(ast::TyU8) => { + ty::TyUint(ast::UintTy::U8) => { // NOTE: cast &[u8] and &[u8; N] to &str and abuse the str_eq lang item, // which calls memcmp(). let pat_len = val_ty(rhs).element_type().array_length(); diff --git a/src/librustc_trans/trans/adt.rs b/src/librustc_trans/trans/adt.rs index c77904020b2..ba227d6c38b 100644 --- a/src/librustc_trans/trans/adt.rs +++ b/src/librustc_trans/trans/adt.rs @@ -403,11 +403,11 @@ fn represent_type_uncached<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, let ity = if use_align { // Use the overall alignment match align { - 1 => attr::UnsignedInt(ast::TyU8), - 2 => attr::UnsignedInt(ast::TyU16), - 4 => attr::UnsignedInt(ast::TyU32), + 1 => attr::UnsignedInt(ast::UintTy::U8), + 2 => attr::UnsignedInt(ast::UintTy::U16), + 4 => attr::UnsignedInt(ast::UintTy::U32), 8 if machine::llalign_of_min(cx, Type::i64(cx)) == 8 => - attr::UnsignedInt(ast::TyU64), + attr::UnsignedInt(ast::UintTy::U64), _ => min_ity // use min_ity as a fallback } } else { @@ -599,12 +599,12 @@ fn range_to_inttype(cx: &CrateContext, hint: Hint, bounds: &IntBounds) -> IntTyp // Lists of sizes to try. u64 is always allowed as a fallback. #[allow(non_upper_case_globals)] const choose_shortest: &'static [IntType] = &[ - attr::UnsignedInt(ast::TyU8), attr::SignedInt(ast::TyI8), - attr::UnsignedInt(ast::TyU16), attr::SignedInt(ast::TyI16), - attr::UnsignedInt(ast::TyU32), attr::SignedInt(ast::TyI32)]; + attr::UnsignedInt(ast::UintTy::U8), attr::SignedInt(ast::IntTy::I8), + attr::UnsignedInt(ast::UintTy::U16), attr::SignedInt(ast::IntTy::I16), + attr::UnsignedInt(ast::UintTy::U32), attr::SignedInt(ast::IntTy::I32)]; #[allow(non_upper_case_globals)] const at_least_32: &'static [IntType] = &[ - attr::UnsignedInt(ast::TyU32), attr::SignedInt(ast::TyI32)]; + attr::UnsignedInt(ast::UintTy::U32), attr::SignedInt(ast::IntTy::I32)]; let attempts; match hint { @@ -638,7 +638,7 @@ fn range_to_inttype(cx: &CrateContext, hint: Hint, bounds: &IntBounds) -> IntTyp return ity; } } - return attr::UnsignedInt(ast::TyU64); + return attr::UnsignedInt(ast::UintTy::U64); } pub fn ll_inttype(cx: &CrateContext, ity: IntType) -> Type { diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index 911229ded3d..c2d962b032f 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -816,12 +816,12 @@ pub fn llty_and_min_for_signed_ty<'blk, 'tcx>(cx: Block<'blk, 'tcx>, ty::TyInt(t) => { let llty = Type::int_from_ty(cx.ccx(), t); let min = match t { - ast::TyIs if llty == Type::i32(cx.ccx()) => i32::MIN as u64, - ast::TyIs => i64::MIN as u64, - ast::TyI8 => i8::MIN as u64, - ast::TyI16 => i16::MIN as u64, - ast::TyI32 => i32::MIN as u64, - ast::TyI64 => i64::MIN as u64, + ast::IntTy::Is if llty == Type::i32(cx.ccx()) => i32::MIN as u64, + ast::IntTy::Is => i64::MIN as u64, + ast::IntTy::I8 => i8::MIN as u64, + ast::IntTy::I16 => i16::MIN as u64, + ast::IntTy::I32 => i32::MIN as u64, + ast::IntTy::I64 => i64::MIN as u64, }; (llty, min) } diff --git a/src/librustc_trans/trans/collector.rs b/src/librustc_trans/trans/collector.rs index 1c127b90f27..8a4adf74140 100644 --- a/src/librustc_trans/trans/collector.rs +++ b/src/librustc_trans/trans/collector.rs @@ -1220,16 +1220,16 @@ pub fn push_unique_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, ty::TyBool => output.push_str("bool"), ty::TyChar => output.push_str("char"), ty::TyStr => output.push_str("str"), - ty::TyInt(ast::TyIs) => output.push_str("isize"), - ty::TyInt(ast::TyI8) => output.push_str("i8"), - ty::TyInt(ast::TyI16) => output.push_str("i16"), - ty::TyInt(ast::TyI32) => output.push_str("i32"), - ty::TyInt(ast::TyI64) => output.push_str("i64"), - ty::TyUint(ast::TyUs) => output.push_str("usize"), - ty::TyUint(ast::TyU8) => output.push_str("u8"), - ty::TyUint(ast::TyU16) => output.push_str("u16"), - ty::TyUint(ast::TyU32) => output.push_str("u32"), - ty::TyUint(ast::TyU64) => output.push_str("u64"), + ty::TyInt(ast::IntTy::Is) => output.push_str("isize"), + ty::TyInt(ast::IntTy::I8) => output.push_str("i8"), + ty::TyInt(ast::IntTy::I16) => output.push_str("i16"), + ty::TyInt(ast::IntTy::I32) => output.push_str("i32"), + ty::TyInt(ast::IntTy::I64) => output.push_str("i64"), + ty::TyUint(ast::UintTy::Us) => output.push_str("usize"), + ty::TyUint(ast::UintTy::U8) => output.push_str("u8"), + ty::TyUint(ast::UintTy::U16) => output.push_str("u16"), + ty::TyUint(ast::UintTy::U32) => output.push_str("u32"), + ty::TyUint(ast::UintTy::U64) => output.push_str("u64"), ty::TyFloat(ast::FloatTy::F32) => output.push_str("f32"), ty::TyFloat(ast::FloatTy::F64) => output.push_str("f64"), ty::TyStruct(adt_def, substs) | diff --git a/src/librustc_trans/trans/consts.rs b/src/librustc_trans/trans/consts.rs index 0d6324f3e89..329a291cd68 100644 --- a/src/librustc_trans/trans/consts.rs +++ b/src/librustc_trans/trans/consts.rs @@ -64,7 +64,7 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &ast::Lit) let _icx = push_ctxt("trans_lit"); debug!("const_lit: {:?}", lit); match lit.node { - ast::LitByte(b) => C_integral(Type::uint_from_ty(cx, ast::TyU8), b as u64, false), + ast::LitByte(b) => C_integral(Type::uint_from_ty(cx, ast::UintTy::U8), b as u64, false), ast::LitChar(i) => C_integral(Type::char(cx), i as u64, false), ast::LitInt(i, ast::SignedIntLit(t, _)) => { C_integral(Type::int_from_ty(cx, t), i, true) diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs index 34567c1178f..a09936e1220 100644 --- a/src/librustc_trans/trans/expr.rs +++ b/src/librustc_trans/trans/expr.rs @@ -2370,14 +2370,14 @@ impl OverflowOpViaIntrinsic { use middle::ty::{TyInt, TyUint}; let new_sty = match ty.sty { - TyInt(TyIs) => match &tcx.sess.target.target.target_pointer_width[..] { - "32" => TyInt(TyI32), - "64" => TyInt(TyI64), + TyInt(Is) => match &tcx.sess.target.target.target_pointer_width[..] { + "32" => TyInt(I32), + "64" => TyInt(I64), _ => panic!("unsupported target word size") }, - TyUint(TyUs) => match &tcx.sess.target.target.target_pointer_width[..] { - "32" => TyUint(TyU32), - "64" => TyUint(TyU64), + TyUint(Us) => match &tcx.sess.target.target.target_pointer_width[..] { + "32" => TyUint(U32), + "64" => TyUint(U64), _ => panic!("unsupported target word size") }, ref t @ TyUint(_) | ref t @ TyInt(_) => t.clone(), @@ -2387,41 +2387,41 @@ impl OverflowOpViaIntrinsic { match *self { OverflowOpViaIntrinsic::Add => match new_sty { - TyInt(TyI8) => "llvm.sadd.with.overflow.i8", - TyInt(TyI16) => "llvm.sadd.with.overflow.i16", - TyInt(TyI32) => "llvm.sadd.with.overflow.i32", - TyInt(TyI64) => "llvm.sadd.with.overflow.i64", + TyInt(I8) => "llvm.sadd.with.overflow.i8", + TyInt(I16) => "llvm.sadd.with.overflow.i16", + TyInt(I32) => "llvm.sadd.with.overflow.i32", + TyInt(I64) => "llvm.sadd.with.overflow.i64", - TyUint(TyU8) => "llvm.uadd.with.overflow.i8", - TyUint(TyU16) => "llvm.uadd.with.overflow.i16", - TyUint(TyU32) => "llvm.uadd.with.overflow.i32", - TyUint(TyU64) => "llvm.uadd.with.overflow.i64", + TyUint(U8) => "llvm.uadd.with.overflow.i8", + TyUint(U16) => "llvm.uadd.with.overflow.i16", + TyUint(U32) => "llvm.uadd.with.overflow.i32", + TyUint(U64) => "llvm.uadd.with.overflow.i64", _ => unreachable!(), }, OverflowOpViaIntrinsic::Sub => match new_sty { - TyInt(TyI8) => "llvm.ssub.with.overflow.i8", - TyInt(TyI16) => "llvm.ssub.with.overflow.i16", - TyInt(TyI32) => "llvm.ssub.with.overflow.i32", - TyInt(TyI64) => "llvm.ssub.with.overflow.i64", + TyInt(I8) => "llvm.ssub.with.overflow.i8", + TyInt(I16) => "llvm.ssub.with.overflow.i16", + TyInt(I32) => "llvm.ssub.with.overflow.i32", + TyInt(I64) => "llvm.ssub.with.overflow.i64", - TyUint(TyU8) => "llvm.usub.with.overflow.i8", - TyUint(TyU16) => "llvm.usub.with.overflow.i16", - TyUint(TyU32) => "llvm.usub.with.overflow.i32", - TyUint(TyU64) => "llvm.usub.with.overflow.i64", + TyUint(U8) => "llvm.usub.with.overflow.i8", + TyUint(U16) => "llvm.usub.with.overflow.i16", + TyUint(U32) => "llvm.usub.with.overflow.i32", + TyUint(U64) => "llvm.usub.with.overflow.i64", _ => unreachable!(), }, OverflowOpViaIntrinsic::Mul => match new_sty { - TyInt(TyI8) => "llvm.smul.with.overflow.i8", - TyInt(TyI16) => "llvm.smul.with.overflow.i16", - TyInt(TyI32) => "llvm.smul.with.overflow.i32", - TyInt(TyI64) => "llvm.smul.with.overflow.i64", + TyInt(I8) => "llvm.smul.with.overflow.i8", + TyInt(I16) => "llvm.smul.with.overflow.i16", + TyInt(I32) => "llvm.smul.with.overflow.i32", + TyInt(I64) => "llvm.smul.with.overflow.i64", - TyUint(TyU8) => "llvm.umul.with.overflow.i8", - TyUint(TyU16) => "llvm.umul.with.overflow.i16", - TyUint(TyU32) => "llvm.umul.with.overflow.i32", - TyUint(TyU64) => "llvm.umul.with.overflow.i64", + TyUint(U8) => "llvm.umul.with.overflow.i8", + TyUint(U16) => "llvm.umul.with.overflow.i16", + TyUint(U32) => "llvm.umul.with.overflow.i32", + TyUint(U64) => "llvm.umul.with.overflow.i64", _ => unreachable!(), }, diff --git a/src/librustc_trans/trans/intrinsic.rs b/src/librustc_trans/trans/intrinsic.rs index 3e5cd7389c4..018d4535d0c 100644 --- a/src/librustc_trans/trans/intrinsic.rs +++ b/src/librustc_trans/trans/intrinsic.rs @@ -1664,30 +1664,30 @@ fn int_type_width_signed<'tcx>(sty: &ty::TypeVariants<'tcx>, ccx: &CrateContext) use rustc::middle::ty::{TyInt, TyUint}; match *sty { TyInt(t) => Some((match t { - ast::TyIs => { + ast::IntTy::Is => { match &ccx.tcx().sess.target.target.target_pointer_width[..] { "32" => 32, "64" => 64, tws => panic!("Unsupported target word size for isize: {}", tws), } }, - ast::TyI8 => 8, - ast::TyI16 => 16, - ast::TyI32 => 32, - ast::TyI64 => 64, + ast::IntTy::I8 => 8, + ast::IntTy::I16 => 16, + ast::IntTy::I32 => 32, + ast::IntTy::I64 => 64, }, true)), TyUint(t) => Some((match t { - ast::TyUs => { + ast::UintTy::Us => { match &ccx.tcx().sess.target.target.target_pointer_width[..] { "32" => 32, "64" => 64, tws => panic!("Unsupported target word size for usize: {}", tws), } }, - ast::TyU8 => 8, - ast::TyU16 => 16, - ast::TyU32 => 32, - ast::TyU64 => 64, + ast::UintTy::U8 => 8, + ast::UintTy::U16 => 16, + ast::UintTy::U32 => 32, + ast::UintTy::U64 => 64, }, false)), _ => None, } diff --git a/src/librustc_trans/trans/meth.rs b/src/librustc_trans/trans/meth.rs index b8f577f654c..ab43861618d 100644 --- a/src/librustc_trans/trans/meth.rs +++ b/src/librustc_trans/trans/meth.rs @@ -644,7 +644,7 @@ pub fn get_vtable_methods<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn opaque_method_ty<'tcx>(tcx: &ty::ctxt<'tcx>, method_ty: &ty::BareFnTy<'tcx>) -> &'tcx ty::BareFnTy<'tcx> { let mut inputs = method_ty.sig.0.inputs.clone(); - inputs[0] = tcx.mk_mut_ptr(tcx.mk_mach_int(ast::TyI8)); + inputs[0] = tcx.mk_mut_ptr(tcx.mk_mach_int(ast::IntTy::I8)); tcx.mk_bare_fn(ty::BareFnTy { unsafety: method_ty.unsafety, diff --git a/src/librustc_trans/trans/type_.rs b/src/librustc_trans/trans/type_.rs index 5d5aa5240d6..17300f356c4 100644 --- a/src/librustc_trans/trans/type_.rs +++ b/src/librustc_trans/trans/type_.rs @@ -127,21 +127,21 @@ impl Type { pub fn int_from_ty(ccx: &CrateContext, t: ast::IntTy) -> Type { match t { - ast::TyIs => ccx.int_type(), - ast::TyI8 => Type::i8(ccx), - ast::TyI16 => Type::i16(ccx), - ast::TyI32 => Type::i32(ccx), - ast::TyI64 => Type::i64(ccx) + ast::IntTy::Is => ccx.int_type(), + ast::IntTy::I8 => Type::i8(ccx), + ast::IntTy::I16 => Type::i16(ccx), + ast::IntTy::I32 => Type::i32(ccx), + ast::IntTy::I64 => Type::i64(ccx) } } pub fn uint_from_ty(ccx: &CrateContext, t: ast::UintTy) -> Type { match t { - ast::TyUs => ccx.int_type(), - ast::TyU8 => Type::i8(ccx), - ast::TyU16 => Type::i16(ccx), - ast::TyU32 => Type::i32(ccx), - ast::TyU64 => Type::i64(ccx) + ast::UintTy::Us => ccx.int_type(), + ast::UintTy::U8 => Type::i8(ccx), + ast::UintTy::U16 => Type::i16(ccx), + ast::UintTy::U32 => Type::i32(ccx), + ast::UintTy::U64 => Type::i64(ccx) } } diff --git a/src/librustc_trans/trans/type_of.rs b/src/librustc_trans/trans/type_of.rs index d9400073685..4b5a0b05512 100644 --- a/src/librustc_trans/trans/type_of.rs +++ b/src/librustc_trans/trans/type_of.rs @@ -385,7 +385,7 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> let unsized_part = cx.tcx().struct_tail(ty); let info_ty = match unsized_part.sty { ty::TyStr | ty::TyArray(..) | ty::TySlice(_) => { - Type::uint_from_ty(cx, ast::TyUs) + Type::uint_from_ty(cx, ast::UintTy::Us) } ty::TyTrait(_) => Type::vtable_ptr(cx), _ => panic!("Unexpected type returned from \ diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 64dbe66a88f..2ea0df280db 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -248,7 +248,7 @@ impl<'tcx> CastCheck<'tcx> { (_, Int(Bool)) => Err(CastError::CastToBool), // * -> Char - (Int(U(ast::TyU8)), Int(Char)) => Ok(CastKind::U8CharCast), // u8-char-cast + (Int(U(ast::UintTy::U8)), Int(Char)) => Ok(CastKind::U8CharCast), // u8-char-cast (_, Int(Char)) => Err(CastError::CastToChar), // prim -> float,ptr diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 0f3cce18ea2..ba6fa9aed3d 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -429,14 +429,14 @@ fn match_intrinsic_type_to_type<'tcx, 'a>( }, // (The width we pass to LLVM doesn't concern the type checker.) Integer(signed, bits, _llvm_width) => match (signed, bits, &t.sty) { - (true, 8, &ty::TyInt(ast::IntTy::TyI8)) | - (false, 8, &ty::TyUint(ast::UintTy::TyU8)) | - (true, 16, &ty::TyInt(ast::IntTy::TyI16)) | - (false, 16, &ty::TyUint(ast::UintTy::TyU16)) | - (true, 32, &ty::TyInt(ast::IntTy::TyI32)) | - (false, 32, &ty::TyUint(ast::UintTy::TyU32)) | - (true, 64, &ty::TyInt(ast::IntTy::TyI64)) | - (false, 64, &ty::TyUint(ast::UintTy::TyU64)) => {}, + (true, 8, &ty::TyInt(ast::IntTy::I8)) | + (false, 8, &ty::TyUint(ast::UintTy::U8)) | + (true, 16, &ty::TyInt(ast::IntTy::I16)) | + (false, 16, &ty::TyUint(ast::UintTy::U16)) | + (true, 32, &ty::TyInt(ast::IntTy::I32)) | + (false, 32, &ty::TyUint(ast::UintTy::U32)) | + (true, 64, &ty::TyInt(ast::IntTy::I64)) | + (false, 64, &ty::TyUint(ast::UintTy::U64)) => {}, _ => simple_error(&format!("`{}`", t), &format!("`{}{n}`", if signed {"i"} else {"u"}, diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index becb0c93b26..3cf182a0d8f 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -317,43 +317,43 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> { let lang_def_id = self.tcx().lang_items.mut_ptr_impl(); self.assemble_inherent_impl_for_primitive(lang_def_id); } - ty::TyInt(ast::TyI8) => { + ty::TyInt(ast::IntTy::I8) => { let lang_def_id = self.tcx().lang_items.i8_impl(); self.assemble_inherent_impl_for_primitive(lang_def_id); } - ty::TyInt(ast::TyI16) => { + ty::TyInt(ast::IntTy::I16) => { let lang_def_id = self.tcx().lang_items.i16_impl(); self.assemble_inherent_impl_for_primitive(lang_def_id); } - ty::TyInt(ast::TyI32) => { + ty::TyInt(ast::IntTy::I32) => { let lang_def_id = self.tcx().lang_items.i32_impl(); self.assemble_inherent_impl_for_primitive(lang_def_id); } - ty::TyInt(ast::TyI64) => { + ty::TyInt(ast::IntTy::I64) => { let lang_def_id = self.tcx().lang_items.i64_impl(); self.assemble_inherent_impl_for_primitive(lang_def_id); } - ty::TyInt(ast::TyIs) => { + ty::TyInt(ast::IntTy::Is) => { let lang_def_id = self.tcx().lang_items.isize_impl(); self.assemble_inherent_impl_for_primitive(lang_def_id); } - ty::TyUint(ast::TyU8) => { + ty::TyUint(ast::UintTy::U8) => { let lang_def_id = self.tcx().lang_items.u8_impl(); self.assemble_inherent_impl_for_primitive(lang_def_id); } - ty::TyUint(ast::TyU16) => { + ty::TyUint(ast::UintTy::U16) => { let lang_def_id = self.tcx().lang_items.u16_impl(); self.assemble_inherent_impl_for_primitive(lang_def_id); } - ty::TyUint(ast::TyU32) => { + ty::TyUint(ast::UintTy::U32) => { let lang_def_id = self.tcx().lang_items.u32_impl(); self.assemble_inherent_impl_for_primitive(lang_def_id); } - ty::TyUint(ast::TyU64) => { + ty::TyUint(ast::UintTy::U64) => { let lang_def_id = self.tcx().lang_items.u64_impl(); self.assemble_inherent_impl_for_primitive(lang_def_id); } - ty::TyUint(ast::TyUs) => { + ty::TyUint(ast::UintTy::Us) => { let lang_def_id = self.tcx().lang_items.usize_impl(); self.assemble_inherent_impl_for_primitive(lang_def_id); } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 7a38a4a0cbf..066805e54a1 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2264,7 +2264,7 @@ fn try_index_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, // First, try built-in indexing. match (adjusted_ty.builtin_index(), &index_ty.sty) { - (Some(ty), &ty::TyUint(ast::TyUs)) | (Some(ty), &ty::TyInfer(ty::IntVar(_))) => { + (Some(ty), &ty::TyUint(ast::UintTy::Us)) | (Some(ty), &ty::TyInfer(ty::IntVar(_))) => { debug!("try_index_step: success, using built-in indexing"); // If we had `[T; N]`, we should've caught it before unsizing to `[T]`. assert!(!unsize); @@ -2563,14 +2563,14 @@ fn check_argument_types<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, function, cast to c_double", t) }, arg_ty, None); } - ty::TyInt(ast::TyI8) | ty::TyInt(ast::TyI16) | ty::TyBool => { + ty::TyInt(ast::IntTy::I8) | ty::TyInt(ast::IntTy::I16) | ty::TyBool => { fcx.type_error_message(arg.span, |t| { format!("can't pass {} to variadic \ function, cast to c_int", t) }, arg_ty, None); } - ty::TyUint(ast::TyU8) | ty::TyUint(ast::TyU16) => { + ty::TyUint(ast::UintTy::U8) | ty::TyUint(ast::UintTy::U16) => { fcx.type_error_message(arg.span, |t| { format!("can't pass {} to variadic \ function, cast to c_uint", @@ -4167,20 +4167,20 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, disr: ty::Disr) -> bool { fn uint_in_range(ccx: &CrateCtxt, ty: ast::UintTy, disr: ty::Disr) -> bool { match ty { - ast::TyU8 => disr as u8 as Disr == disr, - ast::TyU16 => disr as u16 as Disr == disr, - ast::TyU32 => disr as u32 as Disr == disr, - ast::TyU64 => disr as u64 as Disr == disr, - ast::TyUs => uint_in_range(ccx, ccx.tcx.sess.target.uint_type, disr) + ast::UintTy::U8 => disr as u8 as Disr == disr, + ast::UintTy::U16 => disr as u16 as Disr == disr, + ast::UintTy::U32 => disr as u32 as Disr == disr, + ast::UintTy::U64 => disr as u64 as Disr == disr, + ast::UintTy::Us => uint_in_range(ccx, ccx.tcx.sess.target.uint_type, disr) } } fn int_in_range(ccx: &CrateCtxt, ty: ast::IntTy, disr: ty::Disr) -> bool { match ty { - ast::TyI8 => disr as i8 as Disr == disr, - ast::TyI16 => disr as i16 as Disr == disr, - ast::TyI32 => disr as i32 as Disr == disr, - ast::TyI64 => disr as i64 as Disr == disr, - ast::TyIs => int_in_range(ccx, ccx.tcx.sess.target.int_type, disr) + ast::IntTy::I8 => disr as i8 as Disr == disr, + ast::IntTy::I16 => disr as i16 as Disr == disr, + ast::IntTy::I32 => disr as i32 as Disr == disr, + ast::IntTy::I64 => disr as i64 as Disr == disr, + ast::IntTy::Is => int_in_range(ccx, ccx.tcx.sess.target.int_type, disr) } } match ty { diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index e03bbfd09f2..9e966c283a0 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -121,70 +121,70 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> { "*mut T", item.span); } - ty::TyInt(ast::TyI8) => { + ty::TyInt(ast::IntTy::I8) => { self.check_primitive_impl(def_id, self.tcx.lang_items.i8_impl(), "i8", "i8", item.span); } - ty::TyInt(ast::TyI16) => { + ty::TyInt(ast::IntTy::I16) => { self.check_primitive_impl(def_id, self.tcx.lang_items.i16_impl(), "i16", "i16", item.span); } - ty::TyInt(ast::TyI32) => { + ty::TyInt(ast::IntTy::I32) => { self.check_primitive_impl(def_id, self.tcx.lang_items.i32_impl(), "i32", "i32", item.span); } - ty::TyInt(ast::TyI64) => { + ty::TyInt(ast::IntTy::I64) => { self.check_primitive_impl(def_id, self.tcx.lang_items.i64_impl(), "i64", "i64", item.span); } - ty::TyInt(ast::TyIs) => { + ty::TyInt(ast::IntTy::Is) => { self.check_primitive_impl(def_id, self.tcx.lang_items.isize_impl(), "isize", "isize", item.span); } - ty::TyUint(ast::TyU8) => { + ty::TyUint(ast::UintTy::U8) => { self.check_primitive_impl(def_id, self.tcx.lang_items.u8_impl(), "u8", "u8", item.span); } - ty::TyUint(ast::TyU16) => { + ty::TyUint(ast::UintTy::U16) => { self.check_primitive_impl(def_id, self.tcx.lang_items.u16_impl(), "u16", "u16", item.span); } - ty::TyUint(ast::TyU32) => { + ty::TyUint(ast::UintTy::U32) => { self.check_primitive_impl(def_id, self.tcx.lang_items.u32_impl(), "u32", "u32", item.span); } - ty::TyUint(ast::TyU64) => { + ty::TyUint(ast::UintTy::U64) => { self.check_primitive_impl(def_id, self.tcx.lang_items.u64_impl(), "u64", "u64", item.span); } - ty::TyUint(ast::TyUs) => { + ty::TyUint(ast::UintTy::Us) => { self.check_primitive_impl(def_id, self.tcx.lang_items.usize_impl(), "usize", diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 254106434fa..29722e5b538 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1640,16 +1640,16 @@ impl<'tcx> Clean for ty::Ty<'tcx> { match self.sty { ty::TyBool => Primitive(Bool), ty::TyChar => Primitive(Char), - ty::TyInt(ast::TyIs) => Primitive(Isize), - ty::TyInt(ast::TyI8) => Primitive(I8), - ty::TyInt(ast::TyI16) => Primitive(I16), - ty::TyInt(ast::TyI32) => Primitive(I32), - ty::TyInt(ast::TyI64) => Primitive(I64), - ty::TyUint(ast::TyUs) => Primitive(Usize), - ty::TyUint(ast::TyU8) => Primitive(U8), - ty::TyUint(ast::TyU16) => Primitive(U16), - ty::TyUint(ast::TyU32) => Primitive(U32), - ty::TyUint(ast::TyU64) => Primitive(U64), + ty::TyInt(ast::IntTy::Is) => Primitive(Isize), + ty::TyInt(ast::IntTy::I8) => Primitive(I8), + ty::TyInt(ast::IntTy::I16) => Primitive(I16), + ty::TyInt(ast::IntTy::I32) => Primitive(I32), + ty::TyInt(ast::IntTy::I64) => Primitive(I64), + ty::TyUint(ast::UintTy::Us) => Primitive(Usize), + ty::TyUint(ast::UintTy::U8) => Primitive(U8), + ty::TyUint(ast::UintTy::U16) => Primitive(U16), + ty::TyUint(ast::UintTy::U32) => Primitive(U32), + ty::TyUint(ast::UintTy::U64) => Primitive(U64), ty::TyFloat(ast::FloatTy::F32) => Primitive(F32), ty::TyFloat(ast::FloatTy::F64) => Primitive(F64), ty::TyStr => Primitive(Str), @@ -2619,16 +2619,16 @@ fn resolve_type(cx: &DocContext, hir::TyStr => return Primitive(Str), hir::TyBool => return Primitive(Bool), hir::TyChar => return Primitive(Char), - hir::TyInt(ast::TyIs) => return Primitive(Isize), - hir::TyInt(ast::TyI8) => return Primitive(I8), - hir::TyInt(ast::TyI16) => return Primitive(I16), - hir::TyInt(ast::TyI32) => return Primitive(I32), - hir::TyInt(ast::TyI64) => return Primitive(I64), - hir::TyUint(ast::TyUs) => return Primitive(Usize), - hir::TyUint(ast::TyU8) => return Primitive(U8), - hir::TyUint(ast::TyU16) => return Primitive(U16), - hir::TyUint(ast::TyU32) => return Primitive(U32), - hir::TyUint(ast::TyU64) => return Primitive(U64), + hir::TyInt(ast::IntTy::Is) => return Primitive(Isize), + hir::TyInt(ast::IntTy::I8) => return Primitive(I8), + hir::TyInt(ast::IntTy::I16) => return Primitive(I16), + hir::TyInt(ast::IntTy::I32) => return Primitive(I32), + hir::TyInt(ast::IntTy::I64) => return Primitive(I64), + hir::TyUint(ast::UintTy::Us) => return Primitive(Usize), + hir::TyUint(ast::UintTy::U8) => return Primitive(U8), + hir::TyUint(ast::UintTy::U16) => return Primitive(U16), + hir::TyUint(ast::UintTy::U32) => return Primitive(U32), + hir::TyUint(ast::UintTy::U64) => return Primitive(U64), hir::TyFloat(ast::FloatTy::F32) => return Primitive(F32), hir::TyFloat(ast::FloatTy::F64) => return Primitive(F64), }, diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index a43874f9990..dbc73f01bc2 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -11,7 +11,6 @@ // The Rust abstract syntax tree. pub use self::ForeignItem_::*; -pub use self::IntTy::*; pub use self::Item_::*; pub use self::KleeneOp::*; pub use self::Lit_::*; @@ -29,7 +28,6 @@ pub use self::StructFieldKind::*; pub use self::TraitItem_::*; pub use self::Ty_::*; pub use self::TyParamBound::*; -pub use self::UintTy::*; pub use self::UnsafeSource::*; pub use self::ViewPath_::*; pub use self::Visibility::*; @@ -1393,11 +1391,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 { @@ -1415,11 +1413,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" } } @@ -1432,41 +1430,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 { 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" } } @@ -1476,20 +1474,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 { 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, }) } } diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 746f728e096..64e6bcaa53c 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -746,16 +746,16 @@ pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec fn int_type_of_word(s: &str) -> Option { 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 +797,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 } } } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 446c90f310d..1af29f2f93a 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -680,17 +680,17 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.expr(sp, ast::ExprKind::Lit(P(respan(sp, lit)))) } fn expr_usize(&self, span: Span, i: usize) -> P { - self.expr_lit(span, ast::LitInt(i as u64, ast::UnsignedIntLit(ast::TyUs))) + self.expr_lit(span, ast::LitInt(i as u64, ast::UnsignedIntLit(ast::UintTy::Us))) } fn expr_isize(&self, sp: Span, i: isize) -> P { - self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::TyIs, + self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::IntTy::Is, ast::Sign::new(i)))) } fn expr_u32(&self, sp: Span, u: u32) -> P { - self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::TyU32))) + self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::UintTy::U32))) } fn expr_u8(&self, sp: Span, u: u8) -> P { - self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::TyU8))) + self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::UintTy::U8))) } fn expr_bool(&self, sp: Span, value: bool) -> P { self.expr_lit(sp, ast::LitBool(value)) diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index d7a47b40506..a9f480daa0e 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -279,17 +279,17 @@ pub mod rt { ); } - 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; diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index bbcb0c70ff4..2472da36d52 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -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::SignedIntLit(ast::IntTy::Is, ast::Plus), + "i8" => ast::SignedIntLit(ast::IntTy::I8, ast::Plus), + "i16" => ast::SignedIntLit(ast::IntTy::I16, ast::Plus), + "i32" => ast::SignedIntLit(ast::IntTy::I32, ast::Plus), + "i64" => ast::SignedIntLit(ast::IntTy::I64, ast::Plus), + "usize" => ast::UnsignedIntLit(ast::UintTy::Us), + "u8" => ast::UnsignedIntLit(ast::UintTy::U8), + "u16" => ast::UnsignedIntLit(ast::UintTy::U16), + "u32" => ast::UnsignedIntLit(ast::UintTy::U32), + "u64" => ast::UnsignedIntLit(ast::UintTy::U64), _ => { // i and u look like widths, so lets // give an error message along those lines diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index df73e8815ed..99db01a915e 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -27,7 +27,7 @@ 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::{Lit, Lit_, UintTy}; use ast::{LitBool, LitChar, LitByte, LitByteStr}; use ast::{LitStr, LitInt, Local}; use ast::{MacStmtWithBraces, MacStmtWithSemicolon, MacStmtWithoutBraces}; @@ -45,7 +45,7 @@ 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::{TyRptr, TyTup, TyVec}; use ast::TypeTraitItem; use ast::UnnamedField; use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple}; @@ -2017,7 +2017,7 @@ impl<'a> Parser<'a> { pub fn mk_lit_u32(&mut self, i: u32, attrs: ThinAttributes) -> P { let span = &self.span; let lv_lit = P(codemap::Spanned { - node: LitInt(i as u64, ast::UnsignedIntLit(TyU32)), + node: LitInt(i as u64, ast::UnsignedIntLit(UintTy::U32)), span: *span }); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 736af70091a..2054c0fc9bd 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -3184,8 +3184,8 @@ mod tests { #[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)); + let pos_int = ast::LitInt(42, ast::SignedIntLit(ast::IntTy::I32, ast::Plus)); + let neg_int = ast::LitInt((!42 + 1) as u64, ast::SignedIntLit(ast::IntTy::I32, 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_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 82002b0be29..950c2f48bac 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -748,17 +748,17 @@ fn find_repr_type_name(diagnostic: &Handler, attr::ReprAny | attr::ReprPacked | attr::ReprSimd => continue, attr::ReprExtern => "i32", - attr::ReprInt(_, attr::SignedInt(ast::TyIs)) => "isize", - attr::ReprInt(_, attr::SignedInt(ast::TyI8)) => "i8", - attr::ReprInt(_, attr::SignedInt(ast::TyI16)) => "i16", - attr::ReprInt(_, attr::SignedInt(ast::TyI32)) => "i32", - attr::ReprInt(_, attr::SignedInt(ast::TyI64)) => "i64", + attr::ReprInt(_, attr::SignedInt(ast::IntTy::Is)) => "isize", + attr::ReprInt(_, attr::SignedInt(ast::IntTy::I8)) => "i8", + attr::ReprInt(_, attr::SignedInt(ast::IntTy::I16)) => "i16", + attr::ReprInt(_, attr::SignedInt(ast::IntTy::I32)) => "i32", + attr::ReprInt(_, attr::SignedInt(ast::IntTy::I64)) => "i64", - attr::ReprInt(_, attr::UnsignedInt(ast::TyUs)) => "usize", - attr::ReprInt(_, attr::UnsignedInt(ast::TyU8)) => "u8", - attr::ReprInt(_, attr::UnsignedInt(ast::TyU16)) => "u16", - attr::ReprInt(_, attr::UnsignedInt(ast::TyU32)) => "u32", - attr::ReprInt(_, attr::UnsignedInt(ast::TyU64)) => "u64", + attr::ReprInt(_, attr::UnsignedInt(ast::UintTy::Us)) => "usize", + attr::ReprInt(_, attr::UnsignedInt(ast::UintTy::U8)) => "u8", + attr::ReprInt(_, attr::UnsignedInt(ast::UintTy::U16)) => "u16", + attr::ReprInt(_, attr::UnsignedInt(ast::UintTy::U32)) => "u32", + attr::ReprInt(_, attr::UnsignedInt(ast::UintTy::U64)) => "u64", } } } From bfa66bb389ce1c7ce4aff09d1842b3428015bd4d Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 11 Feb 2016 09:52:55 +0100 Subject: [PATCH 12/29] [breaking-change] remove the sign from integer literals in the ast --- src/librustc/middle/const_eval.rs | 6 ++---- src/librustc_lint/types.rs | 12 +++++------- src/librustc_trans/trans/consts.rs | 4 ++-- src/librustc_typeck/check/mod.rs | 4 ++-- src/libsyntax/ast.rs | 30 ++---------------------------- src/libsyntax/ext/build.rs | 9 +++++++-- src/libsyntax/ext/quote.rs | 24 +++++++++++++++++++++--- src/libsyntax/parse/mod.rs | 28 ++++++++++------------------ src/libsyntax/print/pprust.rs | 12 ++---------- src/libsyntax_ext/concat.rs | 8 ++------ 10 files changed, 55 insertions(+), 82 deletions(-) diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 5e3cfff086c..e8e817db7ab 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -1328,15 +1328,13 @@ fn lit_to_const(sess: &Session, span: Span, lit: &ast::Lit, ty_hint: Option) } ast::LitByte(n) => Uint(n as u64), ast::LitChar(n) => Uint(n as u64), - ast::LitInt(n, ast::SignedIntLit(_, ast::Plus)) => Int(n as i64), - ast::LitInt(n, ast::UnsuffixedIntLit(ast::Plus)) => { + ast::LitInt(n, ast::SignedIntLit(_)) => Int(n as i64), + ast::LitInt(n, ast::UnsuffixedIntLit) => { match ty_hint.map(|ty| &ty.sty) { Some(&ty::TyUint(_)) => Uint(n), _ => Int(n as i64) } } - ast::LitInt(n, ast::SignedIntLit(_, ast::Minus)) | - ast::LitInt(n, ast::UnsuffixedIntLit(ast::Minus)) => Int(-(n as i64)), ast::LitInt(n, ast::UnsignedIntLit(_)) => Uint(n), ast::LitFloat(ref n, _) | ast::LitFloatUnsuffixed(ref n) => { diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index bd5f237cbfb..9993234c36a 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -106,7 +106,7 @@ impl LateLintPass for TypeLimits { ast::LitInt(_, ast::UnsignedIntLit(_)) => { forbid_unsigned_negation(cx, e.span); }, - ast::LitInt(_, ast::UnsuffixedIntLit(_)) => { + ast::LitInt(_, ast::UnsuffixedIntLit) => { if let ty::TyUint(_) = cx.tcx.node_id_to_type(e.id).sty { forbid_unsigned_negation(cx, e.span); } @@ -159,8 +159,8 @@ impl LateLintPass for TypeLimits { match cx.tcx.node_id_to_type(e.id).sty { ty::TyInt(t) => { match lit.node { - ast::LitInt(v, ast::SignedIntLit(_, ast::Plus)) | - ast::LitInt(v, ast::UnsuffixedIntLit(ast::Plus)) => { + ast::LitInt(v, ast::SignedIntLit(_)) | + ast::LitInt(v, ast::UnsuffixedIntLit) => { let int_type = if let ast::IntTy::Is = t { cx.sess().target.int_type } else { @@ -311,10 +311,8 @@ impl LateLintPass for TypeLimits { let (min, max) = int_ty_range(int_ty); let lit_val: i64 = match lit.node { hir::ExprLit(ref li) => match li.node { - ast::LitInt(v, ast::SignedIntLit(_, ast::Plus)) | - ast::LitInt(v, ast::UnsuffixedIntLit(ast::Plus)) => v as i64, - ast::LitInt(v, ast::SignedIntLit(_, ast::Minus)) | - ast::LitInt(v, ast::UnsuffixedIntLit(ast::Minus)) => -(v as i64), + ast::LitInt(v, ast::SignedIntLit(_)) | + ast::LitInt(v, ast::UnsuffixedIntLit) => v as i64, _ => return true }, _ => panic!() diff --git a/src/librustc_trans/trans/consts.rs b/src/librustc_trans/trans/consts.rs index 329a291cd68..81df4746d10 100644 --- a/src/librustc_trans/trans/consts.rs +++ b/src/librustc_trans/trans/consts.rs @@ -66,13 +66,13 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &ast::Lit) match lit.node { ast::LitByte(b) => C_integral(Type::uint_from_ty(cx, ast::UintTy::U8), b as u64, false), ast::LitChar(i) => C_integral(Type::char(cx), i as u64, false), - ast::LitInt(i, ast::SignedIntLit(t, _)) => { + ast::LitInt(i, ast::SignedIntLit(t)) => { C_integral(Type::int_from_ty(cx, t), i, true) } ast::LitInt(u, ast::UnsignedIntLit(t)) => { C_integral(Type::uint_from_ty(cx, t), u, false) } - ast::LitInt(i, ast::UnsuffixedIntLit(_)) => { + ast::LitInt(i, ast::UnsuffixedIntLit) => { let lit_int_ty = cx.tcx().node_id_to_type(e.id); match lit_int_ty.sty { ty::TyInt(t) => { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 066805e54a1..176f9bcd4f6 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2613,9 +2613,9 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, } ast::LitByte(_) => tcx.types.u8, ast::LitChar(_) => tcx.types.char, - ast::LitInt(_, ast::SignedIntLit(t, _)) => tcx.mk_mach_int(t), + ast::LitInt(_, ast::SignedIntLit(t)) => tcx.mk_mach_int(t), ast::LitInt(_, ast::UnsignedIntLit(t)) => tcx.mk_mach_uint(t), - ast::LitInt(_, ast::UnsuffixedIntLit(_)) => { + ast::LitInt(_, ast::UnsuffixedIntLit) => { let opt_ty = expected.to_option(fcx).and_then(|ty| { match ty.sty { ty::TyInt(_) | ty::TyUint(_) => Some(ty), diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index dbc73f01bc2..464e9da3724 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -21,7 +21,6 @@ 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::*; @@ -1269,36 +1268,11 @@ pub enum StrStyle { /// A literal pub type Lit = Spanned; -#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] -pub enum Sign { - Minus, - Plus -} - -impl Sign { - pub fn new(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 } - #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub enum LitIntType { - SignedIntLit(IntTy, Sign), + SignedIntLit(IntTy), UnsignedIntLit(UintTy), - UnsuffixedIntLit(Sign) + UnsuffixedIntLit, } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 1af29f2f93a..1c2d1cebf3d 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -683,8 +683,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.expr_lit(span, ast::LitInt(i as u64, ast::UnsignedIntLit(ast::UintTy::Us))) } fn expr_isize(&self, sp: Span, i: isize) -> P { - self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::IntTy::Is, - ast::Sign::new(i)))) + if i < 0 { + let i = (-i) as u64; + let lit = self.expr_lit(sp, ast::LitInt(i, ast::SignedIntLit(ast::IntTy::Is))); + self.expr_unary(sp, ast::UnOp::Neg, lit) + } else { + self.expr_lit(sp, ast::LitInt(i as u64, ast::SignedIntLit(ast::IntTy::Is))) + } } fn expr_u32(&self, sp: Span, u: u32) -> P { self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::UintTy::U32))) diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index a9f480daa0e..dfe3f8e3c54 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -263,9 +263,27 @@ pub mod rt { (signed, $t:ty, $tag:expr) => ( impl ToTokens for $t { fn to_tokens(&self, cx: &ExtCtxt) -> Vec { - 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::LitInt(val as u64, ast::SignedIntLit($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) } } ); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 2472da36d52..d800b6925c0 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -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::UnsuffixedIntLit; if char_at(s, 0) == '0' && s.len() > 1 { match char_at(s, 1) { @@ -618,11 +618,11 @@ 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::IntTy::Is, ast::Plus), - "i8" => ast::SignedIntLit(ast::IntTy::I8, ast::Plus), - "i16" => ast::SignedIntLit(ast::IntTy::I16, ast::Plus), - "i32" => ast::SignedIntLit(ast::IntTy::I32, ast::Plus), - "i64" => ast::SignedIntLit(ast::IntTy::I64, ast::Plus), + "isize" => ast::SignedIntLit(ast::IntTy::Is), + "i8" => ast::SignedIntLit(ast::IntTy::I8), + "i16" => ast::SignedIntLit(ast::IntTy::I16), + "i32" => ast::SignedIntLit(ast::IntTy::I32), + "i64" => ast::SignedIntLit(ast::IntTy::I64), "usize" => ast::UnsignedIntLit(ast::UintTy::Us), "u8" => ast::UnsignedIntLit(ast::UintTy::U8), "u16" => ast::UnsignedIntLit(ast::UintTy::U16), @@ -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::LitInt(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::LitInt(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) } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 2054c0fc9bd..a02a7d47d32 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -645,24 +645,16 @@ pub trait PrintState<'a> { } ast::LitInt(i, t) => { match t { - ast::SignedIntLit(st, ast::Plus) => { + ast::SignedIntLit(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) => { word(self.writer(), &ut.val_to_string(i)) } - ast::UnsuffixedIntLit(ast::Plus) => { + ast::UnsuffixedIntLit => { word(self.writer(), &format!("{}", i)) } - ast::UnsuffixedIntLit(ast::Minus) => { - word(self.writer(), &format!("-{}", i)) - } } } ast::LitFloat(ref f, t) => { diff --git a/src/libsyntax_ext/concat.rs b/src/libsyntax_ext/concat.rs index f5c2805c4ca..9f6cf73ed64 100644 --- a/src/libsyntax_ext/concat.rs +++ b/src/libsyntax_ext/concat.rs @@ -38,14 +38,10 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, accumulator.push(c); } ast::LitInt(i, ast::UnsignedIntLit(_)) | - ast::LitInt(i, ast::SignedIntLit(_, ast::Plus)) | - ast::LitInt(i, ast::UnsuffixedIntLit(ast::Plus)) => { + ast::LitInt(i, ast::SignedIntLit(_)) | + ast::LitInt(i, ast::UnsuffixedIntLit) => { accumulator.push_str(&format!("{}", i)); } - ast::LitInt(i, ast::SignedIntLit(_, ast::Minus)) | - ast::LitInt(i, ast::UnsuffixedIntLit(ast::Minus)) => { - accumulator.push_str(&format!("-{}", i)); - } ast::LitBool(b) => { accumulator.push_str(&format!("{}", b)); } From 08e35d4deca064cbe079ee278aab49efff16f7da Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Wed, 23 Dec 2015 22:29:43 +0100 Subject: [PATCH 13/29] remove unit test that can't be tested anymore --- src/libsyntax/print/pprust.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index a02a7d47d32..1df73014b85 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -3173,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::IntTy::I32, ast::Plus)); - let neg_int = ast::LitInt((!42 + 1) as u64, ast::SignedIntLit(ast::IntTy::I32, ast::Minus)); - assert_eq!(format!("-{}", lit_to_string(&codemap::dummy_spanned(pos_int))), - lit_to_string(&codemap::dummy_spanned(neg_int))); - } } From ec61e632c0a00ccc2ca0494d5d3c8a0848c574f2 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 8 Feb 2016 16:35:20 +0100 Subject: [PATCH 14/29] [breaking-change] remove unused enum ast::PrimTy --- src/libsyntax/ast.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 464e9da3724..d06ed4be978 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -20,7 +20,6 @@ pub use self::MetaItem_::*; pub use self::Mutability::*; pub use self::Pat_::*; pub use self::PathListItem_::*; -pub use self::PrimTy::*; pub use self::Stmt_::*; pub use self::StrStyle::*; pub use self::StructFieldKind::*; @@ -1534,17 +1533,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, From 05d4cefd630cd9ae104555e69ceb3b1566298a6a Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 8 Feb 2016 16:53:21 +0100 Subject: [PATCH 15/29] [breaking-change] don't pub export ast::Ty_ variants --- src/librustc_front/lowering.rs | 27 ++++++------ src/librustc_trans/save/dump_csv.rs | 2 +- src/librustc_trans/save/mod.rs | 2 +- src/libsyntax/ast.rs | 35 ++++++++-------- src/libsyntax/diagnostics/plugin.rs | 4 +- src/libsyntax/ext/base.rs | 2 +- src/libsyntax/ext/build.rs | 14 +++---- src/libsyntax/ext/expand.rs | 4 +- src/libsyntax/fold.rs | 42 +++++++++---------- src/libsyntax/parse/mod.rs | 2 +- src/libsyntax/parse/parser.rs | 50 +++++++++++------------ src/libsyntax/print/pprust.rs | 30 +++++++------- src/libsyntax/test.rs | 8 ++-- src/libsyntax/visit.rs | 24 +++++------ src/libsyntax_ext/deriving/generic/mod.rs | 4 +- src/libsyntax_ext/deriving/generic/ty.rs | 2 +- src/libsyntax_ext/format.rs | 2 +- 17 files changed, 126 insertions(+), 128 deletions(-) diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index fe44ba7a646..813a7f71fe9 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -268,16 +268,17 @@ pub fn lower_ty_binding(lctx: &LoweringContext, b: &TypeBinding) -> hir::TypeBin } pub fn lower_ty(lctx: &LoweringContext, t: &Ty) -> P { + use syntax::ast::TyKind::*; P(hir::Ty { id: t.id, node: match t.node { - TyInfer => hir::TyInfer, - TyVec(ref ty) => hir::TyVec(lower_ty(lctx, ty)), - TyPtr(ref mt) => hir::TyPtr(lower_mt(lctx, mt)), - TyRptr(ref region, ref mt) => { + Infer => hir::TyInfer, + Vec(ref ty) => hir::TyVec(lower_ty(lctx, ty)), + Ptr(ref mt) => hir::TyPtr(lower_mt(lctx, mt)), + Rptr(ref region, ref mt) => { hir::TyRptr(lower_opt_lifetime(lctx, region), lower_mt(lctx, mt)) } - TyBareFn(ref f) => { + BareFn(ref f) => { hir::TyBareFn(P(hir::BareFnTy { lifetimes: lower_lifetime_defs(lctx, &f.lifetimes), unsafety: lower_unsafety(lctx, f.unsafety), @@ -285,11 +286,11 @@ pub fn lower_ty(lctx: &LoweringContext, t: &Ty) -> P { decl: lower_fn_decl(lctx, &f.decl), })) } - TyTup(ref tys) => hir::TyTup(tys.iter().map(|ty| lower_ty(lctx, ty)).collect()), - TyParen(ref ty) => { + Tup(ref tys) => hir::TyTup(tys.iter().map(|ty| lower_ty(lctx, ty)).collect()), + Paren(ref ty) => { return lower_ty(lctx, ty); } - TyPath(ref qself, ref path) => { + Path(ref qself, ref path) => { let qself = qself.as_ref().map(|&QSelf { ref ty, position }| { hir::QSelf { ty: lower_ty(lctx, ty), @@ -298,19 +299,19 @@ pub fn lower_ty(lctx: &LoweringContext, t: &Ty) -> P { }); hir::TyPath(qself, lower_path(lctx, path)) } - TyObjectSum(ref ty, ref bounds) => { + ObjectSum(ref ty, ref bounds) => { hir::TyObjectSum(lower_ty(lctx, ty), lower_bounds(lctx, bounds)) } - TyFixedLengthVec(ref ty, ref e) => { + FixedLengthVec(ref ty, ref e) => { hir::TyFixedLengthVec(lower_ty(lctx, ty), lower_expr(lctx, e)) } - TyTypeof(ref expr) => { + Typeof(ref expr) => { hir::TyTypeof(lower_expr(lctx, expr)) } - TyPolyTraitRef(ref bounds) => { + PolyTraitRef(ref bounds) => { hir::TyPolyTraitRef(bounds.iter().map(|b| lower_ty_param_bound(lctx, b)).collect()) } - TyMac(_) => panic!("TyMac should have been expanded by now."), + Mac(_) => panic!("TyMac should have been expanded by now."), }, span: t.span, }) diff --git a/src/librustc_trans/save/dump_csv.rs b/src/librustc_trans/save/dump_csv.rs index e8a0e4a8d42..10840933c01 100644 --- a/src/librustc_trans/save/dump_csv.rs +++ b/src/librustc_trans/save/dump_csv.rs @@ -1063,7 +1063,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> { fn visit_ty(&mut self, t: &ast::Ty) { self.process_macro_use(t.span, t.id); match t.node { - ast::TyPath(_, ref path) => { + ast::TyKind::Path(_, ref path) => { match self.lookup_type_ref(t.id) { Some(id) => { let sub_span = self.span.sub_span_for_type_name(t.span); diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs index 116051f6fe5..53fa1bfff38 100644 --- a/src/librustc_trans/save/mod.rs +++ b/src/librustc_trans/save/mod.rs @@ -316,7 +316,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { match typ.node { // Common case impl for a struct or something basic. - ast::TyPath(None, ref path) => { + ast::TyKind::Path(None, ref path) => { sub_span = self.span_utils.sub_span_for_type_name(path.span); filter!(self.span_utils, sub_span, path.span, None); type_data = self.lookup_ref_id(typ.id).map(|id| { diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index d06ed4be978..5752cbda9b9 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -24,7 +24,6 @@ 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::UnsafeSource::*; pub use self::ViewPath_::*; @@ -1523,7 +1522,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, } @@ -1543,36 +1542,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), +pub enum TyKind { + Vec(P), /// A fixed length array (`[T; n]`) - TyFixedLengthVec(P, P), + FixedLengthVec(P, P), /// A raw pointer (`*const T` or `*mut T`) - TyPtr(MutTy), + Ptr(MutTy), /// A reference (`&'a T` or `&'a mut T`) - TyRptr(Option, MutTy), + Rptr(Option, MutTy), /// A bare function (e.g. `fn(usize) -> bool`) - TyBareFn(P), + BareFn(P), /// A tuple (`(A, B, C, D,...)`) - TyTup(Vec> ), + Tup(Vec> ), /// A path (`module::module::...::Type`), optionally /// "qualified", e.g. ` as SomeTrait>::SomeType`. /// /// Type parameters are stored in the Path itself - TyPath(Option, Path), + Path(Option, Path), /// Something like `A+B`. Note that `B` must always be a path. - TyObjectSum(P, TyParamBounds), + ObjectSum(P, 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), + Paren(P), /// Unused for now - TyTypeof(P), - /// TyInfer means the type should be inferred instead of it having been + Typeof(P), + /// 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)] @@ -1617,7 +1616,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 { diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 6e389e83591..4e6fde10ade 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -212,10 +212,10 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, 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), ), diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 33414a697a7..b58f8007e0a 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -367,7 +367,7 @@ impl DummyResult { pub fn raw_ty(sp: Span) -> P { P(ast::Ty { id: ast::DUMMY_NODE_ID, - node: ast::TyInfer, + node: ast::TyKind::Infer, span: sp }) } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 1c2d1cebf3d..241ea976eee 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -52,7 +52,7 @@ pub trait AstBuilder { // types fn ty_mt(&self, ty: P, mutbl: ast::Mutability) -> ast::MutTy; - fn ty(&self, span: Span, ty: ast::Ty_) -> P; + fn ty(&self, span: Span, ty: ast::TyKind) -> P; fn ty_path(&self, ast::Path) -> P; fn ty_sum(&self, ast::Path, ast::TyParamBounds) -> P; fn ty_ident(&self, span: Span, idents: ast::Ident) -> P; @@ -385,7 +385,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } } - fn ty(&self, span: Span, ty: ast::Ty_) -> P { + fn ty(&self, span: Span, ty: ast::TyKind) -> P { P(ast::Ty { id: ast::DUMMY_NODE_ID, span: span, @@ -394,12 +394,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn ty_path(&self, path: ast::Path) -> P { - 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 { self.ty(path.span, - ast::TyObjectSum(self.ty_path(path), + ast::TyKind::ObjectSum(self.ty_path(path), bounds)) } @@ -417,7 +417,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { mutbl: ast::Mutability) -> P { self.ty(span, - ast::TyRptr(lifetime, self.ty_mt(ty, mutbl))) + ast::TyKind::Rptr(lifetime, self.ty_mt(ty, mutbl))) } fn ty_ptr(&self, @@ -426,7 +426,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { mutbl: ast::Mutability) -> P { self.ty(span, - ast::TyPtr(self.ty_mt(ty, mutbl))) + ast::TyKind::Ptr(self.ty_mt(ty, mutbl))) } fn ty_option(&self, ty: P) -> P { @@ -440,7 +440,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn ty_infer(&self, span: Span) -> P { - self.ty(span, ast::TyInfer) + self.ty(span, ast::TyKind::Infer) } fn typaram(&self, diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 69b932aa72b..9b31465b547 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -562,7 +562,7 @@ fn expand_non_macro_stmt(Spanned {node, span: stmt_span}: Stmt, fld: &mut MacroE 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): @@ -1133,7 +1133,7 @@ fn expand_and_rename_method(sig: ast::MethodSig, body: P, pub fn expand_type(t: P, fld: &mut MacroExpander) -> P { 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(), diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 8cd2d24102f..1a6171e1981 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -380,46 +380,46 @@ pub fn noop_fold_ty(t: P, fld: &mut T) -> P { 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) diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index d800b6925c0..d467405e089 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -916,7 +916,7 @@ mod tests { node: ast::ItemFn(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!( diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 99db01a915e..1a8b1cbc374 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -42,10 +42,7 @@ use ast::{StmtExpr, StmtSemi, StmtMac, 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, TyVec}; +use ast::{Ty, TyKind, TypeBinding, TyParam, TyParamBounds}; use ast::TypeTraitItem; use ast::UnnamedField; use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple}; @@ -1058,7 +1055,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. @@ -1097,16 +1094,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) -> PResult<'a, Ty_> { + /// parse a TyKind::BareFn type: + pub fn parse_ty_bare_fn(&mut self, lifetime_defs: Vec) + -> PResult<'a, TyKind> { /* [unsafe] [extern "ABI"] fn <'lt> (S) -> T @@ -1134,7 +1132,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, @@ -1308,7 +1306,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})) } @@ -1339,14 +1337,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))); @@ -1355,8 +1353,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 @@ -1376,13 +1374,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() { @@ -1395,14 +1393,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); @@ -1413,12 +1411,12 @@ 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> { @@ -1498,7 +1496,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), }) }; @@ -4809,7 +4807,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, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 1df73014b85..1e57d347f5a 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -957,12 +957,12 @@ 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")), @@ -970,12 +970,12 @@ impl<'a> State<'a> { } 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))); @@ -984,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(), @@ -1005,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)); } } @@ -2959,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 diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index dbdc1bfcbaa..24890d2cbed 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -358,7 +358,7 @@ fn is_test_fn(cx: &TestCtxt, i: &ast::Item) -> bool { ast::ItemFn(ref decl, _, _, _, ref generics, _) => { let no_output = match decl.output { ast::FunctionRetTy::Default(..) => true, - ast::FunctionRetTy::Ty(ref t) if t.node == ast::TyTup(vec![]) => true, + ast::FunctionRetTy::Ty(ref t) if t.node == ast::TyKind::Tup(vec![]) => true, _ => false }; if decl.inputs.is_empty() @@ -395,7 +395,7 @@ fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool { let input_cnt = decl.inputs.len(); let no_output = match decl.output { ast::FunctionRetTy::Default(..) => true, - ast::FunctionRetTy::Ty(ref t) if t.node == ast::TyTup(vec![]) => true, + ast::FunctionRetTy::Ty(ref t) if t.node == ast::TyKind::Tup(vec![]) => true, _ => false }; let tparm_cnt = generics.ty_params.len(); @@ -494,7 +494,7 @@ fn mk_main(cx: &mut TestCtxt) -> P { 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), ast::Unsafety::Normal, @@ -591,7 +591,7 @@ fn mk_tests(cx: &TestCtxt) -> P { 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); // static TESTS: $static_type = &[...]; diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 90cc403961e..44b3e581849 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -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) } } diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 950c2f48bac..e54ff637f25 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -354,7 +354,7 @@ fn find_type_parameters(ty: &ast::Ty, ty_param_names: &[ast::Name]) -> Vec visit::Visitor<'a> for Visitor<'a> { fn visit_ty(&mut self, ty: &'a ast::Ty) { match ty.node { - ast::TyPath(_, ref path) if !path.global => { + ast::TyKind::Path(_, ref path) if !path.global => { match path.segments.first() { Some(segment) => { if self.ty_param_names.contains(&segment.identifier.name) { @@ -557,7 +557,7 @@ impl<'a> TraitDef<'a> { for ty in tys { // if we have already handled this type, skip it - if let ast::TyPath(_, ref p) = ty.node { + if let ast::TyKind::Path(_, ref p) = ty.node { if p.segments.len() == 1 && ty_param_names.contains(&p.segments[0].identifier.name) || processed_field_types.contains(&p.segments) { diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index 543beeb5da0..e5b82fa1afc 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -153,7 +153,7 @@ impl<'a> Ty<'a> { cx.ty_path(self.to_path(cx, span, self_ty, self_generics)) } Tuple(ref fields) => { - let ty = ast::TyTup(fields.iter() + let ty = ast::TyKind::Tup(fields.iter() .map(|f| f.to_ty(cx, span, self_ty, self_generics)) .collect()); cx.ty(span, ty) diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index 986cdef49b2..21b32153ed9 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -448,7 +448,7 @@ impl<'a, 'b> Context<'a, 'b> { -> P { let sp = piece_ty.span; let ty = ecx.ty_rptr(sp, - ecx.ty(sp, ast::TyVec(piece_ty)), + ecx.ty(sp, ast::TyKind::Vec(piece_ty)), Some(ecx.lifetime(sp, special_idents::static_lifetime.name)), ast::MutImmutable); let slice = ecx.expr_vec_slice(sp, pieces); From 69072c4f5d18d7a1762fbfb007b0ba3d6b59ad33 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 8 Feb 2016 17:06:20 +0100 Subject: [PATCH 16/29] [breaking-change] don't pub export ast::Lit_ variants --- src/librustc/middle/check_match.rs | 2 +- src/librustc/middle/const_eval.rs | 20 ++++++++++---------- src/librustc_back/svh.rs | 2 +- src/librustc_driver/lib.rs | 2 +- src/librustc_lint/builtin.rs | 2 +- src/librustc_lint/types.rs | 25 +++++++++++++------------ src/librustc_metadata/encoder.rs | 2 +- src/librustc_trans/trans/consts.rs | 22 +++++++++++----------- src/librustc_trans/trans/expr.rs | 2 +- src/librustc_trans/trans/tvec.rs | 6 +++--- src/librustc_typeck/check/_match.rs | 2 +- src/librustc_typeck/check/mod.rs | 20 ++++++++++---------- src/librustdoc/clean/mod.rs | 16 ++++++++-------- src/libsyntax/ast.rs | 25 ++++++++++++------------- src/libsyntax/attr.rs | 6 +++--- src/libsyntax/ext/base.rs | 4 ++-- src/libsyntax/ext/build.rs | 23 ++++++++++++----------- src/libsyntax/ext/quote.rs | 10 +++++----- src/libsyntax/ext/source_util.rs | 2 +- src/libsyntax/parse/attr.rs | 2 +- src/libsyntax/parse/mod.rs | 18 +++++++++--------- src/libsyntax/parse/parser.rs | 27 +++++++++++++-------------- src/libsyntax/print/pprust.rs | 16 ++++++++-------- src/libsyntax_ext/concat.rs | 20 ++++++++++---------- src/libsyntax_ext/deriving/debug.rs | 6 +++--- src/libsyntax_ext/format.rs | 2 +- 26 files changed, 142 insertions(+), 142 deletions(-) diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index fa09c9d2bb6..62b6279bb33 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -421,7 +421,7 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix, source: hir: fn const_val_to_expr(value: &ConstVal) -> P { let node = match value { - &ConstVal::Bool(b) => ast::LitBool(b), + &ConstVal::Bool(b) => ast::LitKind::Bool(b), _ => unreachable!() }; P(hir::Expr { diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index e8e817db7ab..80adc3e6fc6 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -1322,22 +1322,22 @@ fn cast_const<'tcx>(tcx: &ty::ctxt<'tcx>, val: ConstVal, ty: Ty) -> CastResult { fn lit_to_const(sess: &Session, span: Span, lit: &ast::Lit, ty_hint: Option) -> ConstVal { match lit.node { - ast::LitStr(ref s, _) => Str((*s).clone()), - ast::LitByteStr(ref data) => { + ast::LitKind::Str(ref s, _) => Str((*s).clone()), + ast::LitKind::ByteStr(ref data) => { ByteStr(data.clone()) } - ast::LitByte(n) => Uint(n as u64), - ast::LitChar(n) => Uint(n as u64), - ast::LitInt(n, ast::SignedIntLit(_)) => Int(n as i64), - ast::LitInt(n, ast::UnsuffixedIntLit) => { + ast::LitKind::Byte(n) => Uint(n as u64), + ast::LitKind::Char(n) => Uint(n as u64), + ast::LitKind::Int(n, ast::SignedIntLit(_)) => Int(n as i64), + ast::LitKind::Int(n, ast::UnsuffixedIntLit) => { match ty_hint.map(|ty| &ty.sty) { Some(&ty::TyUint(_)) => Uint(n), _ => Int(n as i64) } } - ast::LitInt(n, ast::UnsignedIntLit(_)) => Uint(n), - ast::LitFloat(ref n, _) | - ast::LitFloatUnsuffixed(ref n) => { + ast::LitKind::Int(n, ast::UnsignedIntLit(_)) => Uint(n), + ast::LitKind::Float(ref n, _) | + ast::LitKind::FloatUnsuffixed(ref n) => { if let Ok(x) = n.parse::() { Float(x) } else { @@ -1345,7 +1345,7 @@ fn lit_to_const(sess: &Session, span: Span, lit: &ast::Lit, ty_hint: Option) sess.span_bug(span, "could not evaluate float literal (see issue #31407)"); } } - ast::LitBool(b) => Bool(b) + ast::LitKind::Bool(b) => Bool(b) } } diff --git a/src/librustc_back/svh.rs b/src/librustc_back/svh.rs index 2532882d012..b2911630991 100644 --- a/src/librustc_back/svh.rs +++ b/src/librustc_back/svh.rs @@ -232,7 +232,7 @@ mod svh_visitor { SawExprTup, SawExprBinary(hir::BinOp_), SawExprUnary(hir::UnOp), - SawExprLit(ast::Lit_), + SawExprLit(ast::LitKind), SawExprCast, SawExprType, SawExprIf, diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index efc2dc2814a..c0e935f7952 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -563,7 +563,7 @@ impl RustcDefaultCalls { ast::MetaWord(ref word) => println!("{}", word), ast::MetaNameValue(ref name, ref value) => { println!("{}=\"{}\"", name, match value.node { - ast::LitStr(ref s, _) => s, + ast::LitKind::Str(ref s, _) => s, _ => continue, }); } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 09cdab33c84..d90e145454c 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -73,7 +73,7 @@ impl LateLintPass for WhileTrue { fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) { if let hir::ExprWhile(ref cond, _, _) = e.node { if let hir::ExprLit(ref lit) = cond.node { - if let ast::LitBool(true) = lit.node { + if let ast::LitKind::Bool(true) = lit.node { cx.span_lint(WHILE_TRUE, e.span, "denote infinite loops with loop { ... }"); } diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 9993234c36a..11469f43140 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -103,10 +103,10 @@ impl LateLintPass for TypeLimits { hir::ExprUnary(hir::UnNeg, ref expr) => { if let hir::ExprLit(ref lit) = expr.node { match lit.node { - ast::LitInt(_, ast::UnsignedIntLit(_)) => { + ast::LitKind::Int(_, ast::UnsignedIntLit(_)) => { forbid_unsigned_negation(cx, e.span); }, - ast::LitInt(_, ast::UnsuffixedIntLit) => { + ast::LitKind::Int(_, ast::UnsuffixedIntLit) => { if let ty::TyUint(_) = cx.tcx.node_id_to_type(e.id).sty { forbid_unsigned_negation(cx, e.span); } @@ -139,7 +139,7 @@ impl LateLintPass for TypeLimits { if let Some(bits) = opt_ty_bits { let exceeding = if let hir::ExprLit(ref lit) = r.node { - if let ast::LitInt(shift, _) = lit.node { shift >= bits } + if let ast::LitKind::Int(shift, _) = lit.node { shift >= bits } else { false } } else { match eval_const_expr_partial(cx.tcx, &r, ExprTypeChecked, None) { @@ -159,8 +159,8 @@ impl LateLintPass for TypeLimits { match cx.tcx.node_id_to_type(e.id).sty { ty::TyInt(t) => { match lit.node { - ast::LitInt(v, ast::SignedIntLit(_)) | - ast::LitInt(v, ast::UnsuffixedIntLit) => { + ast::LitKind::Int(v, ast::SignedIntLit(_)) | + ast::LitKind::Int(v, ast::UnsuffixedIntLit) => { let int_type = if let ast::IntTy::Is = t { cx.sess().target.int_type } else { @@ -189,8 +189,9 @@ impl LateLintPass for TypeLimits { }; let (min, max) = uint_ty_range(uint_type); let lit_val: u64 = match lit.node { - ast::LitByte(_v) => return, // _v is u8, within range by definition - ast::LitInt(v, _) => v, + // _v is u8, within range by definition + ast::LitKind::Byte(_v) => return, + ast::LitKind::Int(v, _) => v, _ => panic!() }; if lit_val < min || lit_val > max { @@ -201,8 +202,8 @@ impl LateLintPass for TypeLimits { ty::TyFloat(t) => { let (min, max) = float_ty_range(t); let lit_val: f64 = match lit.node { - ast::LitFloat(ref v, _) | - ast::LitFloatUnsuffixed(ref v) => { + ast::LitKind::Float(ref v, _) | + ast::LitKind::FloatUnsuffixed(ref v) => { match v.parse() { Ok(f) => f, Err(_) => return @@ -311,8 +312,8 @@ impl LateLintPass for TypeLimits { let (min, max) = int_ty_range(int_ty); let lit_val: i64 = match lit.node { hir::ExprLit(ref li) => match li.node { - ast::LitInt(v, ast::SignedIntLit(_)) | - ast::LitInt(v, ast::UnsuffixedIntLit) => v as i64, + ast::LitKind::Int(v, ast::SignedIntLit(_)) | + ast::LitKind::Int(v, ast::UnsuffixedIntLit) => v as i64, _ => return true }, _ => panic!() @@ -323,7 +324,7 @@ impl LateLintPass for TypeLimits { let (min, max): (u64, u64) = uint_ty_range(uint_ty); let lit_val: u64 = match lit.node { hir::ExprLit(ref li) => match li.node { - ast::LitInt(v, _) => v, + ast::LitKind::Int(v, _) => v, _ => return true }, _ => panic!() diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index bcc506e96bb..9afbe5f1dbb 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -1548,7 +1548,7 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) { } ast::MetaNameValue(ref name, ref value) => { match value.node { - ast::LitStr(ref value, _) => { + ast::LitKind::Str(ref value, _) => { rbml_w.start_tag(tag_meta_item_name_value); rbml_w.wr_tagged_str(tag_meta_item_name, name); rbml_w.wr_tagged_str(tag_meta_item_value, value); diff --git a/src/librustc_trans/trans/consts.rs b/src/librustc_trans/trans/consts.rs index 81df4746d10..f6bee7c2696 100644 --- a/src/librustc_trans/trans/consts.rs +++ b/src/librustc_trans/trans/consts.rs @@ -52,7 +52,7 @@ use rustc_front::hir; use std::ffi::{CStr, CString}; use std::borrow::Cow; use libc::c_uint; -use syntax::ast; +use syntax::ast::{self, LitKind}; use syntax::attr; use syntax::parse::token; use syntax::ptr::P; @@ -64,15 +64,15 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &ast::Lit) let _icx = push_ctxt("trans_lit"); debug!("const_lit: {:?}", lit); match lit.node { - ast::LitByte(b) => C_integral(Type::uint_from_ty(cx, ast::UintTy::U8), b as u64, false), - ast::LitChar(i) => C_integral(Type::char(cx), i as u64, false), - ast::LitInt(i, ast::SignedIntLit(t)) => { + LitKind::Byte(b) => C_integral(Type::uint_from_ty(cx, ast::UintTy::U8), b as u64, false), + LitKind::Char(i) => C_integral(Type::char(cx), i as u64, false), + LitKind::Int(i, ast::SignedIntLit(t)) => { C_integral(Type::int_from_ty(cx, t), i, true) } - ast::LitInt(u, ast::UnsignedIntLit(t)) => { + LitKind::Int(u, ast::UnsignedIntLit(t)) => { C_integral(Type::uint_from_ty(cx, t), u, false) } - ast::LitInt(i, ast::UnsuffixedIntLit) => { + LitKind::Int(i, ast::UnsuffixedIntLit) => { let lit_int_ty = cx.tcx().node_id_to_type(e.id); match lit_int_ty.sty { ty::TyInt(t) => { @@ -87,10 +87,10 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &ast::Lit) lit_int_ty)) } } - ast::LitFloat(ref fs, t) => { + LitKind::Float(ref fs, t) => { C_floating(&fs, Type::float_from_ty(cx, t)) } - ast::LitFloatUnsuffixed(ref fs) => { + LitKind::FloatUnsuffixed(ref fs) => { let lit_float_ty = cx.tcx().node_id_to_type(e.id); match lit_float_ty.sty { ty::TyFloat(t) => { @@ -102,9 +102,9 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &ast::Lit) } } } - ast::LitBool(b) => C_bool(cx, b), - ast::LitStr(ref s, _) => C_str_slice(cx, (*s).clone()), - ast::LitByteStr(ref data) => { + LitKind::Bool(b) => C_bool(cx, b), + LitKind::Str(ref s, _) => C_str_slice(cx, (*s).clone()), + LitKind::ByteStr(ref data) => { addr_of(cx, C_bytes(cx, &data[..]), 1, "byte_str") } } diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs index a09936e1220..e411ed34691 100644 --- a/src/librustc_trans/trans/expr.rs +++ b/src/librustc_trans/trans/expr.rs @@ -1153,7 +1153,7 @@ fn trans_rvalue_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } hir::ExprLit(ref lit) => { match lit.node { - ast::LitStr(ref s, _) => { + ast::LitKind::Str(ref s, _) => { tvec::trans_lit_str(bcx, expr, (*s).clone(), dest) } _ => { diff --git a/src/librustc_trans/trans/tvec.rs b/src/librustc_trans/trans/tvec.rs index 3a1568a70c9..b3f783a974d 100644 --- a/src/librustc_trans/trans/tvec.rs +++ b/src/librustc_trans/trans/tvec.rs @@ -92,7 +92,7 @@ pub fn trans_slice_vec<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, // Handle the "..." case (returns a slice since strings are always unsized): if let hir::ExprLit(ref lit) = content_expr.node { - if let ast::LitStr(ref s, _) = lit.node { + if let ast::LitKind::Str(ref s, _) = lit.node { let scratch = rvalue_scratch_datum(bcx, vec_ty, ""); bcx = trans_lit_str(bcx, content_expr, @@ -180,7 +180,7 @@ fn write_content<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, match content_expr.node { hir::ExprLit(ref lit) => { match lit.node { - ast::LitStr(ref s, _) => { + ast::LitKind::Str(ref s, _) => { match dest { Ignore => return bcx, SaveIn(lldest) => { @@ -276,7 +276,7 @@ fn elements_required(bcx: Block, content_expr: &hir::Expr) -> usize { match content_expr.node { hir::ExprLit(ref lit) => { match lit.node { - ast::LitStr(ref s, _) => s.len(), + ast::LitKind::Str(ref s, _) => s.len(), _ => { bcx.tcx().sess.span_bug(content_expr.span, "unexpected evec content") diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index c43349f8810..f0436eee420 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -57,7 +57,7 @@ pub fn check_pat<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, // They can denote both statically and dynamically sized byte arrays let mut pat_ty = expr_ty; if let hir::ExprLit(ref lt) = lt.node { - if let ast::LitByteStr(_) = lt.node { + if let ast::LitKind::ByteStr(_) = lt.node { let expected_ty = structurally_resolved_type(fcx, pat.span, expected); if let ty::TyRef(_, mt) = expected_ty.sty { if let ty::TySlice(_) = mt.ty.sty { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 176f9bcd4f6..e348f7a9e06 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2606,16 +2606,16 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, let tcx = fcx.ccx.tcx; match lit.node { - ast::LitStr(..) => tcx.mk_static_str(), - ast::LitByteStr(ref v) => { + ast::LitKind::Str(..) => tcx.mk_static_str(), + ast::LitKind::ByteStr(ref v) => { tcx.mk_imm_ref(tcx.mk_region(ty::ReStatic), tcx.mk_array(tcx.types.u8, v.len())) } - ast::LitByte(_) => tcx.types.u8, - ast::LitChar(_) => tcx.types.char, - ast::LitInt(_, ast::SignedIntLit(t)) => tcx.mk_mach_int(t), - ast::LitInt(_, ast::UnsignedIntLit(t)) => tcx.mk_mach_uint(t), - ast::LitInt(_, ast::UnsuffixedIntLit) => { + ast::LitKind::Byte(_) => tcx.types.u8, + ast::LitKind::Char(_) => tcx.types.char, + ast::LitKind::Int(_, ast::SignedIntLit(t)) => tcx.mk_mach_int(t), + ast::LitKind::Int(_, ast::UnsignedIntLit(t)) => tcx.mk_mach_uint(t), + ast::LitKind::Int(_, ast::UnsuffixedIntLit) => { let opt_ty = expected.to_option(fcx).and_then(|ty| { match ty.sty { ty::TyInt(_) | ty::TyUint(_) => Some(ty), @@ -2628,8 +2628,8 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, opt_ty.unwrap_or_else( || tcx.mk_int_var(fcx.infcx().next_int_var_id())) } - ast::LitFloat(_, t) => tcx.mk_mach_float(t), - ast::LitFloatUnsuffixed(_) => { + ast::LitKind::Float(_, t) => tcx.mk_mach_float(t), + ast::LitKind::FloatUnsuffixed(_) => { let opt_ty = expected.to_option(fcx).and_then(|ty| { match ty.sty { ty::TyFloat(_) => Some(ty), @@ -2639,7 +2639,7 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, opt_ty.unwrap_or_else( || tcx.mk_float_var(fcx.infcx().next_float_var_id())) } - ast::LitBool(_) => tcx.types.bool + ast::LitKind::Bool(_) => tcx.types.bool } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 29722e5b538..2a346b773e6 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2531,9 +2531,9 @@ impl ToSource for syntax::codemap::Span { fn lit_to_string(lit: &ast::Lit) -> String { match lit.node { - ast::LitStr(ref st, _) => st.to_string(), - ast::LitByteStr(ref data) => format!("{:?}", data), - ast::LitByte(b) => { + ast::LitKind::Str(ref st, _) => st.to_string(), + ast::LitKind::ByteStr(ref data) => format!("{:?}", data), + ast::LitKind::Byte(b) => { let mut res = String::from("b'"); for c in (b as char).escape_default() { res.push(c); @@ -2541,11 +2541,11 @@ fn lit_to_string(lit: &ast::Lit) -> String { res.push('\''); res }, - ast::LitChar(c) => format!("'{}'", c), - ast::LitInt(i, _t) => i.to_string(), - ast::LitFloat(ref f, _t) => f.to_string(), - ast::LitFloatUnsuffixed(ref f) => f.to_string(), - ast::LitBool(b) => b.to_string(), + ast::LitKind::Char(c) => format!("'{}'", c), + ast::LitKind::Int(i, _t) => i.to_string(), + ast::LitKind::Float(ref f, _t) => f.to_string(), + ast::LitKind::FloatUnsuffixed(ref f) => f.to_string(), + ast::LitKind::Bool(b) => b.to_string(), } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 5752cbda9b9..41414ef5be1 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -13,7 +13,6 @@ pub use self::ForeignItem_::*; pub use self::Item_::*; pub use self::KleeneOp::*; -pub use self::Lit_::*; pub use self::LitIntType::*; pub use self::MacStmtStyle::*; pub use self::MetaItem_::*; @@ -1264,7 +1263,7 @@ pub enum StrStyle { } /// A literal -pub type Lit = Spanned; +pub type Lit = Spanned; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub enum LitIntType { @@ -1274,30 +1273,30 @@ pub enum LitIntType { } #[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>), + ByteStr(Rc>), /// 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, } } diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 64e6bcaa53c..c79661c1948 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -106,7 +106,7 @@ impl AttrMetaMethods for MetaItem { match self.node { MetaNameValue(_, ref v) => { match v.node { - ast::LitStr(ref s, _) => Some((*s).clone()), + ast::LitKind::Str(ref s, _) => Some((*s).clone()), _ => None, } }, @@ -173,7 +173,7 @@ impl AttributeMethods for Attribute { pub fn mk_name_value_item_str(name: InternedString, value: InternedString) -> P { - let value_lit = dummy_spanned(ast::LitStr(value, ast::CookedStr)); + let value_lit = dummy_spanned(ast::LitKind::Str(value, ast::CookedStr)); mk_name_value_item(name, value_lit) } @@ -225,7 +225,7 @@ 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::CookedStr)); let attr = Attribute_ { id: id, style: style, diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index b58f8007e0a..267b2dd9f6a 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -349,7 +349,7 @@ impl DummyResult { pub fn raw_expr(sp: Span) -> P { P(ast::Expr { id: ast::DUMMY_NODE_ID, - node: ast::ExprKind::Lit(P(codemap::respan(sp, ast::LitBool(false)))), + node: ast::ExprKind::Lit(P(codemap::respan(sp, ast::LitKind::Bool(false)))), span: sp, attrs: None, }) @@ -774,7 +774,7 @@ pub fn expr_to_string(cx: &mut ExtCtxt, expr: P, err_msg: &str) let expr = cx.expander().fold_expr(expr); match expr.node { ast::ExprKind::Lit(ref l) => match l.node { - ast::LitStr(ref s, style) => return Some(((*s).clone(), style)), + 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 241ea976eee..9302cabe8d8 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -139,7 +139,7 @@ pub trait AstBuilder { fn expr_struct_ident(&self, span: Span, id: ast::Ident, fields: Vec) -> P; - fn expr_lit(&self, sp: Span, lit: ast::Lit_) -> P; + fn expr_lit(&self, sp: Span, lit: ast::LitKind) -> P; fn expr_usize(&self, span: Span, i: usize) -> P; fn expr_isize(&self, sp: Span, i: isize) -> P; @@ -285,7 +285,7 @@ pub trait AstBuilder { fn meta_name_value(&self, sp: Span, name: InternedString, - value: ast::Lit_) + value: ast::LitKind) -> P; fn item_use(&self, sp: Span, @@ -676,29 +676,30 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.expr_struct(span, self.path_ident(span, id), fields) } - fn expr_lit(&self, sp: Span, lit: ast::Lit_) -> P { + fn expr_lit(&self, sp: Span, lit: ast::LitKind) -> P { self.expr(sp, ast::ExprKind::Lit(P(respan(sp, lit)))) } fn expr_usize(&self, span: Span, i: usize) -> P { - self.expr_lit(span, ast::LitInt(i as u64, ast::UnsignedIntLit(ast::UintTy::Us))) + self.expr_lit(span, ast::LitKind::Int(i as u64, ast::UnsignedIntLit(ast::UintTy::Us))) } fn expr_isize(&self, sp: Span, i: isize) -> P { if i < 0 { let i = (-i) as u64; - let lit = self.expr_lit(sp, ast::LitInt(i, ast::SignedIntLit(ast::IntTy::Is))); + 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::LitInt(i as u64, ast::SignedIntLit(ast::IntTy::Is))) + self.expr_lit(sp, ast::LitKind::Int(i as u64, ast::SignedIntLit(ast::IntTy::Is))) } } fn expr_u32(&self, sp: Span, u: u32) -> P { - self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::UintTy::U32))) + self.expr_lit(sp, ast::LitKind::Int(u as u64, ast::UnsignedIntLit(ast::UintTy::U32))) } fn expr_u8(&self, sp: Span, u: u8) -> P { - self.expr_lit(sp, ast::LitInt(u as u64, ast::UnsignedIntLit(ast::UintTy::U8))) + self.expr_lit(sp, ast::LitKind::Int(u as u64, ast::UnsignedIntLit(ast::UintTy::U8))) } fn expr_bool(&self, sp: Span, value: bool) -> P { - self.expr_lit(sp, ast::LitBool(value)) + self.expr_lit(sp, ast::LitKind::Bool(value)) } fn expr_vec(&self, sp: Span, exprs: Vec>) -> P { @@ -712,7 +713,7 @@ 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 { - self.expr_lit(sp, ast::LitStr(s, ast::CookedStr)) + self.expr_lit(sp, ast::LitKind::Str(s, ast::CookedStr)) } fn expr_cast(&self, sp: Span, expr: P, ty: P) -> P { @@ -1113,7 +1114,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn meta_name_value(&self, sp: Span, name: InternedString, - value: ast::Lit_) + value: ast::LitKind) -> P { P(respan(sp, ast::MetaNameValue(name, respan(sp, value)))) } diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index dfe3f8e3c54..18342fa775b 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -218,7 +218,7 @@ pub mod rt { impl ToTokens for str { fn to_tokens(&self, cx: &ExtCtxt) -> Vec { - let lit = ast::LitStr( + let lit = ast::LitKind::Str( token::intern_and_get_ident(self), ast::CookedStr); dummy_spanned(lit).to_tokens(cx) } @@ -249,13 +249,13 @@ pub mod rt { impl ToTokens for bool { fn to_tokens(&self, cx: &ExtCtxt) -> Vec { - 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 { - dummy_spanned(ast::LitChar(*self)).to_tokens(cx) + dummy_spanned(ast::LitKind::Char(*self)).to_tokens(cx) } } @@ -268,7 +268,7 @@ pub mod rt { } else { *self }; - let lit = ast::LitInt(val as u64, ast::SignedIntLit($tag)); + let lit = ast::LitKind::Int(val as u64, ast::SignedIntLit($tag)); let lit = P(ast::Expr { id: ast::DUMMY_NODE_ID, node: ast::ExprKind::Lit(P(dummy_spanned(lit))), @@ -290,7 +290,7 @@ pub mod rt { (unsigned, $t:ty, $tag:expr) => ( impl ToTokens for $t { fn to_tokens(&self, cx: &ExtCtxt) -> Vec { - let lit = ast::LitInt(*self as u64, ast::UnsignedIntLit($tag)); + let lit = ast::LitKind::Int(*self as u64, ast::UnsignedIntLit($tag)); dummy_spanned(lit).to_tokens(cx) } } 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/parse/attr.rs b/src/libsyntax/parse/attr.rs index 96ac9b83d2f..3f9f2ae44a3 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -175,7 +175,7 @@ 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"); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index d467405e089..bfd3dea38ce 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::FloatTy::F32), - Some("f64") => ast::LitFloat(data, ast::FloatTy::F64), + 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, - 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::(); @@ -576,7 +576,7 @@ pub fn integer_lit(s: &str, suffix: Option, 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::(); @@ -652,7 +652,7 @@ pub fn integer_lit(s: &str, string was {:?}, the original suffix was {:?}", ty, base, s, orig, suffix); match u64::from_str_radix(s, base) { - Ok(r) => ast::LitInt(r, ty), + 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, @@ -665,7 +665,7 @@ pub fn integer_lit(s: &str, if !already_errored { sd.span_err(sp, "int literal is too large"); } - ast::LitInt(0, ty) + ast::LitKind::Int(0, ty) } } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 1a8b1cbc374..d3b92ac0c0c 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -27,9 +27,8 @@ 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_, UintTy}; -use ast::{LitBool, LitChar, LitByte, LitByteStr}; -use ast::{LitStr, LitInt, Local}; +use ast::{Lit, LitKind, UintTy}; +use ast::Local; use ast::{MacStmtWithBraces, MacStmtWithSemicolon, MacStmtWithoutBraces}; use ast::{MutImmutable, MutMutable, Mac_}; use ast::{MutTy, Mutability}; @@ -1517,7 +1516,7 @@ 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 { @@ -1527,8 +1526,8 @@ impl<'a> Parser<'a> { } 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 @@ -1548,20 +1547,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::CookedStr)) } token::StrRaw(s, n) => { (true, - LitStr( + LitKind::Str( token::intern_and_get_ident(&parse::raw_str_lit(&s.as_str())), ast::RawStr(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 { @@ -1579,9 +1578,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)); @@ -2015,7 +2014,7 @@ impl<'a> Parser<'a> { pub fn mk_lit_u32(&mut self, i: u32, attrs: ThinAttributes) -> P { let span = &self.span; let lv_lit = P(codemap::Spanned { - node: LitInt(i as u64, ast::UnsignedIntLit(UintTy::U32)), + node: LitKind::Int(i as u64, ast::UnsignedIntLit(UintTy::U32)), span: *span }); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 1e57d347f5a..96c5d116629 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -630,20 +630,20 @@ 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) => { word(self.writer(), @@ -657,18 +657,18 @@ pub trait PrintState<'a> { } } } - 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) diff --git a/src/libsyntax_ext/concat.rs b/src/libsyntax_ext/concat.rs index 9f6cf73ed64..8ea0580d4c8 100644 --- a/src/libsyntax_ext/concat.rs +++ b/src/libsyntax_ext/concat.rs @@ -29,24 +29,24 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, match e.node { ast::ExprKind::Lit(ref lit) => { match lit.node { - ast::LitStr(ref s, _) | - ast::LitFloat(ref s, _) | - ast::LitFloatUnsuffixed(ref s) => { + ast::LitKind::Str(ref s, _) | + ast::LitKind::Float(ref s, _) | + ast::LitKind::FloatUnsuffixed(ref s) => { accumulator.push_str(&s); } - ast::LitChar(c) => { + ast::LitKind::Char(c) => { accumulator.push(c); } - ast::LitInt(i, ast::UnsignedIntLit(_)) | - ast::LitInt(i, ast::SignedIntLit(_)) | - ast::LitInt(i, ast::UnsuffixedIntLit) => { + ast::LitKind::Int(i, ast::UnsignedIntLit(_)) | + ast::LitKind::Int(i, ast::SignedIntLit(_)) | + ast::LitKind::Int(i, ast::UnsuffixedIntLit) => { accumulator.push_str(&format!("{}", i)); } - ast::LitBool(b) => { + ast::LitKind::Bool(b) => { accumulator.push_str(&format!("{}", b)); } - ast::LitByte(..) | - ast::LitByteStr(..) => { + ast::LitKind::Byte(..) | + ast::LitKind::ByteStr(..) => { cx.span_err(e.span, "cannot concatenate a byte string literal"); } } diff --git a/src/libsyntax_ext/deriving/debug.rs b/src/libsyntax_ext/deriving/debug.rs index 3c36ce57d18..1751f43e0a1 100644 --- a/src/libsyntax_ext/deriving/debug.rs +++ b/src/libsyntax_ext/deriving/debug.rs @@ -71,8 +71,8 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, // We want to make sure we have the expn_id set so that we can use unstable methods let span = Span { expn_id: cx.backtrace(), .. span }; - let name = cx.expr_lit(span, ast::Lit_::LitStr(ident.name.as_str(), - ast::StrStyle::CookedStr)); + let name = cx.expr_lit(span, ast::LitKind::Str(ident.name.as_str(), + ast::StrStyle::CookedStr)); let builder = token::str_to_ident("builder"); let builder_expr = cx.expr_ident(span, builder.clone()); @@ -112,7 +112,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, stmts.push(cx.stmt_let(DUMMY_SP, true, builder, expr)); for field in fields { - let name = cx.expr_lit(field.span, ast::Lit_::LitStr( + let name = cx.expr_lit(field.span, ast::LitKind::Str( field.name.unwrap().name.as_str(), ast::StrStyle::CookedStr)); diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index 21b32153ed9..541c2dbda4e 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -409,7 +409,7 @@ impl<'a, 'b> Context<'a, 'b> { } // Translate the format - let fill = self.ecx.expr_lit(sp, ast::LitChar(fill)); + let fill = self.ecx.expr_lit(sp, ast::LitKind::Char(fill)); let align = |name| { let mut p = Context::rtpath(self.ecx, "Alignment"); p.push(self.ecx.ident_of(name)); From 498a2e416e693fa22042d3ae81c5c969fc87fe5c Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 8 Feb 2016 17:16:23 +0100 Subject: [PATCH 17/29] [breaking-change] don't pub export ast::IntLitType variants --- src/librustc/middle/const_eval.rs | 6 +++--- src/librustc_lint/types.rs | 12 ++++++------ src/librustc_trans/trans/consts.rs | 6 +++--- src/librustc_typeck/check/mod.rs | 6 +++--- src/libsyntax/ast.rs | 7 +++---- src/libsyntax/ext/build.rs | 8 ++++---- src/libsyntax/ext/quote.rs | 4 ++-- src/libsyntax/parse/mod.rs | 22 +++++++++++----------- src/libsyntax/parse/parser.rs | 2 +- src/libsyntax/print/pprust.rs | 6 +++--- src/libsyntax_ext/concat.rs | 6 +++--- 11 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 80adc3e6fc6..6650a06229a 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -1328,14 +1328,14 @@ fn lit_to_const(sess: &Session, span: Span, lit: &ast::Lit, ty_hint: Option) } ast::LitKind::Byte(n) => Uint(n as u64), ast::LitKind::Char(n) => Uint(n as u64), - ast::LitKind::Int(n, ast::SignedIntLit(_)) => Int(n as i64), - ast::LitKind::Int(n, ast::UnsuffixedIntLit) => { + ast::LitKind::Int(n, ast::LitIntType::Signed(_)) => Int(n as i64), + ast::LitKind::Int(n, ast::LitIntType::Unsuffixed) => { match ty_hint.map(|ty| &ty.sty) { Some(&ty::TyUint(_)) => Uint(n), _ => Int(n as i64) } } - ast::LitKind::Int(n, ast::UnsignedIntLit(_)) => Uint(n), + ast::LitKind::Int(n, ast::LitIntType::Unsigned(_)) => Uint(n), ast::LitKind::Float(ref n, _) | ast::LitKind::FloatUnsuffixed(ref n) => { if let Ok(x) = n.parse::() { diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 11469f43140..9fe1aa15f4a 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -103,10 +103,10 @@ impl LateLintPass for TypeLimits { hir::ExprUnary(hir::UnNeg, ref expr) => { if let hir::ExprLit(ref lit) = expr.node { match lit.node { - ast::LitKind::Int(_, ast::UnsignedIntLit(_)) => { + ast::LitKind::Int(_, ast::LitIntType::Unsigned(_)) => { forbid_unsigned_negation(cx, e.span); }, - ast::LitKind::Int(_, ast::UnsuffixedIntLit) => { + ast::LitKind::Int(_, ast::LitIntType::Unsuffixed) => { if let ty::TyUint(_) = cx.tcx.node_id_to_type(e.id).sty { forbid_unsigned_negation(cx, e.span); } @@ -159,8 +159,8 @@ impl LateLintPass for TypeLimits { match cx.tcx.node_id_to_type(e.id).sty { ty::TyInt(t) => { match lit.node { - ast::LitKind::Int(v, ast::SignedIntLit(_)) | - ast::LitKind::Int(v, ast::UnsuffixedIntLit) => { + ast::LitKind::Int(v, ast::LitIntType::Signed(_)) | + ast::LitKind::Int(v, ast::LitIntType::Unsuffixed) => { let int_type = if let ast::IntTy::Is = t { cx.sess().target.int_type } else { @@ -312,8 +312,8 @@ impl LateLintPass for TypeLimits { let (min, max) = int_ty_range(int_ty); let lit_val: i64 = match lit.node { hir::ExprLit(ref li) => match li.node { - ast::LitKind::Int(v, ast::SignedIntLit(_)) | - ast::LitKind::Int(v, ast::UnsuffixedIntLit) => v as i64, + ast::LitKind::Int(v, ast::LitIntType::Signed(_)) | + ast::LitKind::Int(v, ast::LitIntType::Unsuffixed) => v as i64, _ => return true }, _ => panic!() diff --git a/src/librustc_trans/trans/consts.rs b/src/librustc_trans/trans/consts.rs index f6bee7c2696..e1cff76cb0f 100644 --- a/src/librustc_trans/trans/consts.rs +++ b/src/librustc_trans/trans/consts.rs @@ -66,13 +66,13 @@ pub fn const_lit(cx: &CrateContext, e: &hir::Expr, lit: &ast::Lit) match lit.node { LitKind::Byte(b) => C_integral(Type::uint_from_ty(cx, ast::UintTy::U8), b as u64, false), LitKind::Char(i) => C_integral(Type::char(cx), i as u64, false), - LitKind::Int(i, ast::SignedIntLit(t)) => { + LitKind::Int(i, ast::LitIntType::Signed(t)) => { C_integral(Type::int_from_ty(cx, t), i, true) } - LitKind::Int(u, ast::UnsignedIntLit(t)) => { + LitKind::Int(u, ast::LitIntType::Unsigned(t)) => { C_integral(Type::uint_from_ty(cx, t), u, false) } - LitKind::Int(i, ast::UnsuffixedIntLit) => { + LitKind::Int(i, ast::LitIntType::Unsuffixed) => { let lit_int_ty = cx.tcx().node_id_to_type(e.id); match lit_int_ty.sty { ty::TyInt(t) => { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index e348f7a9e06..f61316f1dfe 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2613,9 +2613,9 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, } ast::LitKind::Byte(_) => tcx.types.u8, ast::LitKind::Char(_) => tcx.types.char, - ast::LitKind::Int(_, ast::SignedIntLit(t)) => tcx.mk_mach_int(t), - ast::LitKind::Int(_, ast::UnsignedIntLit(t)) => tcx.mk_mach_uint(t), - ast::LitKind::Int(_, ast::UnsuffixedIntLit) => { + ast::LitKind::Int(_, ast::LitIntType::Signed(t)) => tcx.mk_mach_int(t), + ast::LitKind::Int(_, ast::LitIntType::Unsigned(t)) => tcx.mk_mach_uint(t), + ast::LitKind::Int(_, ast::LitIntType::Unsuffixed) => { let opt_ty = expected.to_option(fcx).and_then(|ty| { match ty.sty { ty::TyInt(_) | ty::TyUint(_) => Some(ty), diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 41414ef5be1..6ece7ed56cf 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -13,7 +13,6 @@ pub use self::ForeignItem_::*; pub use self::Item_::*; pub use self::KleeneOp::*; -pub use self::LitIntType::*; pub use self::MacStmtStyle::*; pub use self::MetaItem_::*; pub use self::Mutability::*; @@ -1267,9 +1266,9 @@ pub type Lit = Spanned; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub enum LitIntType { - SignedIntLit(IntTy), - UnsignedIntLit(UintTy), - UnsuffixedIntLit, + Signed(IntTy), + Unsigned(UintTy), + Unsuffixed, } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 9302cabe8d8..7dfea4f798c 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -680,7 +680,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.expr(sp, ast::ExprKind::Lit(P(respan(sp, lit)))) } fn expr_usize(&self, span: Span, i: usize) -> P { - self.expr_lit(span, ast::LitKind::Int(i as u64, ast::UnsignedIntLit(ast::UintTy::Us))) + 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 { if i < 0 { @@ -689,14 +689,14 @@ impl<'a> AstBuilder for ExtCtxt<'a> { 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::SignedIntLit(ast::IntTy::Is))) + 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 { - self.expr_lit(sp, ast::LitKind::Int(u as u64, ast::UnsignedIntLit(ast::UintTy::U32))) + 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 { - self.expr_lit(sp, ast::LitKind::Int(u as u64, ast::UnsignedIntLit(ast::UintTy::U8))) + 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 { self.expr_lit(sp, ast::LitKind::Bool(value)) diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 18342fa775b..44ef74fcc0c 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -268,7 +268,7 @@ pub mod rt { } else { *self }; - let lit = ast::LitKind::Int(val as u64, ast::SignedIntLit($tag)); + 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))), @@ -290,7 +290,7 @@ pub mod rt { (unsigned, $t:ty, $tag:expr) => ( impl ToTokens for $t { fn to_tokens(&self, cx: &ExtCtxt) -> Vec { - let lit = ast::LitKind::Int(*self as u64, ast::UnsignedIntLit($tag)); + let lit = ast::LitKind::Int(*self as u64, ast::LitIntType::Unsigned($tag)); dummy_spanned(lit).to_tokens(cx) } } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index bfd3dea38ce..3d68dcdc6b7 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -586,7 +586,7 @@ pub fn integer_lit(s: &str, let mut base = 10; let orig = s; - let mut ty = ast::UnsuffixedIntLit; + 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::IntTy::Is), - "i8" => ast::SignedIntLit(ast::IntTy::I8), - "i16" => ast::SignedIntLit(ast::IntTy::I16), - "i32" => ast::SignedIntLit(ast::IntTy::I32), - "i64" => ast::SignedIntLit(ast::IntTy::I64), - "usize" => ast::UnsignedIntLit(ast::UintTy::Us), - "u8" => ast::UnsignedIntLit(ast::UintTy::U8), - "u16" => ast::UnsignedIntLit(ast::UintTy::U16), - "u32" => ast::UnsignedIntLit(ast::UintTy::U32), - "u64" => ast::UnsignedIntLit(ast::UintTy::U64), + "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 and u look like widths, so lets // give an error message along those lines diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d3b92ac0c0c..85a5b5b3068 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2014,7 +2014,7 @@ impl<'a> Parser<'a> { pub fn mk_lit_u32(&mut self, i: u32, attrs: ThinAttributes) -> P { let span = &self.span; let lv_lit = P(codemap::Spanned { - node: LitKind::Int(i as u64, ast::UnsignedIntLit(UintTy::U32)), + node: LitKind::Int(i as u64, ast::LitIntType::Unsigned(UintTy::U32)), span: *span }); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 96c5d116629..8d29cb39d3a 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -645,14 +645,14 @@ pub trait PrintState<'a> { } ast::LitKind::Int(i, t) => { match t { - ast::SignedIntLit(st) => { + ast::LitIntType::Signed(st) => { word(self.writer(), &st.val_to_string(i as i64)) } - ast::UnsignedIntLit(ut) => { + ast::LitIntType::Unsigned(ut) => { word(self.writer(), &ut.val_to_string(i)) } - ast::UnsuffixedIntLit => { + ast::LitIntType::Unsuffixed => { word(self.writer(), &format!("{}", i)) } } diff --git a/src/libsyntax_ext/concat.rs b/src/libsyntax_ext/concat.rs index 8ea0580d4c8..db731adf794 100644 --- a/src/libsyntax_ext/concat.rs +++ b/src/libsyntax_ext/concat.rs @@ -37,9 +37,9 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, ast::LitKind::Char(c) => { accumulator.push(c); } - ast::LitKind::Int(i, ast::UnsignedIntLit(_)) | - ast::LitKind::Int(i, ast::SignedIntLit(_)) | - ast::LitKind::Int(i, ast::UnsuffixedIntLit) => { + ast::LitKind::Int(i, ast::LitIntType::Unsigned(_)) | + ast::LitKind::Int(i, ast::LitIntType::Signed(_)) | + ast::LitKind::Int(i, ast::LitIntType::Unsuffixed) => { accumulator.push_str(&format!("{}", i)); } ast::LitKind::Bool(b) => { From 8290c950a8b4cdc70038736abcf29f41dede6e0c Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 8 Feb 2016 17:23:13 +0100 Subject: [PATCH 18/29] [breaking-change] don't pub export ast::Stmt_ variants --- src/librustc_front/lowering.rs | 8 +++---- src/librustc_lint/unused.rs | 2 +- src/librustc_passes/const_fn.rs | 8 +++---- src/libsyntax/ast.rs | 33 +++++++++++++-------------- src/libsyntax/attr.rs | 12 +++++----- src/libsyntax/config.rs | 2 +- src/libsyntax/ext/base.rs | 6 ++--- src/libsyntax/ext/build.rs | 8 +++---- src/libsyntax/ext/expand.rs | 13 +++++------ src/libsyntax/fold.rs | 20 ++++++++--------- src/libsyntax/parse/classify.rs | 10 ++++----- src/libsyntax/parse/mod.rs | 4 ++-- src/libsyntax/parse/parser.rs | 35 +++++++++++++---------------- src/libsyntax/print/pprust.rs | 8 +++---- src/libsyntax/visit.rs | 6 ++--- src/libsyntax_ext/deriving/debug.rs | 2 +- src/libsyntax_ext/format.rs | 2 +- 17 files changed, 87 insertions(+), 92 deletions(-) diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index 813a7f71fe9..55f37759892 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -1534,25 +1534,25 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P { pub fn lower_stmt(lctx: &LoweringContext, s: &Stmt) -> hir::Stmt { match s.node { - StmtDecl(ref d, id) => { + StmtKind::Decl(ref d, id) => { Spanned { node: hir::StmtDecl(lower_decl(lctx, d), id), span: s.span, } } - StmtExpr(ref e, id) => { + StmtKind::Expr(ref e, id) => { Spanned { node: hir::StmtExpr(lower_expr(lctx, e), id), span: s.span, } } - StmtSemi(ref e, id) => { + StmtKind::Semi(ref e, id) => { Spanned { node: hir::StmtSemi(lower_expr(lctx, e), id), span: s.span, } } - StmtMac(..) => panic!("Shouldn't exist here"), + StmtKind::Mac(..) => panic!("Shouldn't exist here"), } } diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index bbd714fad06..f18b68a5b73 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -365,7 +365,7 @@ impl EarlyLintPass for UnusedParens { fn check_stmt(&mut self, cx: &EarlyContext, s: &ast::Stmt) { let (value, msg) = match s.node { - ast::StmtDecl(ref decl, _) => match decl.node { + ast::StmtKind::Decl(ref decl, _) => match decl.node { ast::DeclKind::Local(ref local) => match local.init { Some(ref value) => (value, "assigned value"), None => return diff --git a/src/librustc_passes/const_fn.rs b/src/librustc_passes/const_fn.rs index 5ec00439df2..ec9fa1afb55 100644 --- a/src/librustc_passes/const_fn.rs +++ b/src/librustc_passes/const_fn.rs @@ -57,7 +57,7 @@ fn check_block(sess: &Session, b: &ast::Block, kind: &'static str) { // Check all statements in the block for stmt in &b.stmts { let span = match stmt.node { - ast::StmtDecl(ref decl, _) => { + ast::StmtKind::Decl(ref decl, _) => { match decl.node { ast::DeclKind::Local(_) => decl.span, @@ -65,9 +65,9 @@ fn check_block(sess: &Session, b: &ast::Block, kind: &'static str) { ast::DeclKind::Item(_) => continue, } } - ast::StmtExpr(ref expr, _) => expr.span, - ast::StmtSemi(ref semi, _) => semi.span, - ast::StmtMac(..) => unreachable!(), + ast::StmtKind::Expr(ref expr, _) => expr.span, + ast::StmtKind::Semi(ref semi, _) => semi.span, + ast::StmtKind::Mac(..) => unreachable!(), }; span_err!(sess, span, E0016, "blocks in {}s are limited to items and tail expressions", kind); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 6ece7ed56cf..b677941291b 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -18,7 +18,6 @@ pub use self::MetaItem_::*; pub use self::Mutability::*; pub use self::Pat_::*; pub use self::PathListItem_::*; -pub use self::Stmt_::*; pub use self::StrStyle::*; pub use self::StructFieldKind::*; pub use self::TraitItem_::*; @@ -735,7 +734,7 @@ impl UnOp { } /// A statement -pub type Stmt = Spanned; +pub type Stmt = Spanned; impl fmt::Debug for Stmt { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -748,36 +747,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, NodeId), + Decl(P, NodeId), /// Expr without trailing semi-colon (must have unit type): - StmtExpr(P, NodeId), + Expr(P, NodeId), /// Expr with trailing semi-colon (may have any type): - StmtSemi(P, NodeId), + Semi(P, NodeId), - StmtMac(P, MacStmtStyle, ThinAttributes), + Mac(P, MacStmtStyle, ThinAttributes), } -impl Stmt_ { +impl StmtKind { pub fn id(&self) -> Option { 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) => &[], } } } diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index c79661c1948..f9c41ee43dd 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -16,7 +16,7 @@ pub use self::IntType::*; use ast; use ast::{AttrId, Attribute, Attribute_, MetaItem, MetaWord, MetaNameValue, MetaList}; -use ast::{Stmt, StmtDecl, StmtExpr, StmtMac, StmtSemi, DeclKind}; +use ast::{Stmt, StmtKind, DeclKind}; use ast::{Expr, Item, Local, Decl}; use codemap::{Span, Spanned, spanned, dummy_spanned}; use codemap::BytePos; @@ -947,12 +947,12 @@ impl WithAttrs for P { 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 8d74990fc32..840acff73ad 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -372,7 +372,7 @@ 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::StmtKind::Decl(ref decl, _) = s.node { if let ast::DeclKind::Item(_) = decl.node { visit::walk_stmt(self, s); return; diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 267b2dd9f6a..ceb7cf69680 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -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)))) }) } } @@ -402,8 +402,8 @@ impl MacResult for DummyResult { fn make_stmts(self: Box) -> Option>> { 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))))) } } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 7dfea4f798c..76071cc71e6 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -506,7 +506,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn stmt_expr(&self, expr: P) -> P { - 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, @@ -525,7 +525,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { attrs: None, }); let decl = respan(sp, ast::DeclKind::Local(local)); - P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID))) + P(respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID))) } fn stmt_let_typed(&self, @@ -549,7 +549,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { attrs: None, }); let decl = respan(sp, ast::DeclKind::Local(local)); - P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID))) + P(respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID))) } fn block(&self, span: Span, stmts: Vec>, @@ -559,7 +559,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn stmt_item(&self, sp: Span, item: P) -> P { let decl = respan(sp, ast::DeclKind::Item(item)); - P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID))) + P(respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID))) } fn block_expr(&self, expr: P) -> P { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 9b31465b547..78bc4e2c735 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -10,8 +10,7 @@ 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::{ItemMac, MacStmtWithSemicolon, Mrk, Stmt, StmtKind}; use ast::TokenTree; use ast; use ext::mtwt; @@ -507,7 +506,7 @@ pub fn expand_item_mac(it: P, fn expand_stmt(stmt: P, fld: &mut MacroExpander) -> SmallVector> { 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) }; @@ -539,7 +538,7 @@ fn expand_stmt(stmt: P, fld: &mut MacroExpander) -> SmallVector> { 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,7 +557,7 @@ fn expand_non_macro_stmt(Spanned {node, span: stmt_span}: Stmt, fld: &mut MacroE -> SmallVector> { // is it a let? match node { - StmtDecl(decl, node_id) => decl.and_then(|Spanned {node: decl, span}| match decl { + 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}| { @@ -596,7 +595,7 @@ fn expand_non_macro_stmt(Spanned {node, span: stmt_span}: Stmt, fld: &mut MacroE } }); SmallVector::one(P(Spanned { - node: StmtDecl(P(Spanned { + node: StmtKind::Decl(P(Spanned { node: DeclKind::Local(rewritten_local), span: span }), @@ -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 }), diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 1a6171e1981..9819dc6220a 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -1347,39 +1347,39 @@ pub fn noop_fold_stmt(Spanned {node, span}: Stmt, folder: &mut T) -> SmallVector> { 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/classify.rs b/src/libsyntax/parse/classify.rs index 325fe64203c..89110f3160f 100644 --- a/src/libsyntax/parse/classify.rs +++ b/src/libsyntax/parse/classify.rs @@ -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::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 3d68dcdc6b7..2bbf1699662 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -867,7 +867,7 @@ 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::ExprKind::Path(None, ast::Path { span:sp(0,1), @@ -958,7 +958,7 @@ 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::ExprKind::Path(None, ast::Path{ diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 85a5b5b3068..93088648e93 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -36,8 +36,8 @@ 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::{Stmt, StmtDecl}; -use ast::{StmtExpr, StmtSemi, StmtMac, VariantData, StructField}; +use ast::{Stmt, StmtKind}; +use ast::{VariantData, StructField}; use ast::StrStyle; use ast::SelfKind; use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef}; @@ -3678,7 +3678,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() @@ -3730,11 +3730,8 @@ impl<'a> Parser<'a> { }; 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 @@ -3749,7 +3746,7 @@ impl<'a> Parser<'a> { followed by a semicolon"); } } - spanned(lo, hi, StmtDecl( + spanned(lo, hi, StmtKind::Decl( P(spanned(lo, hi, DeclKind::Item( self.mk_item( lo, hi, id /*id is good here*/, @@ -3764,7 +3761,7 @@ impl<'a> Parser<'a> { Some(i) => { let hi = i.span.hi; let decl = P(spanned(lo, hi, DeclKind::Item(i))); - spanned(lo, hi, StmtDecl(decl, ast::DUMMY_NODE_ID)) + spanned(lo, hi, StmtKind::Decl(decl, ast::DUMMY_NODE_ID)) } None => { let unused_attrs = |attrs: &[_], s: &mut Self| { @@ -3790,7 +3787,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) } } @@ -3844,16 +3841,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, MacStmtWithoutBraces, 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, MacStmtWithSemicolon, attrs), span: mk_sp(span.lo, self.span.hi), })); self.bump(); @@ -3873,12 +3870,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, MacStmtWithSemicolon, attrs), span: mk_sp(span.lo, self.span.hi), })); self.bump(); @@ -3892,7 +3889,7 @@ impl<'a> Parser<'a> { } _ => { stmts.push(P(Spanned { - node: StmtMac(m, style, attrs), + node: StmtKind::Mac(m, style, attrs), span: span })); } @@ -3944,14 +3941,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 })); } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 8d29cb39d3a..a880e0dca80 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1613,19 +1613,19 @@ 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 { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 44b3e581849..369efcd051e 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -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); diff --git a/src/libsyntax_ext/deriving/debug.rs b/src/libsyntax_ext/deriving/debug.rs index 1751f43e0a1..917c6b1ab89 100644 --- a/src/libsyntax_ext/deriving/debug.rs +++ b/src/libsyntax_ext/deriving/debug.rs @@ -152,5 +152,5 @@ fn stmt_let_undescore(cx: &mut ExtCtxt, attrs: None, }); let decl = respan(sp, ast::DeclKind::Local(local)); - P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID))) + P(respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID))) } diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index 541c2dbda4e..831a6250c9f 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -461,7 +461,7 @@ impl<'a, 'b> Context<'a, 'b> { // Wrap the declaration in a block so that it forms a single expression. ecx.expr_block(ecx.block(sp, - vec![P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID)))], + vec![P(respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID)))], Some(ecx.expr_ident(sp, name)))) } From 0d6ddd190355650a6d851c3aae12cf79339665af Mon Sep 17 00:00:00 2001 From: Oliver 'ker' Schneider Date: Tue, 9 Feb 2016 11:31:19 +0100 Subject: [PATCH 19/29] [breaking-change] don't glob export ast::ForeignItem_ variants --- src/librustc_front/lowering.rs | 4 ++-- src/libsyntax/ast.rs | 15 +++++++-------- src/libsyntax/fold.rs | 8 ++++---- src/libsyntax/parse/parser.rs | 6 +++--- src/libsyntax/print/pprust.rs | 4 ++-- src/libsyntax/visit.rs | 4 ++-- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index 55f37759892..781008db129 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -838,10 +838,10 @@ pub fn lower_foreign_item(lctx: &LoweringContext, i: &ForeignItem) -> hir::Forei name: i.ident.name, attrs: lower_attrs(lctx, &i.attrs), node: match i.node { - ForeignItemFn(ref fdec, ref generics) => { + ForeignItemKind::Fn(ref fdec, ref generics) => { hir::ForeignItemFn(lower_fn_decl(lctx, fdec), lower_generics(lctx, generics)) } - ForeignItemStatic(ref t, m) => { + ForeignItemKind::Static(ref t, m) => { hir::ForeignItemStatic(lower_ty(lctx, t), m) } }, diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index b677941291b..f2225ff2c09 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,7 +10,6 @@ // The Rust abstract syntax tree. -pub use self::ForeignItem_::*; pub use self::Item_::*; pub use self::KleeneOp::*; pub use self::MacStmtStyle::*; @@ -2039,7 +2038,7 @@ impl Item_ { pub struct ForeignItem { pub ident: Ident, pub attrs: Vec, - pub node: ForeignItem_, + pub node: ForeignItemKind, pub id: NodeId, pub span: Span, pub vis: Visibility, @@ -2047,19 +2046,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, Generics), + Fn(P, Generics), /// A foreign static item (`static ext: u8`), with optional mutability /// (the boolean is true when mutable) - ForeignItemStatic(P, bool), + Static(P, 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/fold.rs b/src/libsyntax/fold.rs index 9819dc6220a..8c39c48bbc7 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -1092,11 +1092,11 @@ pub fn noop_fold_foreign_item(ni: P, 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, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 93088648e93..4faad48f5b7 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -22,7 +22,7 @@ use ast::{Decl, DeclKind}; use ast::{EMPTY_CTXT, EnumDef, ExplicitSelf}; use ast::{Expr, ExprKind}; use ast::{Field, FnDecl}; -use ast::{ForeignItem, ForeignItemStatic, ForeignItemFn, FunctionRetTy}; +use ast::{ForeignItem, ForeignItemKind, FunctionRetTy}; use ast::{Ident, Inherited, ImplItem, Item, Item_, ItemStatic}; use ast::{ItemEnum, ItemFn, ItemForeignMod, ItemImpl, ItemConst}; use ast::{ItemMac, ItemMod, ItemStruct, ItemTrait, ItemTy, ItemDefaultImpl}; @@ -5256,7 +5256,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 @@ -5277,7 +5277,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 diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index a880e0dca80..becf2d2bc14 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1046,7 +1046,7 @@ 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, @@ -1056,7 +1056,7 @@ impl<'a> State<'a> { 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 { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 369efcd051e..54b3eccefc6 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -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); From 019614f03d106324ab50a37746b556c41e66c099 Mon Sep 17 00:00:00 2001 From: Oliver 'ker' Schneider Date: Tue, 9 Feb 2016 11:36:51 +0100 Subject: [PATCH 20/29] [breaking-change] don't glob export ast::Item_ variants --- src/librustc/front/check_attr.rs | 6 +-- src/librustc_driver/pretty.rs | 8 +-- src/librustc_front/lowering.rs | 32 +++++------ src/librustc_metadata/creader.rs | 2 +- src/librustc_metadata/macro_import.rs | 4 +- src/librustc_passes/const_fn.rs | 4 +- src/librustc_trans/save/dump_csv.rs | 25 ++++----- src/librustc_trans/save/mod.rs | 12 ++--- src/libsyntax/ast.rs | 65 +++++++++++------------ src/libsyntax/ast_util.rs | 2 +- src/libsyntax/config.rs | 24 ++++----- src/libsyntax/diagnostics/plugin.rs | 2 +- src/libsyntax/entry.rs | 4 +- src/libsyntax/ext/base.rs | 2 +- src/libsyntax/ext/build.rs | 20 +++---- src/libsyntax/ext/expand.rs | 24 ++++----- src/libsyntax/feature_gate.rs | 12 ++--- src/libsyntax/fold.rs | 62 ++++++++++----------- src/libsyntax/parse/mod.rs | 2 +- src/libsyntax/parse/parser.rs | 45 ++++++++-------- src/libsyntax/print/pprust.rs | 30 +++++------ src/libsyntax/std_inject.rs | 4 +- src/libsyntax/test.rs | 20 +++---- src/libsyntax/visit.rs | 28 +++++----- src/libsyntax_ext/deriving/generic/mod.rs | 16 +++--- src/libsyntax_ext/format.rs | 2 +- src/test/auxiliary/macro_crate_test.rs | 6 +-- 27 files changed, 230 insertions(+), 233 deletions(-) diff --git a/src/librustc/front/check_attr.rs b/src/librustc/front/check_attr.rs index 27785a072a6..cfd9d5bdaa7 100644 --- a/src/librustc/front/check_attr.rs +++ b/src/librustc/front/check_attr.rs @@ -26,9 +26,9 @@ enum Target { impl Target { fn from_item(item: &ast::Item) -> Target { match item.node { - ast::ItemFn(..) => Target::Fn, - ast::ItemStruct(..) => Target::Struct, - ast::ItemEnum(..) => Target::Enum, + ast::ItemKind::Fn(..) => Target::Fn, + ast::ItemKind::Struct(..) => Target::Struct, + ast::ItemKind::Enum(..) => Target::Enum, _ => Target::Other, } } diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 0f6ba63d54b..e0a948f7661 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -600,16 +600,16 @@ impl ReplaceBodyWithLoop { } impl fold::Folder for ReplaceBodyWithLoop { - fn fold_item_underscore(&mut self, i: ast::Item_) -> ast::Item_ { + fn fold_item_kind(&mut self, i: ast::ItemKind) -> ast::ItemKind { match i { - ast::ItemStatic(..) | ast::ItemConst(..) => { + ast::ItemKind::Static(..) | ast::ItemKind::Const(..) => { self.within_static_or_const = true; - let ret = fold::noop_fold_item_underscore(i, self); + let ret = fold::noop_fold_item_kind(i, self); self.within_static_or_const = false; return ret; } _ => { - fold::noop_fold_item_underscore(i, self) + fold::noop_fold_item_kind(i, self) } } } diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index 781008db129..d04f4c96504 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -654,21 +654,21 @@ pub fn lower_block(lctx: &LoweringContext, b: &Block) -> P { }) } -pub fn lower_item_underscore(lctx: &LoweringContext, i: &Item_) -> hir::Item_ { +pub fn lower_item_kind(lctx: &LoweringContext, i: &ItemKind) -> hir::Item_ { match *i { - ItemExternCrate(string) => hir::ItemExternCrate(string), - ItemUse(ref view_path) => { + ItemKind::ExternCrate(string) => hir::ItemExternCrate(string), + ItemKind::Use(ref view_path) => { hir::ItemUse(lower_view_path(lctx, view_path)) } - ItemStatic(ref t, m, ref e) => { + ItemKind::Static(ref t, m, ref e) => { hir::ItemStatic(lower_ty(lctx, t), lower_mutability(lctx, m), lower_expr(lctx, e)) } - ItemConst(ref t, ref e) => { + ItemKind::Const(ref t, ref e) => { hir::ItemConst(lower_ty(lctx, t), lower_expr(lctx, e)) } - ItemFn(ref decl, unsafety, constness, abi, ref generics, ref body) => { + ItemKind::Fn(ref decl, unsafety, constness, abi, ref generics, ref body) => { hir::ItemFn(lower_fn_decl(lctx, decl), lower_unsafety(lctx, unsafety), lower_constness(lctx, constness), @@ -676,12 +676,12 @@ pub fn lower_item_underscore(lctx: &LoweringContext, i: &Item_) -> hir::Item_ { lower_generics(lctx, generics), lower_block(lctx, body)) } - ItemMod(ref m) => hir::ItemMod(lower_mod(lctx, m)), - ItemForeignMod(ref nm) => hir::ItemForeignMod(lower_foreign_mod(lctx, nm)), - ItemTy(ref t, ref generics) => { + ItemKind::Mod(ref m) => hir::ItemMod(lower_mod(lctx, m)), + ItemKind::ForeignMod(ref nm) => hir::ItemForeignMod(lower_foreign_mod(lctx, nm)), + ItemKind::Ty(ref t, ref generics) => { hir::ItemTy(lower_ty(lctx, t), lower_generics(lctx, generics)) } - ItemEnum(ref enum_definition, ref generics) => { + ItemKind::Enum(ref enum_definition, ref generics) => { hir::ItemEnum(hir::EnumDef { variants: enum_definition.variants .iter() @@ -690,15 +690,15 @@ pub fn lower_item_underscore(lctx: &LoweringContext, i: &Item_) -> hir::Item_ { }, lower_generics(lctx, generics)) } - ItemStruct(ref struct_def, ref generics) => { + ItemKind::Struct(ref struct_def, ref generics) => { let struct_def = lower_variant_data(lctx, struct_def); hir::ItemStruct(struct_def, lower_generics(lctx, generics)) } - ItemDefaultImpl(unsafety, ref trait_ref) => { + ItemKind::DefaultImpl(unsafety, ref trait_ref) => { hir::ItemDefaultImpl(lower_unsafety(lctx, unsafety), lower_trait_ref(lctx, trait_ref)) } - ItemImpl(unsafety, polarity, ref generics, ref ifce, ref ty, ref impl_items) => { + ItemKind::Impl(unsafety, polarity, ref generics, ref ifce, ref ty, ref impl_items) => { let new_impl_items = impl_items.iter() .map(|item| lower_impl_item(lctx, item)) .collect(); @@ -710,7 +710,7 @@ pub fn lower_item_underscore(lctx: &LoweringContext, i: &Item_) -> hir::Item_ { lower_ty(lctx, ty), new_impl_items) } - ItemTrait(unsafety, ref generics, ref bounds, ref items) => { + ItemKind::Trait(unsafety, ref generics, ref bounds, ref items) => { let bounds = lower_bounds(lctx, bounds); let items = items.iter().map(|item| lower_trait_item(lctx, item)).collect(); hir::ItemTrait(lower_unsafety(lctx, unsafety), @@ -718,7 +718,7 @@ pub fn lower_item_underscore(lctx: &LoweringContext, i: &Item_) -> hir::Item_ { bounds, items) } - ItemMac(_) => panic!("Shouldn't still be around"), + ItemKind::Mac(_) => panic!("Shouldn't still be around"), } } @@ -820,7 +820,7 @@ pub fn lower_item_id(_lctx: &LoweringContext, i: &Item) -> hir::ItemId { } pub fn lower_item(lctx: &LoweringContext, i: &Item) -> hir::Item { - let node = lower_item_underscore(lctx, &i.node); + let node = lower_item_kind(lctx, &i.node); hir::Item { id: i.id, diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index d5aa091886e..52456251f96 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -157,7 +157,7 @@ impl<'a> CrateReader<'a> { fn extract_crate_info(&self, i: &ast::Item) -> Option { match i.node { - ast::ItemExternCrate(ref path_opt) => { + ast::ItemKind::ExternCrate(ref path_opt) => { debug!("resolving extern crate stmt. ident: {} path_opt: {:?}", i.ident, path_opt); let name = match *path_opt { diff --git a/src/librustc_metadata/macro_import.rs b/src/librustc_metadata/macro_import.rs index d67fc3a0eab..b2395ac355f 100644 --- a/src/librustc_metadata/macro_import.rs +++ b/src/librustc_metadata/macro_import.rs @@ -56,7 +56,7 @@ pub fn read_macro_defs(sess: &Session, cstore: &CStore, krate: &ast::Crate) // crate root, because `$crate` won't work properly. Identify these by // spans, because the crate map isn't set up yet. for item in &krate.module.items { - if let ast::ItemExternCrate(_) = item.node { + if let ast::ItemKind::ExternCrate(_) = item.node { loader.span_whitelist.insert(item.span); } } @@ -73,7 +73,7 @@ impl<'a, 'v> Visitor<'v> for MacroLoader<'a> { fn visit_item(&mut self, item: &ast::Item) { // We're only interested in `extern crate`. match item.node { - ast::ItemExternCrate(_) => {} + ast::ItemKind::ExternCrate(_) => {} _ => { visit::walk_item(self, item); return; diff --git a/src/librustc_passes/const_fn.rs b/src/librustc_passes/const_fn.rs index ec9fa1afb55..98346f538b0 100644 --- a/src/librustc_passes/const_fn.rs +++ b/src/librustc_passes/const_fn.rs @@ -78,10 +78,10 @@ impl<'a, 'v> Visitor<'v> for CheckConstFn<'a> { fn visit_item(&mut self, i: &'v ast::Item) { visit::walk_item(self, i); match i.node { - ast::ItemConst(_, ref e) => { + ast::ItemKind::Const(_, ref e) => { CheckBlock{ sess: self.sess, kind: "constant"}.visit_expr(e) }, - ast::ItemStatic(_, _, ref e) => { + ast::ItemKind::Static(_, _, ref e) => { CheckBlock{ sess: self.sess, kind: "static"}.visit_expr(e) }, _ => {}, diff --git a/src/librustc_trans/save/dump_csv.rs b/src/librustc_trans/save/dump_csv.rs index 10840933c01..d8f21fd4dd6 100644 --- a/src/librustc_trans/save/dump_csv.rs +++ b/src/librustc_trans/save/dump_csv.rs @@ -864,9 +864,10 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> { impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> { fn visit_item(&mut self, item: &ast::Item) { + use syntax::ast::ItemKind::*; self.process_macro_use(item.span, item.id); match item.node { - ast::ItemUse(ref use_item) => { + Use(ref use_item) => { match use_item.node { ast::ViewPathSimple(ident, ref path) => { let sub_span = self.span.span_for_last_ident(path.span); @@ -950,7 +951,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> { } } } - ast::ItemExternCrate(ref s) => { + ExternCrate(ref s) => { let location = match *s { Some(s) => s.to_string(), None => item.ident.to_string(), @@ -968,28 +969,28 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> { &location, self.cur_scope); } - ast::ItemFn(ref decl, _, _, _, ref ty_params, ref body) => + Fn(ref decl, _, _, _, ref ty_params, ref body) => self.process_fn(item, &**decl, ty_params, &**body), - ast::ItemStatic(ref typ, _, ref expr) => + Static(ref typ, _, ref expr) => self.process_static_or_const_item(item, typ, expr), - ast::ItemConst(ref typ, ref expr) => + Const(ref typ, ref expr) => self.process_static_or_const_item(item, &typ, &expr), - ast::ItemStruct(ref def, ref ty_params) => self.process_struct(item, def, ty_params), - ast::ItemEnum(ref def, ref ty_params) => self.process_enum(item, def, ty_params), - ast::ItemImpl(_, _, + Struct(ref def, ref ty_params) => self.process_struct(item, def, ty_params), + Enum(ref def, ref ty_params) => self.process_enum(item, def, ty_params), + Impl(_, _, ref ty_params, ref trait_ref, ref typ, ref impl_items) => { self.process_impl(item, ty_params, trait_ref, &typ, impl_items) } - ast::ItemTrait(_, ref generics, ref trait_refs, ref methods) => + Trait(_, ref generics, ref trait_refs, ref methods) => self.process_trait(item, generics, trait_refs, methods), - ast::ItemMod(ref m) => { + Mod(ref m) => { self.process_mod(item); self.nest(item.id, |v| visit::walk_mod(v, m)); } - ast::ItemTy(ref ty, ref ty_params) => { + Ty(ref ty, ref ty_params) => { let qualname = format!("::{}", self.tcx.map.path_to_string(item.id)); let value = ty_to_string(&**ty); let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Type); @@ -998,7 +999,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> { self.visit_ty(&**ty); self.process_generic_params(ty_params, item.span, &qualname, item.id); } - ast::ItemMac(_) => (), + Mac(_) => (), _ => visit::walk_item(self, item), } } diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs index 53fa1bfff38..1790da39ad0 100644 --- a/src/librustc_trans/save/mod.rs +++ b/src/librustc_trans/save/mod.rs @@ -229,7 +229,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { pub fn get_item_data(&self, item: &ast::Item) -> Option { match item.node { - ast::ItemFn(..) => { + ast::ItemKind::Fn(..) => { let name = self.tcx.map.path_to_string(item.id); let qualname = format!("::{}", name); let sub_span = self.span_utils.sub_span_after_keyword(item.span, keywords::Fn); @@ -243,7 +243,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { scope: self.enclosing_scope(item.id), })) } - ast::ItemStatic(ref typ, mt, ref expr) => { + ast::ItemKind::Static(ref typ, mt, ref expr) => { let qualname = format!("::{}", self.tcx.map.path_to_string(item.id)); // If the variable is immutable, save the initialising expression. @@ -264,7 +264,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { type_value: ty_to_string(&typ), })) } - ast::ItemConst(ref typ, ref expr) => { + ast::ItemKind::Const(ref typ, ref expr) => { let qualname = format!("::{}", self.tcx.map.path_to_string(item.id)); let sub_span = self.span_utils.sub_span_after_keyword(item.span, keywords::Const); filter!(self.span_utils, sub_span, item.span, None); @@ -278,7 +278,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { type_value: ty_to_string(&typ), })) } - ast::ItemMod(ref m) => { + ast::ItemKind::Mod(ref m) => { let qualname = format!("::{}", self.tcx.map.path_to_string(item.id)); let cm = self.tcx.sess.codemap(); @@ -295,7 +295,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { filename: filename, })) } - ast::ItemEnum(..) => { + ast::ItemKind::Enum(..) => { let enum_name = format!("::{}", self.tcx.map.path_to_string(item.id)); let val = self.span_utils.snippet(item.span); let sub_span = self.span_utils.sub_span_after_keyword(item.span, keywords::Enum); @@ -308,7 +308,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { scope: self.enclosing_scope(item.id), })) } - ast::ItemImpl(_, _, _, ref trait_ref, ref typ, _) => { + ast::ItemKind::Impl(_, _, _, ref trait_ref, ref typ, _) => { let mut type_data = None; let sub_span; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index f2225ff2c09..7519def1503 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,7 +10,6 @@ // The Rust abstract syntax tree. -pub use self::Item_::*; pub use self::KleeneOp::*; pub use self::MacStmtStyle::*; pub use self::MetaItem_::*; @@ -1828,7 +1827,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 { @@ -1956,7 +1955,7 @@ pub struct Item { pub ident: Ident, pub attrs: Vec, pub id: NodeId, - pub node: Item_, + pub node: ItemKind, pub vis: Visibility, pub span: Span, } @@ -1968,32 +1967,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), + ExternCrate(Option), /// A `use` or `pub use` item - ItemUse(P), + Use(P), /// A `static` item - ItemStatic(P, Mutability, P), + Static(P, Mutability, P), /// A `const` item - ItemConst(P, P), + Const(P, P), /// A function declaration - ItemFn(P, Unsafety, Constness, Abi, Generics, P), + Fn(P, Unsafety, Constness, Abi, Generics, P), /// A module - ItemMod(Mod), + Mod(Mod), /// An external module - ItemForeignMod(ForeignMod), + ForeignMod(ForeignMod), /// A type alias, e.g. `type Foo = Bar` - ItemTy(P, Generics), + Ty(P, Generics), /// An enum definition, e.g. `enum Foo {C, D}` - ItemEnum(EnumDef, Generics), + Enum(EnumDef, Generics), /// A struct definition, e.g. `struct Foo {x: A}` - ItemStruct(VariantData, Generics), + Struct(VariantData, Generics), /// Represents a Trait Declaration - ItemTrait(Unsafety, + Trait(Unsafety, Generics, TyParamBounds, Vec>), @@ -2001,35 +2000,35 @@ pub enum Item_ { // Default trait implementations /// // `impl Trait for .. {}` - ItemDefaultImpl(Unsafety, TraitRef), + DefaultImpl(Unsafety, TraitRef), /// An implementation, eg `impl Trait for Foo { .. }` - ItemImpl(Unsafety, + Impl(Unsafety, ImplPolarity, Generics, Option, // (optional) trait this impl implements P, // self Vec>), /// 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" } } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 8ccff527b88..270133ad599 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -173,7 +173,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/config.rs b/src/libsyntax/config.rs index 840acff73ad..57416bce3cb 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) -> P { // If an expr is valid to cfg away it will have been removed by the @@ -129,26 +129,26 @@ fn fold_item(cx: &mut Context, item: P) -> SmallVector(cx: &mut Context, item: ast::Item_) -> ast::Item_ where +fn fold_item_kind(cx: &mut Context, 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(cx: &mut Context, 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(cx: &mut Context, vdata: ast::VariantData) -> ast::VariantData where diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 4e6fde10ade..e8a4bb59bdc 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -226,7 +226,7 @@ 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, ), 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 ceb7cf69680..381d952ea88 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -120,7 +120,7 @@ impl 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. diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 76071cc71e6..256825eacf2 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -213,7 +213,7 @@ pub trait AstBuilder { // items fn item(&self, span: Span, - name: Ident, attrs: Vec , node: ast::Item_) -> P; + name: Ident, attrs: Vec , node: ast::ItemKind) -> P; fn arg(&self, span: Span, name: Ident, ty: P) -> ast::Arg; // FIXME unused self @@ -951,7 +951,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn item(&self, span: Span, name: Ident, - attrs: Vec, node: ast::Item_) -> P { + attrs: Vec, node: ast::ItemKind) -> P { // FIXME: Would be nice if our generated code didn't violate // Rust coding conventions P(ast::Item { @@ -974,7 +974,7 @@ 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, @@ -1026,7 +1026,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn item_enum_poly(&self, span: Span, name: Ident, enum_definition: ast::EnumDef, generics: Generics) -> P { - 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, @@ -1047,7 +1047,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn item_struct_poly(&self, span: Span, name: Ident, struct_def: ast::VariantData, generics: Generics) -> P { - 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, @@ -1057,7 +1057,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { span, name, attrs, - ast::ItemMod(ast::Mod { + ast::ItemKind::Mod(ast::Mod { inner: inner_span, items: items, }) @@ -1071,7 +1071,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { mutbl: ast::Mutability, expr: P) -> P { - 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, @@ -1080,12 +1080,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ty: P, expr: P) -> P { - 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, generics: Generics) -> P { - 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) -> P { @@ -1125,7 +1125,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 }) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 78bc4e2c735..bcd02fb8cb3 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -10,7 +10,7 @@ use ast::{Block, Crate, DeclKind, PatMac}; use ast::{Local, Ident, Mac_, Name}; -use ast::{ItemMac, MacStmtWithSemicolon, Mrk, Stmt, StmtKind}; +use ast::{MacStmtStyle, Mrk, Stmt, StmtKind, ItemKind}; use ast::TokenTree; use ast; use ext::mtwt; @@ -315,17 +315,17 @@ pub fn expand_item(it: P, 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) } } @@ -362,7 +362,7 @@ fn contains_macro_use(fld: &mut MacroExpander, attrs: &[ast::Attribute]) -> bool pub fn expand_item_mac(it: P, fld: &mut MacroExpander) -> SmallVector> { 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") }); @@ -890,10 +890,10 @@ fn expand_annotatable(a: Annotatable, let mut new_items: SmallVector = 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; @@ -1048,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) } @@ -1194,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) -> SmallVector> { diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 17eb43e2068..6dc0da1eb09 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -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", diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 8c39c48bbc7..8bb915362e8 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) -> SmallVector> { @@ -890,20 +890,20 @@ pub fn noop_fold_block(b: P, folder: &mut T) -> P { }) } -pub fn noop_fold_item_underscore(i: Item_, folder: &mut T) -> Item_ { +pub fn noop_fold_item_kind(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(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(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)), } } @@ -1025,7 +1025,7 @@ pub fn noop_fold_crate(Crate {module, attrs, config, mut exported_mac id: ast::DUMMY_NODE_ID, vis: ast::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(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(i: P, folder: &mut T) -> SmallVector(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 diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 2bbf1699662..a505b27e9db 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -913,7 +913,7 @@ 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::TyKind::Path(None, ast::Path{ diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 4faad48f5b7..4133c024f85 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -23,10 +23,7 @@ use ast::{EMPTY_CTXT, EnumDef, ExplicitSelf}; use ast::{Expr, ExprKind}; use ast::{Field, FnDecl}; use ast::{ForeignItem, ForeignItemKind, 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::{Ident, Inherited, ImplItem, Item, ItemKind}; use ast::{Lit, LitKind, UintTy}; use ast::Local; use ast::{MacStmtWithBraces, MacStmtWithSemicolon, MacStmtWithoutBraces}; @@ -80,7 +77,7 @@ bitflags! { } } -type ItemInfo = (Ident, Item_, Option >); +type ItemInfo = (Ident, ItemKind, Option >); /// How to parse a path. There are four different kinds of paths, all of which /// are parsed somewhat differently. @@ -3750,7 +3747,7 @@ impl<'a> Parser<'a> { 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)))), ast::DUMMY_NODE_ID)) @@ -4590,7 +4587,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) -> P { P(Item { ident: ident, @@ -4612,7 +4609,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 @@ -4772,7 +4769,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 @@ -4835,7 +4832,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()); @@ -4851,7 +4848,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))) } } @@ -4936,7 +4933,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, @@ -5066,8 +5063,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)) } @@ -5091,7 +5088,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))) } } @@ -5197,7 +5194,7 @@ impl<'a> Parser<'a> { id: ast::Ident, outer_attrs: &[ast::Attribute], id_sp: Span) - -> PResult<'a, (ast::Item_, Vec )> { + -> PResult<'a, (ast::ItemKind, Vec )> { let ModulePathSuccess { path, owns_directory } = try!(self.submod_path(id, outer_attrs, id_sp)); @@ -5212,7 +5209,7 @@ impl<'a> Parser<'a> { path: PathBuf, owns_directory: bool, name: String, - id_sp: Span) -> PResult<'a, (ast::Item_, Vec )> { + id_sp: Span) -> PResult<'a, (ast::ItemKind, Vec )> { let mut included_mod_stack = self.sess.included_mod_stack.borrow_mut(); match included_mod_stack.iter().position(|p| *p == path) { Some(i) => { @@ -5240,7 +5237,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 @@ -5315,7 +5312,7 @@ impl<'a> Parser<'a> { Ok(self.mk_item(lo, last_span.hi, ident, - ItemExternCrate(maybe_path), + ItemKind::ExternCrate(maybe_path), visibility, attrs)) } @@ -5356,7 +5353,7 @@ impl<'a> Parser<'a> { Ok(self.mk_item(lo, last_span.hi, special_idents::invalid, - ItemForeignMod(m), + ItemKind::ForeignMod(m), visibility, attrs)) } @@ -5369,7 +5366,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 '{' @@ -5430,7 +5427,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 @@ -5488,7 +5485,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; @@ -5804,7 +5801,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, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index becf2d2bc14..167df26f433 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1117,7 +1117,7 @@ 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 { @@ -1136,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)); @@ -1144,7 +1144,7 @@ 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 { @@ -1161,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)); @@ -1175,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, @@ -1190,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)); @@ -1199,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"))); @@ -1221,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, @@ -1230,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)); @@ -1247,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, @@ -1290,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)); @@ -1316,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, "! ")); @@ -1596,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)); diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index 345adff2344..828896d422c 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -89,7 +89,7 @@ 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)), + node: ast::ItemKind::ExternCrate(Some(self.crate_name)), vis: ast::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_ { diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 24890d2cbed..a817eb62af8 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")); } @@ -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 { @@ -262,7 +262,7 @@ fn mk_reexport_mod(cx: &mut TestCtxt, tests: Vec, ident: sym.clone(), attrs: Vec::new(), id: ast::DUMMY_NODE_ID, - node: ast::ItemMod(reexport_mod), + node: ast::ItemKind::Mod(reexport_mod), vis: ast::Public, span: DUMMY_SP, }); @@ -355,7 +355,7 @@ 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::FunctionRetTy::Default(..) => true, ast::FunctionRetTy::Ty(ref t) if t.node == ast::TyKind::Tup(vec![]) => true, @@ -391,7 +391,7 @@ 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::FunctionRetTy::Default(..) => true, @@ -453,12 +453,12 @@ mod __test { fn mk_std(cx: &TestCtxt) -> P { 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) } else { - (ast::ItemExternCrate(None), ast::Inherited, id_test) + (ast::ItemKind::ExternCrate(None), ast::Inherited, id_test) }; P(ast::Item { id: ast::DUMMY_NODE_ID, @@ -496,7 +496,7 @@ fn mk_main(cx: &mut TestCtxt) -> P { // pub fn main() { ... } 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::Abi::Rust, ast::Generics::default(), main_body); @@ -527,7 +527,7 @@ fn mk_test_module(cx: &mut TestCtxt) -> (P, Option>) { 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 { @@ -550,7 +550,7 @@ fn mk_test_module(cx: &mut TestCtxt) -> (P, Option>) { id: ast::DUMMY_NODE_ID, ident: token::special_idents::invalid, attrs: vec![], - node: ast::ItemUse(P(use_path)), + node: ast::ItemKind::Use(P(use_path)), vis: ast::Inherited, span: DUMMY_SP }) diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 54b3eccefc6..4082bcbe38e 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -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); } diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index e54ff637f25..51091b84672 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -391,13 +391,13 @@ impl<'a> TraitDef<'a> { match *item { Annotatable::Item(ref item) => { let newitem = match item.node { - ast::ItemStruct(ref struct_def, ref generics) => { + ast::ItemKind::Struct(ref struct_def, ref generics) => { self.expand_struct_def(cx, &struct_def, item.ident, generics) } - ast::ItemEnum(ref enum_def, ref generics) => { + ast::ItemKind::Enum(ref enum_def, ref generics) => { self.expand_enum_def(cx, enum_def, &item.attrs, @@ -637,12 +637,12 @@ impl<'a> TraitDef<'a> { self.span, ident, a, - ast::ItemImpl(unsafety, - ast::ImplPolarity::Positive, - trait_generics, - opt_trait_ref, - self_type, - methods.into_iter().chain(associated_types).collect())) + ast::ItemKind::Impl(unsafety, + ast::ImplPolarity::Positive, + trait_generics, + opt_trait_ref, + self_type, + methods.into_iter().chain(associated_types).collect())) } fn expand_struct_def(&self, diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index 831a6250c9f..a5ad143f15b 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -453,7 +453,7 @@ impl<'a, 'b> Context<'a, 'b> { ast::MutImmutable); let slice = ecx.expr_vec_slice(sp, pieces); // static instead of const to speed up codegen by not requiring this to be inlined - let st = ast::ItemStatic(ty, ast::MutImmutable, slice); + let st = ast::ItemKind::Static(ty, ast::MutImmutable, slice); let name = ecx.ident_of(name); let item = ecx.item(sp, name, vec![], st); diff --git a/src/test/auxiliary/macro_crate_test.rs b/src/test/auxiliary/macro_crate_test.rs index fe61c80b4c3..2c68296b634 100644 --- a/src/test/auxiliary/macro_crate_test.rs +++ b/src/test/auxiliary/macro_crate_test.rs @@ -16,7 +16,7 @@ extern crate syntax; extern crate rustc; extern crate rustc_plugin; -use syntax::ast::{self, TokenTree, Item, MetaItem, ImplItem, TraitItem}; +use syntax::ast::{self, TokenTree, Item, MetaItem, ImplItem, TraitItem, ItemKind}; use syntax::codemap::Span; use syntax::ext::base::*; use syntax::parse::{self, token}; @@ -73,7 +73,7 @@ fn expand_into_foo_multi(cx: &mut ExtCtxt, Annotatable::ImplItem(it) => { quote_item!(cx, impl X { fn foo(&self) -> i32 { 42 } }).unwrap().and_then(|i| { match i.node { - ast::ItemImpl(_, _, _, _, _, mut items) => { + ItemKind::Impl(_, _, _, _, _, mut items) => { Annotatable::ImplItem(items.pop().expect("impl method not found")) } _ => unreachable!("impl parsed to something other than impl") @@ -83,7 +83,7 @@ fn expand_into_foo_multi(cx: &mut ExtCtxt, Annotatable::TraitItem(it) => { quote_item!(cx, trait X { fn foo(&self) -> i32 { 0 } }).unwrap().and_then(|i| { match i.node { - ast::ItemTrait(_, _, _, mut items) => { + ItemKind::Trait(_, _, _, mut items) => { Annotatable::TraitItem(items.pop().expect("trait method not found")) } _ => unreachable!("trait parsed to something other than trait") From 798974cae58639c174010fd4a6411dcdc860e404 Mon Sep 17 00:00:00 2001 From: Oliver 'ker' Schneider Date: Tue, 9 Feb 2016 11:45:01 +0100 Subject: [PATCH 21/29] [breaking-change] don't glob export ast::KleeneOp variants --- src/libsyntax/ast.rs | 1 - src/libsyntax/ext/quote.rs | 16 +++++++++------- src/libsyntax/ext/tt/macro_parser.rs | 2 +- src/libsyntax/ext/tt/macro_rules.rs | 4 ++-- src/libsyntax/ext/tt/transcribe.rs | 4 ++-- src/libsyntax/parse/parser.rs | 4 ++-- src/libsyntax/print/pprust.rs | 4 ++-- 7 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 7519def1503..6814f41f017 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,7 +10,6 @@ // The Rust abstract syntax tree. -pub use self::KleeneOp::*; pub use self::MacStmtStyle::*; pub use self::MetaItem_::*; pub use self::Mutability::*; diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 44ef74fcc0c..8c86205fed4 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -542,11 +542,6 @@ fn mk_tt_path(cx: &ExtCtxt, sp: Span, name: &str) -> P { cx.expr_path(cx.path_global(sp, idents)) } -fn mk_ast_path(cx: &ExtCtxt, sp: Span, name: &str) -> P { - 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 { let idents = vec!(id_ext("syntax"), id_ext("parse"), id_ext("token"), id_ext(name)); cx.expr_path(cx.path_global(sp, idents)) @@ -779,9 +774,16 @@ fn statements_mk_tt(cx: &ExtCtxt, tt: &TokenTree, matcher: bool) -> Vec 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), 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/parse/parser.rs b/src/libsyntax/parse/parser.rs index 4133c024f85..5121f6e1561 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2599,11 +2599,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) } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 167df26f433..0a73ccd6d12 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1489,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, "+"), } } } From e797e1961df00ec7725c47225dcf9b5a0e9fce64 Mon Sep 17 00:00:00 2001 From: Oliver 'ker' Schneider Date: Tue, 9 Feb 2016 11:56:59 +0100 Subject: [PATCH 22/29] [breaking-change] don't glob export ast::MacStmtStyle --- src/libsyntax/ast.rs | 7 +++---- src/libsyntax/ext/expand.rs | 2 +- src/libsyntax/parse/parser.rs | 14 +++++++------- src/libsyntax/print/pprust.rs | 4 ++-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 6814f41f017..b94c033e48a 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,7 +10,6 @@ // The Rust abstract syntax tree. -pub use self::MacStmtStyle::*; pub use self::MetaItem_::*; pub use self::Mutability::*; pub use self::Pat_::*; @@ -782,13 +781,13 @@ impl StmtKind { 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 diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index bcd02fb8cb3..6b3e2501761 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -533,7 +533,7 @@ fn expand_stmt(stmt: P, fld: &mut MacroExpander) -> SmallVector> { // 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 { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 5121f6e1561..0875d054564 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -26,7 +26,7 @@ use ast::{ForeignItem, ForeignItemKind, FunctionRetTy}; use ast::{Ident, Inherited, ImplItem, Item, ItemKind}; use ast::{Lit, LitKind, UintTy}; use ast::Local; -use ast::{MacStmtWithBraces, MacStmtWithSemicolon, MacStmtWithoutBraces}; +use ast::MacStmtStyle; use ast::{MutImmutable, MutMutable, Mac_}; use ast::{MutTy, Mutability}; use ast::NamedField; @@ -3721,9 +3721,9 @@ 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 { @@ -3734,7 +3734,7 @@ impl<'a> Parser<'a> { // 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, @@ -3841,13 +3841,13 @@ impl<'a> Parser<'a> { StmtKind::Expr(e, _) => { try!(self.handle_expression_like_statement(e, span, &mut stmts, &mut expr)); } - StmtKind::Mac(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: StmtKind::Mac(mac, MacStmtWithSemicolon, attrs), + node: StmtKind::Mac(mac, MacStmtStyle::Semicolon, attrs), span: mk_sp(span.lo, self.span.hi), })); self.bump(); @@ -3872,7 +3872,7 @@ impl<'a> Parser<'a> { match self.token { token::Semi => { stmts.push(P(Spanned { - node: StmtKind::Mac(m, MacStmtWithSemicolon, attrs), + node: StmtKind::Mac(m, MacStmtStyle::Semicolon, attrs), span: mk_sp(span.lo, self.span.hi), })); self.bump(); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 0a73ccd6d12..2c2414e54ea 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1629,12 +1629,12 @@ impl<'a> State<'a> { 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, ";")), } } From 14e09ad4686bb20a98acfd7d930386f6330d2b4d Mon Sep 17 00:00:00 2001 From: Oliver 'ker' Schneider Date: Tue, 9 Feb 2016 12:05:20 +0100 Subject: [PATCH 23/29] [breaking-change] don't glob export ast::MetaItem_ --- src/librustc/lint/context.rs | 4 +- src/librustc_driver/lib.rs | 10 ++--- src/librustc_front/fold.rs | 10 ++--- src/librustc_lint/builtin.rs | 2 +- src/librustc_metadata/decoder.rs | 2 +- src/librustc_metadata/encoder.rs | 6 +-- src/librustc_metadata/macro_import.rs | 4 +- src/librustc_trans/trans/assert_dep_graph.rs | 6 +-- src/librustc_trans/trans/debuginfo/utils.rs | 2 +- src/librustdoc/clean/mod.rs | 6 +-- src/libsyntax/ast.rs | 30 +++++++------- src/libsyntax/attr.rs | 43 ++++++++++---------- src/libsyntax/config.rs | 2 +- src/libsyntax/ext/build.rs | 6 +-- src/libsyntax/ext/expand.rs | 2 +- src/libsyntax/feature_gate.rs | 2 +- src/libsyntax/fold.rs | 8 ++-- src/libsyntax/parse/attr.rs | 6 +-- src/libsyntax/print/pprust.rs | 6 +-- src/libsyntax/std_inject.rs | 2 +- src/libsyntax_ext/deriving/mod.rs | 4 +- src/test/auxiliary/macro_crate_test.rs | 4 +- 22 files changed, 83 insertions(+), 84 deletions(-) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 55782041be6..5af184385d9 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -374,7 +374,7 @@ pub fn gather_attr(attr: &ast::Attribute) let meta = &attr.node.value; let metas = match meta.node { - ast::MetaList(_, ref metas) => metas, + ast::MetaItemKind::List(_, ref metas) => metas, _ => { out.push(Err(meta.span)); return out; @@ -383,7 +383,7 @@ pub fn gather_attr(attr: &ast::Attribute) for meta in metas { out.push(match meta.node { - ast::MetaWord(ref lint_name) => Ok((lint_name.clone(), level, meta.span)), + ast::MetaItemKind::Word(ref lint_name) => Ok((lint_name.clone(), level, meta.span)), _ => Err(meta.span), }); } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index c0e935f7952..fdee13cb715 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -560,18 +560,18 @@ impl RustcDefaultCalls { PrintRequest::Cfg => { for cfg in config::build_configuration(sess) { match cfg.node { - ast::MetaWord(ref word) => println!("{}", word), - ast::MetaNameValue(ref name, ref value) => { + ast::MetaItemKind::Word(ref word) => println!("{}", word), + ast::MetaItemKind::NameValue(ref name, ref value) => { println!("{}=\"{}\"", name, match value.node { ast::LitKind::Str(ref s, _) => s, _ => continue, }); } // Right now there are not and should not be any - // MetaList items in the configuration returned by + // MetaItemKind::List items in the configuration returned by // `build_configuration`. - ast::MetaList(..) => { - panic!("MetaList encountered in default cfg") + ast::MetaItemKind::List(..) => { + panic!("MetaItemKind::List encountered in default cfg") } } } diff --git a/src/librustc_front/fold.rs b/src/librustc_front/fold.rs index e456b1eadf5..4e2729f3dab 100644 --- a/src/librustc_front/fold.rs +++ b/src/librustc_front/fold.rs @@ -13,7 +13,7 @@ use hir::*; use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, Attribute, Attribute_, MetaItem}; -use syntax::ast::{MetaWord, MetaList, MetaNameValue}; +use syntax::ast::MetaItemKind; use syntax::attr::ThinAttributesExt; use hir; use syntax::codemap::{respan, Span, Spanned}; @@ -522,11 +522,11 @@ pub fn noop_fold_meta_item(mi: P, fld: &mut T) -> P 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), } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index d90e145454c..ed16a11f550 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -308,7 +308,7 @@ impl MissingDoc { let has_doc = attrs.iter().any(|a| { match a.node.value.node { - ast::MetaNameValue(ref name, _) if *name == "doc" => true, + ast::MetaItemKind::NameValue(ref name, _) if *name == "doc" => true, _ => false } }); diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index f73d6f0de2c..5ba9e566e00 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -1170,7 +1170,7 @@ fn get_meta_items(md: rbml::Doc) -> Vec> { let vd = reader::get_doc(meta_item_doc, tag_meta_item_value); let n = token::intern_and_get_ident(nd.as_str_slice()); let v = token::intern_and_get_ident(vd.as_str_slice()); - // FIXME (#623): Should be able to decode MetaNameValue variants, + // FIXME (#623): Should be able to decode MetaItemKind::NameValue variants, // but currently the encoder just drops them attr::mk_name_value_item_str(n, v) })).chain(reader::tagged_docs(md, tag_meta_item_list).map(|meta_item_doc| { diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 9afbe5f1dbb..6375f82b2c5 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -1541,12 +1541,12 @@ fn encode_item_index(rbml_w: &mut Encoder, index: IndexData) { fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) { match mi.node { - ast::MetaWord(ref name) => { + ast::MetaItemKind::Word(ref name) => { rbml_w.start_tag(tag_meta_item_word); rbml_w.wr_tagged_str(tag_meta_item_name, name); rbml_w.end_tag(); } - ast::MetaNameValue(ref name, ref value) => { + ast::MetaItemKind::NameValue(ref name, ref value) => { match value.node { ast::LitKind::Str(ref value, _) => { rbml_w.start_tag(tag_meta_item_name_value); @@ -1557,7 +1557,7 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) { _ => {/* FIXME (#623): encode other variants */ } } } - ast::MetaList(ref name, ref items) => { + ast::MetaItemKind::List(ref name, ref items) => { rbml_w.start_tag(tag_meta_item_list); rbml_w.wr_tagged_str(tag_meta_item_name, name); for inner_item in items { diff --git a/src/librustc_metadata/macro_import.rs b/src/librustc_metadata/macro_import.rs index b2395ac355f..102bcc10fac 100644 --- a/src/librustc_metadata/macro_import.rs +++ b/src/librustc_metadata/macro_import.rs @@ -95,7 +95,7 @@ impl<'a, 'v> Visitor<'v> for MacroLoader<'a> { } if let (Some(sel), Some(names)) = (import.as_mut(), names) { for attr in names { - if let ast::MetaWord(ref name) = attr.node { + if let ast::MetaItemKind::Word(ref name) = attr.node { sel.insert(name.clone(), attr.span); } else { span_err!(self.sess, attr.span, E0466, "bad macro import"); @@ -113,7 +113,7 @@ impl<'a, 'v> Visitor<'v> for MacroLoader<'a> { }; for attr in names { - if let ast::MetaWord(ref name) = attr.node { + if let ast::MetaItemKind::Word(ref name) = attr.node { reexport.insert(name.clone(), attr.span); } else { call_bad_macro_reexport(self.sess, attr.span); diff --git a/src/librustc_trans/trans/assert_dep_graph.rs b/src/librustc_trans/trans/assert_dep_graph.rs index 3d6a6a8fa77..6171d05fef0 100644 --- a/src/librustc_trans/trans/assert_dep_graph.rs +++ b/src/librustc_trans/trans/assert_dep_graph.rs @@ -96,7 +96,7 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> { let mut id = None; for meta_item in attr.meta_item_list().unwrap_or_default() { match meta_item.node { - ast::MetaWord(ref s) if id.is_none() => id = Some(s.clone()), + ast::MetaItemKind::Word(ref s) if id.is_none() => id = Some(s.clone()), _ => { self.tcx.sess.span_err( meta_item.span, @@ -113,9 +113,9 @@ impl<'a, 'tcx> IfThisChanged<'a, 'tcx> { let mut id = None; for meta_item in attr.meta_item_list().unwrap_or_default() { match meta_item.node { - ast::MetaWord(ref s) if dep_node_interned.is_none() => + ast::MetaItemKind::Word(ref s) if dep_node_interned.is_none() => dep_node_interned = Some(s.clone()), - ast::MetaWord(ref s) if id.is_none() => + ast::MetaItemKind::Word(ref s) if id.is_none() => id = Some(s.clone()), _ => { self.tcx.sess.span_err( diff --git a/src/librustc_trans/trans/debuginfo/utils.rs b/src/librustc_trans/trans/debuginfo/utils.rs index 276f9936ac5..e581e19d433 100644 --- a/src/librustc_trans/trans/debuginfo/utils.rs +++ b/src/librustc_trans/trans/debuginfo/utils.rs @@ -48,7 +48,7 @@ pub fn contains_nodebug_attribute(attributes: &[ast::Attribute]) -> bool { attributes.iter().any(|attr| { let meta_item: &ast::MetaItem = &*attr.node.value; match meta_item.node { - ast::MetaWord(ref value) => &value[..] == "no_debug", + ast::MetaItemKind::Word(ref value) => &value[..] == "no_debug", _ => false } }) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 2a346b773e6..ca05806d8f9 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -451,11 +451,11 @@ pub enum Attribute { impl Clean for ast::MetaItem { fn clean(&self, cx: &DocContext) -> Attribute { match self.node { - ast::MetaWord(ref s) => Word(s.to_string()), - ast::MetaList(ref s, ref l) => { + ast::MetaItemKind::Word(ref s) => Word(s.to_string()), + ast::MetaItemKind::List(ref s, ref l) => { List(s.to_string(), l.clean(cx)) } - ast::MetaNameValue(ref s, ref v) => { + ast::MetaItemKind::NameValue(ref s, ref v) => { NameValue(s.to_string(), lit_to_string(v)) } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index b94c033e48a..a3a59b7898b 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,7 +10,6 @@ // The Rust abstract syntax tree. -pub use self::MetaItem_::*; pub use self::Mutability::*; pub use self::Pat_::*; pub use self::PathListItem_::*; @@ -476,31 +475,32 @@ pub struct Crate { pub exported_macros: Vec, } -pub type MetaItem = Spanned; +pub type MetaItem = Spanned; #[derive(Clone, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum MetaItem_ { - MetaWord(InternedString), - MetaList(InternedString, Vec>), - MetaNameValue(InternedString, Lit), +pub enum MetaItemKind { + Word(InternedString), + List(InternedString, Vec>), + 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)) } diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index f9c41ee43dd..53ab4e1b6d5 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -15,7 +15,7 @@ pub use self::ReprAttr::*; pub use self::IntType::*; use ast; -use ast::{AttrId, Attribute, Attribute_, MetaItem, MetaWord, MetaNameValue, MetaList}; +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}; @@ -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; /// Gets a list of inner meta items from a list MetaItem type. @@ -96,15 +96,15 @@ 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 { match self.node { - MetaNameValue(_, ref v) => { + MetaItemKind::NameValue(_, ref v) => { match v.node { ast::LitKind::Str(ref s, _) => Some((*s).clone()), _ => None, @@ -116,7 +116,7 @@ impl AttrMetaMethods for MetaItem { fn meta_item_list(&self) -> Option<&[P]> { match self.node { - MetaList(_, ref l) => Some(&l[..]), + MetaItemKind::List(_, ref l) => Some(&l[..]), _ => None } } @@ -179,15 +179,15 @@ pub fn mk_name_value_item_str(name: InternedString, value: InternedString) pub fn mk_name_value_item(name: InternedString, value: ast::Lit) -> P { - P(dummy_spanned(MetaNameValue(name, value))) + P(dummy_spanned(MetaItemKind::NameValue(name, value))) } pub fn mk_list_item(name: InternedString, items: Vec>) -> P { - P(dummy_spanned(MetaList(name, items))) + P(dummy_spanned(MetaItemKind::List(name, items))) } pub fn mk_word_item(name: InternedString) -> P { - P(dummy_spanned(MetaWord(name))) + P(dummy_spanned(MetaItemKind::Word(name))) } thread_local! { static NEXT_ATTR_ID: Cell = Cell::new(0) } @@ -229,8 +229,7 @@ pub fn mk_sugared_doc_attr(id: AttrId, text: InternedString, lo: BytePos, 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>) -> Vec> { 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(cfgs: &[P], 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(cfgs: &[P], } !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]) { pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec { 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), diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index 57416bce3cb..09408f68dfd 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -270,7 +270,7 @@ fn in_cfg(cfg: &[P], 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 }; diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 256825eacf2..a807fbb93fb 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -1102,21 +1102,21 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn meta_word(&self, sp: Span, w: InternedString) -> P { - P(respan(sp, ast::MetaWord(w))) + P(respan(sp, ast::MetaItemKind::Word(w))) } fn meta_list(&self, sp: Span, name: InternedString, mis: Vec> ) -> P { - 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::LitKind) -> P { - 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, diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 6b3e2501761..c53001e665e 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -348,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; diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 6dc0da1eb09..b04f6b06639 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1138,7 +1138,7 @@ fn check_crate_inner(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 8bb915362e8..722a65fa526 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -556,11 +556,11 @@ pub fn noop_fold_mac(Spanned {node, span}: Mac, fld: &mut T) -> Mac { pub fn noop_fold_meta_item(mi: P, fld: &mut T) -> P { 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) }) diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index 3f9f2ae44a3..505e543a3fb 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -182,16 +182,16 @@ impl<'a> Parser<'a> { } } 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/print/pprust.rs b/src/libsyntax/print/pprust.rs index 2c2414e54ea..8495853c2c9 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -766,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, diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index 828896d422c..996a2ee006e 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -157,7 +157,7 @@ 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, }, diff --git a/src/libsyntax_ext/deriving/mod.rs b/src/libsyntax_ext/deriving/mod.rs index dcaa9644603..4e2142f1fb4 100644 --- a/src/libsyntax_ext/deriving/mod.rs +++ b/src/libsyntax_ext/deriving/mod.rs @@ -13,7 +13,7 @@ //! FIXME (#2810): hygiene. Search for "__" strings (in other files too). We also assume "extra" is //! the standard library, and "std" is the core library. -use syntax::ast::{MetaItem, MetaWord}; +use syntax::ast::{MetaItem, MetaItemKind}; use syntax::attr::AttrMetaMethods; use syntax::ext::base::{ExtCtxt, SyntaxEnv, Annotatable}; use syntax::ext::base::{MultiDecorator, MultiItemDecorator, MultiModifier}; @@ -94,7 +94,7 @@ fn expand_derive(cx: &mut ExtCtxt, for titem in traits.iter().rev() { let tname = match titem.node { - MetaWord(ref tname) => tname, + MetaItemKind::Word(ref tname) => tname, _ => { cx.span_err(titem.span, "malformed `derive` entry"); continue; diff --git a/src/test/auxiliary/macro_crate_test.rs b/src/test/auxiliary/macro_crate_test.rs index 2c68296b634..c4cfa36542f 100644 --- a/src/test/auxiliary/macro_crate_test.rs +++ b/src/test/auxiliary/macro_crate_test.rs @@ -101,8 +101,8 @@ fn expand_duplicate(cx: &mut ExtCtxt, push: &mut FnMut(Annotatable)) { let copy_name = match mi.node { - ast::MetaItem_::MetaList(_, ref xs) => { - if let ast::MetaItem_::MetaWord(ref w) = xs[0].node { + ast::MetaItemKind::List(_, ref xs) => { + if let ast::MetaItemKind::Word(ref w) = xs[0].node { token::str_to_ident(&w) } else { cx.span_err(mi.span, "Expected word"); From 73fa9b2da2ee82c91a5c8d605b91f22f19e4d74b Mon Sep 17 00:00:00 2001 From: Oliver 'ker' Schneider Date: Tue, 9 Feb 2016 17:44:47 +0100 Subject: [PATCH 24/29] [breaking-change] don't glob export ast::Mutablity variants --- src/librustc/middle/ty/relate.rs | 4 +-- src/librustc_front/lowering.rs | 4 +-- src/librustc_passes/const_fn.rs | 2 +- src/librustc_trans/save/dump_csv.rs | 4 +-- src/librustc_trans/save/mod.rs | 12 ++++--- src/libsyntax/ast.rs | 5 ++- src/libsyntax/ast_util.rs | 3 +- src/libsyntax/diagnostics/plugin.rs | 2 +- src/libsyntax/ext/build.rs | 13 +++++--- src/libsyntax/parse/mod.rs | 4 +-- src/libsyntax/parse/parser.rs | 40 +++++++++++++---------- src/libsyntax/print/pprust.rs | 22 ++++++------- src/libsyntax/test.rs | 4 +-- src/libsyntax_ext/deriving/debug.rs | 2 +- src/libsyntax_ext/deriving/decodable.rs | 4 +-- src/libsyntax_ext/deriving/encodable.rs | 4 +-- src/libsyntax_ext/deriving/generic/mod.rs | 17 ++++++---- src/libsyntax_ext/deriving/generic/ty.rs | 2 +- src/libsyntax_ext/deriving/hash.rs | 4 +-- src/libsyntax_ext/env.rs | 2 +- src/libsyntax_ext/format.rs | 6 ++-- 21 files changed, 87 insertions(+), 73 deletions(-) diff --git a/src/librustc/middle/ty/relate.rs b/src/librustc/middle/ty/relate.rs index 46bc13bd598..974b5c4bc6c 100644 --- a/src/librustc/middle/ty/relate.rs +++ b/src/librustc/middle/ty/relate.rs @@ -105,8 +105,8 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::TypeAndMut<'tcx> { } else { let mutbl = a.mutbl; let variance = match mutbl { - ast::MutImmutable => ty::Covariant, - ast::MutMutable => ty::Invariant, + ast::Mutability::MutImmutable => ty::Covariant, + ast::Mutability::MutMutable => ty::Invariant, }; let ty = try!(relation.relate_with_variance(variance, &a.ty, &b.ty)); Ok(ty::TypeAndMut {ty: ty, mutbl: mutbl}) diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index d04f4c96504..e9dfa1bd164 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -427,8 +427,8 @@ pub fn lower_explicit_self_underscore(lctx: &LoweringContext, pub fn lower_mutability(_lctx: &LoweringContext, m: Mutability) -> hir::Mutability { match m { - MutMutable => hir::MutMutable, - MutImmutable => hir::MutImmutable, + Mutability::Mutable => hir::MutMutable, + Mutability::Immutable => hir::MutImmutable, } } diff --git a/src/librustc_passes/const_fn.rs b/src/librustc_passes/const_fn.rs index 98346f538b0..edbc6424ccd 100644 --- a/src/librustc_passes/const_fn.rs +++ b/src/librustc_passes/const_fn.rs @@ -105,7 +105,7 @@ impl<'a, 'v> Visitor<'v> for CheckConstFn<'a> { for arg in &fd.inputs { match arg.pat.node { ast::PatWild => {} - ast::PatIdent(ast::BindingMode::ByValue(ast::MutImmutable), _, None) => {} + ast::PatIdent(ast::BindingMode::ByValue(ast::Mutability::Immutable), _, None) => {} _ => { span_err!(self.sess, arg.pat.span, E0022, "arguments of constant functions can only \ diff --git a/src/librustc_trans/save/dump_csv.rs b/src/librustc_trans/save/dump_csv.rs index d8f21fd4dd6..68c04427c65 100644 --- a/src/librustc_trans/save/dump_csv.rs +++ b/src/librustc_trans/save/dump_csv.rs @@ -807,7 +807,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> { self.visit_pat(&p); for &(id, ref p, immut, _) in &collector.collected_paths { - let value = if immut == ast::MutImmutable { + let value = if immut == ast::Mutability::Immutable { value.to_string() } else { "".to_string() @@ -1200,7 +1200,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> { let def = def_map.get(&id).unwrap().full_def(); match def { Def::Local(_, id) => { - let value = if immut == ast::MutImmutable { + let value = if immut == ast::Mutability::Immutable { self.span.snippet(p.span).to_string() } else { "".to_string() diff --git a/src/librustc_trans/save/mod.rs b/src/librustc_trans/save/mod.rs index 1790da39ad0..ff19640d645 100644 --- a/src/librustc_trans/save/mod.rs +++ b/src/librustc_trans/save/mod.rs @@ -248,8 +248,10 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { // If the variable is immutable, save the initialising expression. let (value, keyword) = match mt { - ast::MutMutable => (String::from(""), keywords::Mut), - ast::MutImmutable => (self.span_utils.snippet(expr.span), keywords::Static), + ast::Mutability::Mutable => (String::from(""), keywords::Mut), + ast::Mutability::Immutable => { + (self.span_utils.snippet(expr.span), keywords::Static) + }, }; let sub_span = self.span_utils.sub_span_after_keyword(item.span, keyword); @@ -758,12 +760,12 @@ impl<'v> Visitor<'v> for PathCollector { match p.node { ast::PatStruct(ref path, _, _) => { self.collected_paths.push((p.id, path.clone(), - ast::MutMutable, recorder::TypeRef)); + ast::Mutability::Mutable, recorder::TypeRef)); } ast::PatEnum(ref path, _) | ast::PatQPath(_, ref path) => { self.collected_paths.push((p.id, path.clone(), - ast::MutMutable, recorder::VarRef)); + ast::Mutability::Mutable, recorder::VarRef)); } ast::PatIdent(bm, ref path1, _) => { debug!("PathCollector, visit ident in pat {}: {:?} {:?}", @@ -774,7 +776,7 @@ impl<'v> Visitor<'v> for PathCollector { // Even if the ref is mut, you can't change the ref, only // the data pointed at, so showing the initialising expression // is still worthwhile. - ast::BindingMode::ByRef(_) => ast::MutImmutable, + ast::BindingMode::ByRef(_) => ast::Mutability::Immutable, ast::BindingMode::ByValue(mt) => mt, }; // collect path for either visit_local or visit_arm diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index a3a59b7898b..cfaa5fc4a96 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -10,7 +10,6 @@ // The Rust abstract syntax tree. -pub use self::Mutability::*; pub use self::Pat_::*; pub use self::PathListItem_::*; pub use self::StrStyle::*; @@ -602,8 +601,8 @@ 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)] diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 270133ad599..e22cdab97e8 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -66,9 +66,10 @@ pub fn path_to_ident(path: &Path) -> Option { } pub fn ident_to_pat(id: NodeId, s: Span, i: Ident) -> P { + 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 }) } diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index e8a4bb59bdc..2e343948c42 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -207,7 +207,7 @@ 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( diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index a807fbb93fb..e32dcc99a0e 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -512,7 +512,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident, ex: P) -> P { 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) }; @@ -536,7 +537,8 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ex: P) -> P { 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) }; @@ -636,10 +638,10 @@ impl<'a> AstBuilder for ExtCtxt<'a> { self.expr(sp, ast::ExprKind::TupField(expr, id)) } fn expr_addr_of(&self, sp: Span, e: P) -> P { - self.expr(sp, ast::ExprKind::AddrOf(ast::MutImmutable, e)) + self.expr(sp, ast::ExprKind::AddrOf(ast::Mutability::Immutable, e)) } fn expr_mut_addr_of(&self, sp: Span, e: P) -> P { - self.expr(sp, ast::ExprKind::AddrOf(ast::MutMutable, e)) + self.expr(sp, ast::ExprKind::AddrOf(ast::Mutability::Mutable, e)) } fn expr_call(&self, span: Span, expr: P, args: Vec>) -> P { @@ -813,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 { - 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, diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index a505b27e9db..850b4365256 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -896,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") }, @@ -932,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")}, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 0875d054564..11638a3d424 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -27,7 +27,7 @@ use ast::{Ident, Inherited, ImplItem, Item, ItemKind}; use ast::{Lit, LitKind, UintTy}; use ast::Local; use ast::MacStmtStyle; -use ast::{MutImmutable, MutMutable, Mac_}; +use ast::Mac_; use ast::{MutTy, Mutability}; use ast::NamedField; use ast::{Pat, PatBox, PatEnum, PatIdent, PatLit, PatQPath, PatMac, PatRange}; @@ -1417,16 +1417,16 @@ impl<'a> Parser<'a> { 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 }) @@ -1924,9 +1924,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) } } @@ -3350,10 +3350,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{ @@ -3448,7 +3448,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()); @@ -3481,7 +3481,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() { @@ -4408,7 +4409,7 @@ impl<'a> Parser<'a> { if this.look_ahead(1, |t| t.is_keyword(keywords::SelfValue)) { this.bump(); - Ok(SelfKind::Region(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(); @@ -4418,7 +4419,8 @@ impl<'a> Parser<'a> { this.look_ahead(2, |t| t.is_keyword(keywords::SelfValue)) { this.bump(); let lifetime = try!(this.parse_lifetime()); - Ok(SelfKind::Region(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)) { @@ -4439,7 +4441,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)); @@ -4454,7 +4456,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; @@ -5527,7 +5529,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, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 8495853c2c9..b14117c9704 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -417,7 +417,7 @@ pub fn lit_to_string(l: &ast::Lit) -> String { } pub fn explicit_self_to_string(explicit_self: &ast::SelfKind) -> String { - to_string(|s| s.print_explicit_self(explicit_self, ast::MutImmutable).map(|_| {})) + to_string(|s| s.print_explicit_self(explicit_self, ast::Mutability::Immutable).map(|_| {})) } pub fn variant_to_string(var: &ast::Variant) -> String { @@ -965,8 +965,8 @@ impl<'a> State<'a> { 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)); } @@ -1147,7 +1147,7 @@ impl<'a> State<'a> { 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)); @@ -2464,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")); } } @@ -2534,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)); @@ -2669,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::SelfKind::Static => 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)); @@ -2946,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(()), } } diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index a817eb62af8..92ecadd7ae8 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -593,7 +593,7 @@ fn mk_tests(cx: &TestCtxt) -> P { let static_type = ecx.ty_rptr(sp, 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,7 +613,7 @@ fn mk_test_descs(cx: &TestCtxt) -> P { P(ast::Expr { id: ast::DUMMY_NODE_ID, - node: ast::ExprKind::AddrOf(ast::MutImmutable, + node: ast::ExprKind::AddrOf(ast::Mutability::Immutable, P(ast::Expr { id: ast::DUMMY_NODE_ID, node: ast::ExprKind::Vec(cx.testfns.iter().map(|test| { diff --git a/src/libsyntax_ext/deriving/debug.rs b/src/libsyntax_ext/deriving/debug.rs index 917c6b1ab89..6e769cd3810 100644 --- a/src/libsyntax_ext/deriving/debug.rs +++ b/src/libsyntax_ext/deriving/debug.rs @@ -27,7 +27,7 @@ pub fn expand_deriving_debug(cx: &mut ExtCtxt, { // &mut ::std::fmt::Formatter let fmtr = Ptr(Box::new(Literal(path_std!(cx, core::fmt::Formatter))), - Borrowed(None, ast::MutMutable)); + Borrowed(None, ast::Mutability::Mutable)); let trait_def = TraitDef { span: span, diff --git a/src/libsyntax_ext/deriving/decodable.rs b/src/libsyntax_ext/deriving/decodable.rs index 4ea4f04623a..092f8548966 100644 --- a/src/libsyntax_ext/deriving/decodable.rs +++ b/src/libsyntax_ext/deriving/decodable.rs @@ -14,7 +14,7 @@ use deriving::generic::*; use deriving::generic::ty::*; use syntax::ast; -use syntax::ast::{MetaItem, Expr, MutMutable}; +use syntax::ast::{MetaItem, Expr, Mutability}; use syntax::codemap::Span; use syntax::ext::base::{ExtCtxt, Annotatable}; use syntax::ext::build::AstBuilder; @@ -72,7 +72,7 @@ fn expand_deriving_decodable_imp(cx: &mut ExtCtxt, }, explicit_self: None, args: vec!(Ptr(Box::new(Literal(Path::new_local("__D"))), - Borrowed(None, MutMutable))), + Borrowed(None, Mutability::Mutable))), ret_ty: Literal(Path::new_( pathvec_std!(cx, core::result::Result), None, diff --git a/src/libsyntax_ext/deriving/encodable.rs b/src/libsyntax_ext/deriving/encodable.rs index 14631659b0b..614a6381962 100644 --- a/src/libsyntax_ext/deriving/encodable.rs +++ b/src/libsyntax_ext/deriving/encodable.rs @@ -91,7 +91,7 @@ use deriving::generic::*; use deriving::generic::ty::*; -use syntax::ast::{MetaItem, Expr, ExprKind, MutMutable}; +use syntax::ast::{MetaItem, Expr, ExprKind, Mutability}; use syntax::codemap::Span; use syntax::ext::base::{ExtCtxt,Annotatable}; use syntax::ext::build::AstBuilder; @@ -148,7 +148,7 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt, }, explicit_self: borrowed_explicit_self(), args: vec!(Ptr(Box::new(Literal(Path::new_local("__S"))), - Borrowed(None, MutMutable))), + Borrowed(None, Mutability::Mutable))), ret_ty: Literal(Path::new_( pathvec_std!(cx, core::result::Result), None, diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 51091b84672..b316b1e7d86 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -864,7 +864,9 @@ impl<'a> MethodDef<'a> { let self_arg = match explicit_self.node { ast::SelfKind::Static => None, // creating fresh self id - _ => Some(ast::Arg::new_self(trait_.span, ast::MutImmutable, special_idents::self_)) + _ => Some(ast::Arg::new_self(trait_.span, + ast::Mutability::Immutable, + special_idents::self_)) }; let args = { let args = arg_types.into_iter().map(|(name, ty)| { @@ -942,7 +944,7 @@ impl<'a> MethodDef<'a> { struct_def, &format!("__self_{}", i), - ast::MutImmutable); + ast::Mutability::Immutable); patterns.push(pat); raw_fields.push(ident_expr); } @@ -1135,11 +1137,12 @@ impl<'a> MethodDef<'a> { let mut match_arms: Vec = variants.iter().enumerate() .map(|(index, variant)| { let mk_self_pat = |cx: &mut ExtCtxt, self_arg_name: &str| { - let (p, idents) = trait_.create_enum_variant_pattern(cx, type_ident, - &**variant, - self_arg_name, - ast::MutImmutable); - (cx.pat(sp, ast::PatRegion(p, ast::MutImmutable)), idents) + let (p, idents) = trait_.create_enum_variant_pattern( + cx, type_ident, + &**variant, + self_arg_name, + ast::Mutability::Immutable); + (cx.pat(sp, ast::PatRegion(p, ast::Mutability::Immutable)), idents) }; // A single arm has form (&VariantK, &VariantK, ...) => BodyK diff --git a/src/libsyntax_ext/deriving/generic/ty.rs b/src/libsyntax_ext/deriving/generic/ty.rs index e5b82fa1afc..a924cc06953 100644 --- a/src/libsyntax_ext/deriving/generic/ty.rs +++ b/src/libsyntax_ext/deriving/generic/ty.rs @@ -98,7 +98,7 @@ pub enum Ty<'a> { } pub fn borrowed_ptrty<'r>() -> PtrTy<'r> { - Borrowed(None, ast::MutImmutable) + Borrowed(None, ast::Mutability::Immutable) } pub fn borrowed<'r>(ty: Box>) -> Ty<'r> { Ptr(ty, borrowed_ptrty()) diff --git a/src/libsyntax_ext/deriving/hash.rs b/src/libsyntax_ext/deriving/hash.rs index 6bd21f7c0e0..371ba732b48 100644 --- a/src/libsyntax_ext/deriving/hash.rs +++ b/src/libsyntax_ext/deriving/hash.rs @@ -11,7 +11,7 @@ use deriving::generic::*; use deriving::generic::ty::*; -use syntax::ast::{MetaItem, Expr, MutMutable}; +use syntax::ast::{MetaItem, Expr, Mutability}; use syntax::codemap::Span; use syntax::ext::base::{ExtCtxt, Annotatable}; use syntax::ext::build::AstBuilder; @@ -43,7 +43,7 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt, vec![path_std!(cx, core::hash::Hasher)])], }, explicit_self: borrowed_explicit_self(), - args: vec!(Ptr(Box::new(Literal(arg)), Borrowed(None, MutMutable))), + args: vec!(Ptr(Box::new(Literal(arg)), Borrowed(None, Mutability::Mutable))), ret_ty: nil_ty(), attributes: vec![], is_unsafe: false, diff --git a/src/libsyntax_ext/env.rs b/src/libsyntax_ext/env.rs index f1dd6854a3a..63ec9cac073 100644 --- a/src/libsyntax_ext/env.rs +++ b/src/libsyntax_ext/env.rs @@ -42,7 +42,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenT Some(cx.lifetime(sp, cx.ident_of( "'static").name)), - ast::MutImmutable)), + ast::Mutability::Immutable)), Vec::new())) } Ok(s) => { diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index a5ad143f15b..4e24eb9f6d7 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -450,10 +450,10 @@ impl<'a, 'b> Context<'a, 'b> { let ty = ecx.ty_rptr(sp, ecx.ty(sp, ast::TyKind::Vec(piece_ty)), Some(ecx.lifetime(sp, special_idents::static_lifetime.name)), - ast::MutImmutable); + ast::Mutability::Immutable); let slice = ecx.expr_vec_slice(sp, pieces); // static instead of const to speed up codegen by not requiring this to be inlined - let st = ast::ItemKind::Static(ty, ast::MutImmutable, slice); + let st = ast::ItemKind::Static(ty, ast::Mutability::Immutable, slice); let name = ecx.ident_of(name); let item = ecx.item(sp, name, vec![], st); @@ -480,7 +480,7 @@ impl<'a, 'b> Context<'a, 'b> { self.fmtsp, self.ecx.ty_ident(self.fmtsp, self.ecx.ident_of("str")), Some(static_lifetime), - ast::MutImmutable); + ast::Mutability::Immutable); let pieces = Context::static_array(self.ecx, "__STATIC_FMTSTR", piece_ty, From dfe35da6b83f64bb7553b19649839512a3c301ce Mon Sep 17 00:00:00 2001 From: Oliver 'ker' Schneider Date: Tue, 9 Feb 2016 17:54:11 +0100 Subject: [PATCH 25/29] [breaking-change] don't glob export ast::TraitItemKind variants --- src/librustc_driver/pretty.rs | 2 +- src/librustc_front/lowering.rs | 6 +++--- src/librustc_trans/save/dump_csv.rs | 8 ++++---- src/libsyntax/ast.rs | 11 +++++------ src/libsyntax/ext/expand.rs | 6 +++--- src/libsyntax/feature_gate.rs | 6 +++--- src/libsyntax/fold.rs | 12 ++++++------ src/libsyntax/parse/parser.rs | 13 ++++++------- src/libsyntax/print/pprust.rs | 6 +++--- src/libsyntax/visit.rs | 8 ++++---- 10 files changed, 38 insertions(+), 40 deletions(-) diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index e0a948f7661..71f9d3c7e74 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -616,7 +616,7 @@ impl fold::Folder for ReplaceBodyWithLoop { fn fold_trait_item(&mut self, i: P) -> SmallVector> { match i.node { - ast::ConstTraitItem(..) => { + ast::TraitItemKind::Const(..) => { self.within_static_or_const = true; let ret = fold::noop_fold_trait_item(i, self); self.within_static_or_const = false; diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index e9dfa1bd164..412e6a68a58 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -728,15 +728,15 @@ pub fn lower_trait_item(lctx: &LoweringContext, i: &TraitItem) -> hir::TraitItem name: i.ident.name, attrs: lower_attrs(lctx, &i.attrs), node: match i.node { - ConstTraitItem(ref ty, ref default) => { + TraitItemKind::Const(ref ty, ref default) => { hir::ConstTraitItem(lower_ty(lctx, ty), default.as_ref().map(|x| lower_expr(lctx, x))) } - MethodTraitItem(ref sig, ref body) => { + TraitItemKind::Method(ref sig, ref body) => { hir::MethodTraitItem(lower_method_sig(lctx, sig), body.as_ref().map(|x| lower_block(lctx, x))) } - TypeTraitItem(ref bounds, ref default) => { + TraitItemKind::Type(ref bounds, ref default) => { hir::TypeTraitItem(lower_bounds(lctx, bounds), default.as_ref().map(|x| lower_ty(lctx, x))) } diff --git a/src/librustc_trans/save/dump_csv.rs b/src/librustc_trans/save/dump_csv.rs index 68c04427c65..1d12abbb9cb 100644 --- a/src/librustc_trans/save/dump_csv.rs +++ b/src/librustc_trans/save/dump_csv.rs @@ -1020,22 +1020,22 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> { fn visit_trait_item(&mut self, trait_item: &ast::TraitItem) { self.process_macro_use(trait_item.span, trait_item.id); match trait_item.node { - ast::ConstTraitItem(ref ty, Some(ref expr)) => { + ast::TraitItemKind::Const(ref ty, Some(ref expr)) => { self.process_const(trait_item.id, trait_item.ident.name, trait_item.span, &*ty, &*expr); } - ast::MethodTraitItem(ref sig, ref body) => { + ast::TraitItemKind::Method(ref sig, ref body) => { self.process_method(sig, body.as_ref().map(|x| &**x), trait_item.id, trait_item.ident.name, trait_item.span); } - ast::ConstTraitItem(_, None) | - ast::TypeTraitItem(..) => {} + ast::TraitItemKind::Const(_, None) | + ast::TraitItemKind::Type(..) => {} } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index cfaa5fc4a96..796e5923578 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -14,7 +14,6 @@ pub use self::Pat_::*; pub use self::PathListItem_::*; pub use self::StrStyle::*; pub use self::StructFieldKind::*; -pub use self::TraitItem_::*; pub use self::TyParamBound::*; pub use self::UnsafeSource::*; pub use self::ViewPath_::*; @@ -1324,15 +1323,15 @@ pub struct TraitItem { pub id: NodeId, pub ident: Ident, pub attrs: Vec, - pub node: TraitItem_, + pub node: TraitItemKind, pub span: Span, } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub enum TraitItem_ { - ConstTraitItem(P, Option>), - MethodTraitItem(MethodSig, Option>), - TypeTraitItem(TyParamBounds, Option>), +pub enum TraitItemKind { + Const(P, Option>), + Method(MethodSig, Option>), + Type(TyParamBounds, Option>), } #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index c53001e665e..c4bbe709f34 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -919,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!() }, diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index b04f6b06639..9bf1dd49db5 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -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"); } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 722a65fa526..08b0c0c539f 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -969,16 +969,16 @@ pub fn noop_fold_trait_item(i: P, 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))) } }, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 11638a3d424..d8fab03d21a 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -13,11 +13,11 @@ pub use self::PathParsingMode::*; use abi::{self, Abi}; use ast::BareFnTy; use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; -use ast::{Public, Unsafety}; -use ast::{Mod, Arg, Arm, Attribute, BindingMode}; +use ast::Unsafety; +use ast::{Mod, Arg, Arm, Attribute, BindingMode, TraitItemKind}; use ast::Block; use ast::{BlockCheckMode, CaptureBy}; -use ast::{Constness, ConstTraitItem, Crate, CrateConfig}; +use ast::{Constness, Crate, CrateConfig}; use ast::{Decl, DeclKind}; use ast::{EMPTY_CTXT, EnumDef, ExplicitSelf}; use ast::{Expr, ExprKind}; @@ -39,7 +39,6 @@ use ast::StrStyle; use ast::SelfKind; use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef}; use ast::{Ty, TyKind, TypeBinding, TyParam, TyParamBounds}; -use ast::TypeTraitItem; use ast::UnnamedField; use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple}; use ast::{Visibility, WhereClause}; @@ -1188,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()); @@ -1203,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()); @@ -1247,7 +1246,7 @@ impl<'a> Parser<'a> { token_str)[..])) } }; - (ident, ast::MethodTraitItem(sig, body)) + (ident, ast::TraitItemKind::Method(sig, body)) }; Ok(P(TraitItem { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index b14117c9704..6e8f0781b4e 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1552,12 +1552,12 @@ 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::MethodTraitItem(ref sig, ref body) => { + ast::TraitItemKind::Method(ref sig, ref body) => { if body.is_some() { try!(self.head("")); } @@ -1569,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))); } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 4082bcbe38e..66ac370c149 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -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); } From d844bfb1967b780ff6cc6e81644bf4b529dc0738 Mon Sep 17 00:00:00 2001 From: Oliver 'ker' Schneider Date: Tue, 9 Feb 2016 17:57:49 +0100 Subject: [PATCH 26/29] [breaking-change] don't glob export ast::Visibility variants --- src/librustc_front/lowering.rs | 4 ++-- src/libsyntax/ast.rs | 5 ++-- src/libsyntax/diagnostics/plugin.rs | 2 +- src/libsyntax/ext/build.rs | 4 ++-- src/libsyntax/ext/quote.rs | 2 +- src/libsyntax/fold.rs | 2 +- src/libsyntax/parse/mod.rs | 2 +- src/libsyntax/parse/parser.rs | 28 +++++++++++------------ src/libsyntax/print/pprust.rs | 16 ++++++------- src/libsyntax/std_inject.rs | 4 ++-- src/libsyntax/test.rs | 18 +++++++-------- src/libsyntax_ext/deriving/generic/mod.rs | 4 ++-- 12 files changed, 45 insertions(+), 46 deletions(-) diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index 412e6a68a58..fda538df5b3 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -1565,8 +1565,8 @@ pub fn lower_capture_clause(_lctx: &LoweringContext, c: CaptureBy) -> hir::Captu pub fn lower_visibility(_lctx: &LoweringContext, v: Visibility) -> hir::Visibility { match v { - Public => hir::Public, - Inherited => hir::Inherited, + Visibility::Public => hir::Public, + Visibility::Inherited => hir::Inherited, } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 796e5923578..79b465a02b8 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -17,7 +17,6 @@ pub use self::StructFieldKind::*; pub use self::TyParamBound::*; pub use self::UnsafeSource::*; pub use self::ViewPath_::*; -pub use self::Visibility::*; pub use self::PathParameters::*; use attr::ThinAttributes; @@ -1851,8 +1850,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 } } } diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 2e343948c42..43b4a201afc 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -230,7 +230,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, ty, expr, ), - vis: ast::Public, + vis: ast::Visibility::Public, span: span, }) ])) diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index e32dcc99a0e..0f1f92f3fb8 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -962,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 }) } @@ -1005,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, }} diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 8c86205fed4..d8099ff004b 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -906,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/fold.rs b/src/libsyntax/fold.rs index 08b0c0c539f..7cbb3439551 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -1023,7 +1023,7 @@ pub fn noop_fold_crate(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::ItemKind::Mod(module), })).into_iter(); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 850b4365256..f7060296f1a 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -983,7 +983,7 @@ mod tests { rules: ast::BlockCheckMode::Default, // no idea span: sp(15,21), })), - vis: ast::Inherited, + vis: ast::Visibility::Inherited, span: sp(0,21)}))); } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d8fab03d21a..a13c79bdda1 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -23,7 +23,7 @@ use ast::{EMPTY_CTXT, EnumDef, ExplicitSelf}; use ast::{Expr, ExprKind}; use ast::{Field, FnDecl}; use ast::{ForeignItem, ForeignItemKind, FunctionRetTy}; -use ast::{Ident, Inherited, ImplItem, Item, ItemKind}; +use ast::{Ident, ImplItem, Item, ItemKind}; use ast::{Lit, LitKind, UintTy}; use ast::Local; use ast::MacStmtStyle; @@ -3631,8 +3631,8 @@ impl<'a> Parser<'a> { fn parse_name_and_ty(&mut self, pr: Visibility, attrs: Vec ) -> 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")); @@ -3749,7 +3749,7 @@ impl<'a> Parser<'a> { lo, hi, id /*id is good here*/, ItemKind::Mac(spanned(lo, hi, Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT })), - Inherited, attrs)))), + Visibility::Inherited, attrs)))), ast::DUMMY_NODE_ID)) } } else { @@ -4686,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, @@ -4704,7 +4704,7 @@ impl<'a> Parser<'a> { .emit(); } } - Inherited => (), + Visibility::Inherited => (), } } @@ -4974,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, @@ -5020,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 @@ -5304,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`."); @@ -5819,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`")); } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 6e8f0781b4e..78a4bbd962f 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -388,7 +388,7 @@ pub fn fun_to_string(decl: &ast::FnDecl, to_string(|s| { try!(s.head("")); try!(s.print_fn(decl, unsafety, constness, Abi::Rust, Some(name), - generics, opt_explicit_self, ast::Inherited)); + generics, opt_explicit_self, ast::Visibility::Inherited)); try!(s.end()); // Close the head box s.end() // Close the outer box }) @@ -434,8 +434,8 @@ 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() } } @@ -1388,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(()) } } @@ -1555,13 +1555,13 @@ impl<'a> State<'a> { 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::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)); @@ -3030,7 +3030,7 @@ impl<'a> State<'a> { name, &generics, opt_explicit_self, - ast::Inherited)); + ast::Visibility::Inherited)); self.end() } diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index 996a2ee006e..9049b21d8b4 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -90,7 +90,7 @@ impl fold::Folder for CrateInjector { attr::mk_attr_outer(attr::mk_attr_id(), attr::mk_word_item( InternedString::new("macro_use")))), node: ast::ItemKind::ExternCrate(Some(self.crate_name)), - vis: ast::Inherited, + vis: ast::Visibility::Inherited, span: DUMMY_SP })); @@ -162,7 +162,7 @@ impl fold::Folder for PreludeInjector { 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 92ecadd7ae8..6b4f9464190 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -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 }) } @@ -245,11 +245,11 @@ fn mk_reexport_mod(cx: &mut TestCtxt, tests: Vec, 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 { @@ -263,7 +263,7 @@ fn mk_reexport_mod(cx: &mut TestCtxt, tests: Vec, attrs: Vec::new(), id: ast::DUMMY_NODE_ID, node: ast::ItemKind::Mod(reexport_mod), - vis: ast::Public, + vis: ast::Visibility::Public, span: DUMMY_SP, }); @@ -456,9 +456,9 @@ fn mk_std(cx: &TestCtxt) -> P { (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::ItemKind::ExternCrate(None), ast::Inherited, id_test) + (ast::ItemKind::ExternCrate(None), ast::Visibility::Inherited, id_test) }; P(ast::Item { id: ast::DUMMY_NODE_ID, @@ -505,7 +505,7 @@ fn mk_main(cx: &mut TestCtxt) -> P { attrs: vec![main_attr], id: ast::DUMMY_NODE_ID, node: main, - vis: ast::Public, + vis: ast::Visibility::Public, span: sp }); @@ -535,7 +535,7 @@ fn mk_test_module(cx: &mut TestCtxt) -> (P, Option>) { 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| { @@ -551,7 +551,7 @@ fn mk_test_module(cx: &mut TestCtxt) -> (P, Option>) { ident: token::special_idents::invalid, attrs: vec![], node: ast::ItemKind::Use(P(use_path)), - vis: ast::Inherited, + vis: ast::Visibility::Inherited, span: DUMMY_SP }) }); diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index b316b1e7d86..1e4babfac1e 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -475,7 +475,7 @@ impl<'a> TraitDef<'a> { id: ast::DUMMY_NODE_ID, span: self.span, ident: ident, - vis: ast::Inherited, + vis: ast::Visibility::Inherited, attrs: Vec::new(), node: ast::ImplItemKind::Type(type_def.to_ty(cx, self.span, @@ -892,7 +892,7 @@ impl<'a> MethodDef<'a> { id: ast::DUMMY_NODE_ID, attrs: self.attributes.clone(), span: trait_.span, - vis: ast::Inherited, + vis: ast::Visibility::Inherited, ident: method_ident, node: ast::ImplItemKind::Method(ast::MethodSig { generics: fn_generics, From 8b3856b1bc1c23969e5d8983f25cf85698a5c2b1 Mon Sep 17 00:00:00 2001 From: Oliver 'ker' Schneider Date: Tue, 9 Feb 2016 18:01:08 +0100 Subject: [PATCH 27/29] [breaking-change] don't glob export ast::StrStyle variants --- src/librustc_front/print/pprust.rs | 12 ++++++------ src/libsyntax/ast.rs | 5 ++--- src/libsyntax/attr.rs | 4 ++-- src/libsyntax/ext/build.rs | 2 +- src/libsyntax/ext/quote.rs | 2 +- src/libsyntax/parse/parser.rs | 10 ++++++---- src/libsyntax/print/pprust.rs | 16 ++++++++-------- src/libsyntax_ext/deriving/debug.rs | 5 ++--- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/librustc_front/print/pprust.rs b/src/librustc_front/print/pprust.rs index 091352bb8f8..cc43e3ae56e 100644 --- a/src/librustc_front/print/pprust.rs +++ b/src/librustc_front/print/pprust.rs @@ -652,7 +652,7 @@ impl<'a> State<'a> { 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)); } @@ -1510,9 +1510,9 @@ impl<'a> State<'a> { try!(self.commasep(Inconsistent, &a.outputs, |s, out| { match out.constraint.slice_shift_char() { Some(('=', operand)) if out.is_rw => { - try!(s.print_string(&format!("+{}", operand), ast::CookedStr)) + try!(s.print_string(&format!("+{}", operand), 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)); @@ -1523,7 +1523,7 @@ impl<'a> State<'a> { try!(self.word_space(":")); 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()); @@ -1533,7 +1533,7 @@ impl<'a> State<'a> { try!(self.word_space(":")); try!(self.commasep(Inconsistent, &a.clobbers, |s, co| { - try!(s.print_string(&co, ast::CookedStr)); + try!(s.print_string(&co, ast::StrStyle::Cooked)); Ok(()) })); @@ -1552,7 +1552,7 @@ impl<'a> State<'a> { try!(space(&mut self.s)); 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(()) })); } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 79b465a02b8..713f5c9a7be 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -12,7 +12,6 @@ pub use self::Pat_::*; pub use self::PathListItem_::*; -pub use self::StrStyle::*; pub use self::StructFieldKind::*; pub use self::TyParamBound::*; pub use self::UnsafeSource::*; @@ -1246,11 +1245,11 @@ 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 diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 53ab4e1b6d5..cc5f30e2184 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -173,7 +173,7 @@ impl AttributeMethods for Attribute { pub fn mk_name_value_item_str(name: InternedString, value: InternedString) -> P { - let value_lit = dummy_spanned(ast::LitKind::Str(value, ast::CookedStr)); + let value_lit = dummy_spanned(ast::LitKind::Str(value, ast::StrStyle::Cooked)); mk_name_value_item(name, value_lit) } @@ -225,7 +225,7 @@ 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::LitKind::Str(text, ast::CookedStr)); + let lit = spanned(lo, hi, ast::LitKind::Str(text, ast::StrStyle::Cooked)); let attr = Attribute_ { id: id, style: style, diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 0f1f92f3fb8..161443c6eb0 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -715,7 +715,7 @@ 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 { - self.expr_lit(sp, ast::LitKind::Str(s, ast::CookedStr)) + self.expr_lit(sp, ast::LitKind::Str(s, ast::StrStyle::Cooked)) } fn expr_cast(&self, sp: Span, expr: P, ty: P) -> P { diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index d8099ff004b..57db1347021 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -219,7 +219,7 @@ pub mod rt { impl ToTokens for str { fn to_tokens(&self, cx: &ExtCtxt) -> Vec { let lit = ast::LitKind::Str( - token::intern_and_get_ident(self), ast::CookedStr); + token::intern_and_get_ident(self), ast::StrStyle::Cooked); dummy_spanned(lit).to_tokens(cx) } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index a13c79bdda1..afab3a0711b 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1544,13 +1544,13 @@ impl<'a> Parser<'a> { token::Str_(s) => { (true, LitKind::Str(token::intern_and_get_ident(&parse::str_lit(&s.as_str())), - ast::CookedStr)) + ast::StrStyle::Cooked)) } token::StrRaw(s, n) => { (true, 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, LitKind::ByteStr(parse::byte_str_lit(&i.as_str()))), @@ -5966,10 +5966,12 @@ impl<'a> Parser<'a> { Option)> { 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/print/pprust.rs b/src/libsyntax/print/pprust.rs index 78a4bbd962f..bb3bc2d78e3 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -682,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)) @@ -1123,7 +1123,7 @@ impl<'a> State<'a> { 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)); } @@ -2215,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)); @@ -2229,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()); @@ -2240,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(()) })); @@ -2260,7 +2260,7 @@ 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(()) })); } diff --git a/src/libsyntax_ext/deriving/debug.rs b/src/libsyntax_ext/deriving/debug.rs index 6e769cd3810..858066cb626 100644 --- a/src/libsyntax_ext/deriving/debug.rs +++ b/src/libsyntax_ext/deriving/debug.rs @@ -71,8 +71,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, // We want to make sure we have the expn_id set so that we can use unstable methods let span = Span { expn_id: cx.backtrace(), .. span }; - let name = cx.expr_lit(span, ast::LitKind::Str(ident.name.as_str(), - ast::StrStyle::CookedStr)); + let name = cx.expr_lit(span, ast::LitKind::Str(ident.name.as_str(), ast::StrStyle::Cooked)); let builder = token::str_to_ident("builder"); let builder_expr = cx.expr_ident(span, builder.clone()); @@ -114,7 +113,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, for field in fields { let name = cx.expr_lit(field.span, ast::LitKind::Str( field.name.unwrap().name.as_str(), - ast::StrStyle::CookedStr)); + ast::StrStyle::Cooked)); // Use double indirection to make sure this works for unsized types let field = cx.expr_addr_of(field.span, field.self_.clone()); From 2b816b0d6a9bc8210ca314a020a247f8632b4f38 Mon Sep 17 00:00:00 2001 From: Oliver 'ker' Schneider Date: Tue, 9 Feb 2016 18:09:18 +0100 Subject: [PATCH 28/29] [breaking-change] don't glob export ast::PathListItem_ variants --- src/librustc_front/lowering.rs | 36 ++++++++++++++--------------- src/librustc_trans/save/dump_csv.rs | 4 ++-- src/libsyntax/ast.rs | 19 ++++++++------- src/libsyntax/ext/build.rs | 7 +++++- src/libsyntax/fold.rs | 8 +++---- src/libsyntax/parse/parser.rs | 4 ++-- src/libsyntax/print/pprust.rs | 4 ++-- 7 files changed, 43 insertions(+), 39 deletions(-) diff --git a/src/librustc_front/lowering.rs b/src/librustc_front/lowering.rs index fda538df5b3..977f271c301 100644 --- a/src/librustc_front/lowering.rs +++ b/src/librustc_front/lowering.rs @@ -211,24 +211,7 @@ pub fn lower_view_path(lctx: &LoweringContext, view_path: &ViewPath) -> P { hir::ViewPathList(lower_path(lctx, path), path_list_idents.iter() - .map(|path_list_ident| { - Spanned { - node: match path_list_ident.node { - PathListIdent { id, name, rename } => - hir::PathListIdent { - id: id, - name: name.name, - rename: rename.map(|x| x.name), - }, - PathListMod { id, rename } => - hir::PathListMod { - id: id, - rename: rename.map(|x| x.name), - }, - }, - span: path_list_ident.span, - } - }) + .map(lower_path_list_item) .collect()) } }, @@ -236,6 +219,23 @@ pub fn lower_view_path(lctx: &LoweringContext, view_path: &ViewPath) -> P hir::PathListItem { + Spanned { + node: match path_list_ident.node { + PathListItemKind::Ident { id, name, rename } => hir::PathListIdent { + id: id, + name: name.name, + rename: rename.map(|x| x.name), + }, + PathListItemKind::Mod { id, rename } => hir::PathListMod { + id: id, + rename: rename.map(|x| x.name), + }, + }, + span: path_list_ident.span, + } +} + pub fn lower_arm(lctx: &LoweringContext, arm: &Arm) -> hir::Arm { hir::Arm { attrs: lower_attrs(lctx, &arm.attrs), diff --git a/src/librustc_trans/save/dump_csv.rs b/src/librustc_trans/save/dump_csv.rs index 1d12abbb9cb..34d806ab0a8 100644 --- a/src/librustc_trans/save/dump_csv.rs +++ b/src/librustc_trans/save/dump_csv.rs @@ -928,7 +928,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> { ast::ViewPathList(ref path, ref list) => { for plid in list { match plid.node { - ast::PathListIdent { id, .. } => { + ast::PathListItemKind::Ident { id, .. } => { match self.lookup_type_ref(id) { Some(def_id) => match self.lookup_def_kind(id, plid.span) { Some(kind) => { @@ -943,7 +943,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> { None => (), } } - ast::PathListMod { .. } => (), + ast::PathListItemKind::Mod { .. } => (), } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 713f5c9a7be..bae6d780b5e 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -11,7 +11,6 @@ // The Rust abstract syntax tree. pub use self::Pat_::*; -pub use self::PathListItem_::*; pub use self::StructFieldKind::*; pub use self::TyParamBound::*; pub use self::UnsafeSource::*; @@ -1737,42 +1736,42 @@ pub struct Variant_ { pub type Variant = Spanned; #[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, id: NodeId }, - PathListMod { + Mod { /// renamed in list, eg `use foo::{self as baz};` rename: Option, 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 { match *self { - PathListIdent { name, .. } => Some(name), - PathListMod { .. } => None, + PathListItemKind::Ident { name, .. } => Some(name), + PathListItemKind::Mod { .. } => None, } } pub fn rename(&self) -> Option { match *self { - PathListIdent { rename, .. } | PathListMod { rename, .. } => rename + PathListItemKind::Ident { rename, .. } | PathListItemKind::Mod { rename, .. } => rename } } } -pub type PathListItem = Spanned; +pub type PathListItem = Spanned; pub type ViewPath = Spanned; diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 161443c6eb0..31d5521799e 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -1150,7 +1150,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn item_use_list(&self, sp: Span, vis: ast::Visibility, path: Vec, imports: &[ast::Ident]) -> P { 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/fold.rs b/src/libsyntax/fold.rs index 7cbb3439551..5ae24e6fb24 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -316,14 +316,14 @@ pub fn noop_fold_view_path(view_path: P, 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 } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index afab3a0711b..e985bfd37b0 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -574,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)) diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index bb3bc2d78e3..ab218971a51 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2918,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)); @@ -2927,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)); From bafea3bf78e75c99958ef15fd3d06652cb63133c Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 11 Feb 2016 12:35:47 +0100 Subject: [PATCH 29/29] fixup: meta item kind --- src/librustc_driver/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index fdee13cb715..25cef24c50d 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -360,7 +360,7 @@ fn check_cfg(sopts: &config::Options, let mut saw_invalid_predicate = false; for item in sopts.cfg.iter() { match item.node { - ast::MetaList(ref pred, _) => { + ast::MetaItemKind::List(ref pred, _) => { saw_invalid_predicate = true; emitter.emit(None, &format!("invalid predicate in --cfg command line argument: `{}`",