Skip to content

Commit

Permalink
[breaking-change] don't pub export ast::Stmt_ variants
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Feb 11, 2016
1 parent 498a2e4 commit 8290c95
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 92 deletions.
8 changes: 4 additions & 4 deletions src/librustc_front/lowering.rs
Expand Up @@ -1534,25 +1534,25 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {

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"),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/unused.rs
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_passes/const_fn.rs
Expand Up @@ -57,17 +57,17 @@ 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,

// Item statements are allowed
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);
Expand Down
33 changes: 16 additions & 17 deletions src/libsyntax/ast.rs
Expand Up @@ -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_::*;
Expand Down Expand Up @@ -735,7 +734,7 @@ impl UnOp {
}

/// A statement
pub type Stmt = Spanned<Stmt_>;
pub type Stmt = Spanned<StmtKind>;

impl fmt::Debug for Stmt {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand All @@ -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<Decl>, NodeId),
Decl(P<Decl>, NodeId),

/// Expr without trailing semi-colon (must have unit type):
StmtExpr(P<Expr>, NodeId),
Expr(P<Expr>, NodeId),

/// Expr with trailing semi-colon (may have any type):
StmtSemi(P<Expr>, NodeId),
Semi(P<Expr>, NodeId),

StmtMac(P<Mac>, MacStmtStyle, ThinAttributes),
Mac(P<Mac>, MacStmtStyle, ThinAttributes),
}

impl Stmt_ {
impl StmtKind {
pub fn id(&self) -> Option<NodeId> {
match *self {
StmtDecl(_, id) => Some(id),
StmtExpr(_, id) => Some(id),
StmtSemi(_, id) => Some(id),
StmtMac(..) => None,
StmtKind::Decl(_, id) => Some(id),
StmtKind::Expr(_, id) => Some(id),
StmtKind::Semi(_, id) => Some(id),
StmtKind::Mac(..) => None,
}
}

pub fn attrs(&self) -> &[Attribute] {
match *self {
StmtDecl(ref d, _) => d.attrs(),
StmtExpr(ref e, _) |
StmtSemi(ref e, _) => e.attrs(),
StmtMac(_, _, Some(ref b)) => b,
StmtMac(_, _, None) => &[],
StmtKind::Decl(ref d, _) => d.attrs(),
StmtKind::Expr(ref e, _) |
StmtKind::Semi(ref e, _) => e.attrs(),
StmtKind::Mac(_, _, Some(ref b)) => b,
StmtKind::Mac(_, _, None) => &[],
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/libsyntax/attr.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -947,12 +947,12 @@ impl WithAttrs for P<Stmt> {
Spanned {
span: span,
node: match node {
StmtDecl(decl, id) => StmtDecl(decl.with_attrs(attrs), id),
StmtExpr(expr, id) => StmtExpr(expr.with_attrs(attrs), id),
StmtSemi(expr, id) => StmtSemi(expr.with_attrs(attrs), id),
StmtMac(mac, style, mut ats) => {
StmtKind::Decl(decl, id) => StmtKind::Decl(decl.with_attrs(attrs), id),
StmtKind::Expr(expr, id) => StmtKind::Expr(expr.with_attrs(attrs), id),
StmtKind::Semi(expr, id) => StmtKind::Semi(expr.with_attrs(attrs), id),
StmtKind::Mac(mac, style, mut ats) => {
ats.update(|a| a.append(attrs));
StmtMac(mac, style, ats)
StmtKind::Mac(mac, style, ats)
}
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/config.rs
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/ext/base.rs
Expand Up @@ -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))))
})
}
}
Expand Down Expand Up @@ -402,8 +402,8 @@ impl MacResult for DummyResult {
fn make_stmts(self: Box<DummyResult>) -> Option<SmallVector<P<ast::Stmt>>> {
Some(SmallVector::one(P(
codemap::respan(self.span,
ast::StmtExpr(DummyResult::raw_expr(self.span),
ast::DUMMY_NODE_ID)))))
ast::StmtKind::Expr(DummyResult::raw_expr(self.span),
ast::DUMMY_NODE_ID)))))
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/libsyntax/ext/build.rs
Expand Up @@ -506,7 +506,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
}

fn stmt_expr(&self, expr: P<ast::Expr>) -> P<ast::Stmt> {
P(respan(expr.span, ast::StmtSemi(expr, ast::DUMMY_NODE_ID)))
P(respan(expr.span, ast::StmtKind::Semi(expr, ast::DUMMY_NODE_ID)))
}

fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident,
Expand All @@ -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,
Expand All @@ -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<P<ast::Stmt>>,
Expand All @@ -559,7 +559,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {

fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> P<ast::Stmt> {
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<ast::Expr>) -> P<ast::Block> {
Expand Down
13 changes: 6 additions & 7 deletions src/libsyntax/ext/expand.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -507,7 +506,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
fn expand_stmt(stmt: P<Stmt>, fld: &mut MacroExpander) -> SmallVector<P<Stmt>> {
let stmt = stmt.and_then(|stmt| stmt);
let (mac, style, attrs) = match stmt.node {
StmtMac(mac, style, attrs) => (mac, style, attrs),
StmtKind::Mac(mac, style, attrs) => (mac, style, attrs),
_ => return expand_non_macro_stmt(stmt, fld)
};

Expand Down Expand Up @@ -539,7 +538,7 @@ fn expand_stmt(stmt: P<Stmt>, fld: &mut MacroExpander) -> SmallVector<P<Stmt>> {
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
Expand All @@ -558,7 +557,7 @@ fn expand_non_macro_stmt(Spanned {node, span: stmt_span}: Stmt, fld: &mut MacroE
-> SmallVector<P<Stmt>> {
// is it a let?
match node {
StmtDecl(decl, node_id) => decl.and_then(|Spanned {node: decl, span}| match decl {
StmtKind::Decl(decl, node_id) => decl.and_then(|Spanned {node: decl, span}| match decl {
DeclKind::Local(local) => {
// take it apart:
let rewritten_local = local.map(|Local {id, pat, ty, init, span, attrs}| {
Expand Down Expand Up @@ -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
}),
Expand All @@ -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
}),
Expand Down
20 changes: 10 additions & 10 deletions src/libsyntax/fold.rs
Expand Up @@ -1347,39 +1347,39 @@ pub fn noop_fold_stmt<T: Folder>(Spanned {node, span}: Stmt, folder: &mut T)
-> SmallVector<P<Stmt>> {
let span = folder.new_span(span);
match node {
StmtDecl(d, id) => {
StmtKind::Decl(d, id) => {
let id = folder.new_id(id);
folder.fold_decl(d).into_iter().map(|d| P(Spanned {
node: StmtDecl(d, id),
node: StmtKind::Decl(d, id),
span: span
})).collect()
}
StmtExpr(e, id) => {
StmtKind::Expr(e, id) => {
let id = folder.new_id(id);
if let Some(e) = folder.fold_opt_expr(e) {
SmallVector::one(P(Spanned {
node: StmtExpr(e, id),
node: StmtKind::Expr(e, id),
span: span
}))
} else {
SmallVector::zero()
}
}
StmtSemi(e, id) => {
StmtKind::Semi(e, id) => {
let id = folder.new_id(id);
if let Some(e) = folder.fold_opt_expr(e) {
SmallVector::one(P(Spanned {
node: StmtSemi(e, id),
node: StmtKind::Semi(e, id),
span: span
}))
} else {
SmallVector::zero()
}
}
StmtMac(mac, semi, attrs) => SmallVector::one(P(Spanned {
node: StmtMac(mac.map(|m| folder.fold_mac(m)),
semi,
attrs.map_thin_attrs(|v| fold_attrs(v, folder))),
StmtKind::Mac(mac, semi, attrs) => SmallVector::one(P(Spanned {
node: StmtKind::Mac(mac.map(|m| folder.fold_mac(m)),
semi,
attrs.map_thin_attrs(|v| fold_attrs(v, folder))),
span: span
}))
}
Expand Down
10 changes: 5 additions & 5 deletions src/libsyntax/parse/classify.rs
Expand Up @@ -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,
}
}
4 changes: 2 additions & 2 deletions src/libsyntax/parse/mod.rs
Expand Up @@ -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),
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 8290c95

Please sign in to comment.