From 79fa657abc6b8885ceb4023099b4e0026c5ef28f Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Mon, 8 Feb 2016 15:34:47 +0100 Subject: [PATCH] [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,