1
Fork 0

[breaking-change] don't pub export ast::Stmt_ variants

This commit is contained in:
Oliver Schneider 2016-02-08 17:23:13 +01:00
parent 498a2e416e
commit 8290c950a8
17 changed files with 87 additions and 92 deletions

View file

@ -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 { pub fn lower_stmt(lctx: &LoweringContext, s: &Stmt) -> hir::Stmt {
match s.node { match s.node {
StmtDecl(ref d, id) => { StmtKind::Decl(ref d, id) => {
Spanned { Spanned {
node: hir::StmtDecl(lower_decl(lctx, d), id), node: hir::StmtDecl(lower_decl(lctx, d), id),
span: s.span, span: s.span,
} }
} }
StmtExpr(ref e, id) => { StmtKind::Expr(ref e, id) => {
Spanned { Spanned {
node: hir::StmtExpr(lower_expr(lctx, e), id), node: hir::StmtExpr(lower_expr(lctx, e), id),
span: s.span, span: s.span,
} }
} }
StmtSemi(ref e, id) => { StmtKind::Semi(ref e, id) => {
Spanned { Spanned {
node: hir::StmtSemi(lower_expr(lctx, e), id), node: hir::StmtSemi(lower_expr(lctx, e), id),
span: s.span, span: s.span,
} }
} }
StmtMac(..) => panic!("Shouldn't exist here"), StmtKind::Mac(..) => panic!("Shouldn't exist here"),
} }
} }

View file

@ -365,7 +365,7 @@ impl EarlyLintPass for UnusedParens {
fn check_stmt(&mut self, cx: &EarlyContext, s: &ast::Stmt) { fn check_stmt(&mut self, cx: &EarlyContext, s: &ast::Stmt) {
let (value, msg) = match s.node { 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 { ast::DeclKind::Local(ref local) => match local.init {
Some(ref value) => (value, "assigned value"), Some(ref value) => (value, "assigned value"),
None => return None => return

View file

@ -57,7 +57,7 @@ fn check_block(sess: &Session, b: &ast::Block, kind: &'static str) {
// Check all statements in the block // Check all statements in the block
for stmt in &b.stmts { for stmt in &b.stmts {
let span = match stmt.node { let span = match stmt.node {
ast::StmtDecl(ref decl, _) => { ast::StmtKind::Decl(ref decl, _) => {
match decl.node { match decl.node {
ast::DeclKind::Local(_) => decl.span, 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::DeclKind::Item(_) => continue,
} }
} }
ast::StmtExpr(ref expr, _) => expr.span, ast::StmtKind::Expr(ref expr, _) => expr.span,
ast::StmtSemi(ref semi, _) => semi.span, ast::StmtKind::Semi(ref semi, _) => semi.span,
ast::StmtMac(..) => unreachable!(), ast::StmtKind::Mac(..) => unreachable!(),
}; };
span_err!(sess, span, E0016, span_err!(sess, span, E0016,
"blocks in {}s are limited to items and tail expressions", kind); "blocks in {}s are limited to items and tail expressions", kind);

View file

@ -18,7 +18,6 @@ pub use self::MetaItem_::*;
pub use self::Mutability::*; pub use self::Mutability::*;
pub use self::Pat_::*; pub use self::Pat_::*;
pub use self::PathListItem_::*; pub use self::PathListItem_::*;
pub use self::Stmt_::*;
pub use self::StrStyle::*; pub use self::StrStyle::*;
pub use self::StructFieldKind::*; pub use self::StructFieldKind::*;
pub use self::TraitItem_::*; pub use self::TraitItem_::*;
@ -735,7 +734,7 @@ impl UnOp {
} }
/// A statement /// A statement
pub type Stmt = Spanned<Stmt_>; pub type Stmt = Spanned<StmtKind>;
impl fmt::Debug for Stmt { impl fmt::Debug for Stmt {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 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)] #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
pub enum Stmt_ { pub enum StmtKind {
/// Could be an item or a local (let) binding: /// 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): /// 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): /// 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> { pub fn id(&self) -> Option<NodeId> {
match *self { match *self {
StmtDecl(_, id) => Some(id), StmtKind::Decl(_, id) => Some(id),
StmtExpr(_, id) => Some(id), StmtKind::Expr(_, id) => Some(id),
StmtSemi(_, id) => Some(id), StmtKind::Semi(_, id) => Some(id),
StmtMac(..) => None, StmtKind::Mac(..) => None,
} }
} }
pub fn attrs(&self) -> &[Attribute] { pub fn attrs(&self) -> &[Attribute] {
match *self { match *self {
StmtDecl(ref d, _) => d.attrs(), StmtKind::Decl(ref d, _) => d.attrs(),
StmtExpr(ref e, _) | StmtKind::Expr(ref e, _) |
StmtSemi(ref e, _) => e.attrs(), StmtKind::Semi(ref e, _) => e.attrs(),
StmtMac(_, _, Some(ref b)) => b, StmtKind::Mac(_, _, Some(ref b)) => b,
StmtMac(_, _, None) => &[], StmtKind::Mac(_, _, None) => &[],
} }
} }
} }

View file

@ -16,7 +16,7 @@ pub use self::IntType::*;
use ast; use ast;
use ast::{AttrId, Attribute, Attribute_, MetaItem, MetaWord, MetaNameValue, MetaList}; 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 ast::{Expr, Item, Local, Decl};
use codemap::{Span, Spanned, spanned, dummy_spanned}; use codemap::{Span, Spanned, spanned, dummy_spanned};
use codemap::BytePos; use codemap::BytePos;
@ -947,12 +947,12 @@ impl WithAttrs for P<Stmt> {
Spanned { Spanned {
span: span, span: span,
node: match node { node: match node {
StmtDecl(decl, id) => StmtDecl(decl.with_attrs(attrs), id), StmtKind::Decl(decl, id) => StmtKind::Decl(decl.with_attrs(attrs), id),
StmtExpr(expr, id) => StmtExpr(expr.with_attrs(attrs), id), StmtKind::Expr(expr, id) => StmtKind::Expr(expr.with_attrs(attrs), id),
StmtSemi(expr, id) => StmtSemi(expr.with_attrs(attrs), id), StmtKind::Semi(expr, id) => StmtKind::Semi(expr.with_attrs(attrs), id),
StmtMac(mac, style, mut ats) => { StmtKind::Mac(mac, style, mut ats) => {
ats.update(|a| a.append(attrs)); ats.update(|a| a.append(attrs));
StmtMac(mac, style, ats) StmtKind::Mac(mac, style, ats)
} }
}, },
} }

View file

@ -372,7 +372,7 @@ impl<'v, 'a, 'b> visit::Visitor<'v> for StmtExprAttrFeatureVisitor<'a, 'b> {
let stmt_attrs = s.node.attrs(); let stmt_attrs = s.node.attrs();
if stmt_attrs.len() > 0 { if stmt_attrs.len() > 0 {
// attributes on items are fine // 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 { if let ast::DeclKind::Item(_) = decl.node {
visit::walk_stmt(self, s); visit::walk_stmt(self, s);
return; return;

View file

@ -205,7 +205,7 @@ macro_rules! make_stmts_default {
($me:expr) => { ($me:expr) => {
$me.make_expr().map(|e| { $me.make_expr().map(|e| {
SmallVector::one(P(codemap::respan( 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,7 +402,7 @@ impl MacResult for DummyResult {
fn make_stmts(self: Box<DummyResult>) -> Option<SmallVector<P<ast::Stmt>>> { fn make_stmts(self: Box<DummyResult>) -> Option<SmallVector<P<ast::Stmt>>> {
Some(SmallVector::one(P( Some(SmallVector::one(P(
codemap::respan(self.span, codemap::respan(self.span,
ast::StmtExpr(DummyResult::raw_expr(self.span), ast::StmtKind::Expr(DummyResult::raw_expr(self.span),
ast::DUMMY_NODE_ID))))) ast::DUMMY_NODE_ID)))))
} }
} }

View file

@ -506,7 +506,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
} }
fn stmt_expr(&self, expr: P<ast::Expr>) -> P<ast::Stmt> { 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, fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident,
@ -525,7 +525,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
attrs: None, attrs: None,
}); });
let decl = respan(sp, ast::DeclKind::Local(local)); 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, fn stmt_let_typed(&self,
@ -549,7 +549,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
attrs: None, attrs: None,
}); });
let decl = respan(sp, ast::DeclKind::Local(local)); 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>>, fn block(&self, span: Span, stmts: Vec<P<ast::Stmt>>,
@ -559,7 +559,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> P<ast::Stmt> { fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> P<ast::Stmt> {
let decl = respan(sp, ast::DeclKind::Item(item)); 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> { fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block> {

View file

@ -10,8 +10,7 @@
use ast::{Block, Crate, DeclKind, PatMac}; use ast::{Block, Crate, DeclKind, PatMac};
use ast::{Local, Ident, Mac_, Name}; use ast::{Local, Ident, Mac_, Name};
use ast::{ItemMac, MacStmtWithSemicolon, Mrk, Stmt, StmtDecl, StmtMac}; use ast::{ItemMac, MacStmtWithSemicolon, Mrk, Stmt, StmtKind};
use ast::{StmtExpr, StmtSemi};
use ast::TokenTree; use ast::TokenTree;
use ast; use ast;
use ext::mtwt; use ext::mtwt;
@ -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>> { fn expand_stmt(stmt: P<Stmt>, fld: &mut MacroExpander) -> SmallVector<P<Stmt>> {
let stmt = stmt.and_then(|stmt| stmt); let stmt = stmt.and_then(|stmt| stmt);
let (mac, style, attrs) = match stmt.node { 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) _ => return expand_non_macro_stmt(stmt, fld)
}; };
@ -539,7 +538,7 @@ fn expand_stmt(stmt: P<Stmt>, fld: &mut MacroExpander) -> SmallVector<P<Stmt>> {
let new_stmt = stmt.map(|Spanned {node, span}| { let new_stmt = stmt.map(|Spanned {node, span}| {
Spanned { Spanned {
node: match node { 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 */ _ => node /* might already have a semi */
}, },
span: span span: span
@ -558,7 +557,7 @@ fn expand_non_macro_stmt(Spanned {node, span: stmt_span}: Stmt, fld: &mut MacroE
-> SmallVector<P<Stmt>> { -> SmallVector<P<Stmt>> {
// is it a let? // is it a let?
match node { 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) => { DeclKind::Local(local) => {
// take it apart: // take it apart:
let rewritten_local = local.map(|Local {id, pat, ty, init, span, attrs}| { 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 { SmallVector::one(P(Spanned {
node: StmtDecl(P(Spanned { node: StmtKind::Decl(P(Spanned {
node: DeclKind::Local(rewritten_local), node: DeclKind::Local(rewritten_local),
span: span span: span
}), }),
@ -606,7 +605,7 @@ fn expand_non_macro_stmt(Spanned {node, span: stmt_span}: Stmt, fld: &mut MacroE
} }
_ => { _ => {
noop_fold_stmt(Spanned { noop_fold_stmt(Spanned {
node: StmtDecl(P(Spanned { node: StmtKind::Decl(P(Spanned {
node: decl, node: decl,
span: span span: span
}), }),

View file

@ -1347,37 +1347,37 @@ pub fn noop_fold_stmt<T: Folder>(Spanned {node, span}: Stmt, folder: &mut T)
-> SmallVector<P<Stmt>> { -> SmallVector<P<Stmt>> {
let span = folder.new_span(span); let span = folder.new_span(span);
match node { match node {
StmtDecl(d, id) => { StmtKind::Decl(d, id) => {
let id = folder.new_id(id); let id = folder.new_id(id);
folder.fold_decl(d).into_iter().map(|d| P(Spanned { folder.fold_decl(d).into_iter().map(|d| P(Spanned {
node: StmtDecl(d, id), node: StmtKind::Decl(d, id),
span: span span: span
})).collect() })).collect()
} }
StmtExpr(e, id) => { StmtKind::Expr(e, id) => {
let id = folder.new_id(id); let id = folder.new_id(id);
if let Some(e) = folder.fold_opt_expr(e) { if let Some(e) = folder.fold_opt_expr(e) {
SmallVector::one(P(Spanned { SmallVector::one(P(Spanned {
node: StmtExpr(e, id), node: StmtKind::Expr(e, id),
span: span span: span
})) }))
} else { } else {
SmallVector::zero() SmallVector::zero()
} }
} }
StmtSemi(e, id) => { StmtKind::Semi(e, id) => {
let id = folder.new_id(id); let id = folder.new_id(id);
if let Some(e) = folder.fold_opt_expr(e) { if let Some(e) = folder.fold_opt_expr(e) {
SmallVector::one(P(Spanned { SmallVector::one(P(Spanned {
node: StmtSemi(e, id), node: StmtKind::Semi(e, id),
span: span span: span
})) }))
} else { } else {
SmallVector::zero() SmallVector::zero()
} }
} }
StmtMac(mac, semi, attrs) => SmallVector::one(P(Spanned { StmtKind::Mac(mac, semi, attrs) => SmallVector::one(P(Spanned {
node: StmtMac(mac.map(|m| folder.fold_mac(m)), node: StmtKind::Mac(mac.map(|m| folder.fold_mac(m)),
semi, semi,
attrs.map_thin_attrs(|v| fold_attrs(v, folder))), attrs.map_thin_attrs(|v| fold_attrs(v, folder))),
span: span span: span

View file

@ -45,16 +45,16 @@ pub fn expr_is_simple_block(e: &ast::Expr) -> bool {
/// this statement requires a semicolon after it. /// this statement requires a semicolon after it.
/// note that in one case (stmt_semi), we've already /// note that in one case (stmt_semi), we've already
/// seen the semicolon, and thus don't need another. /// 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 { match *stmt {
ast::StmtDecl(ref d, _) => { ast::StmtKind::Decl(ref d, _) => {
match d.node { match d.node {
ast::DeclKind::Local(_) => true, ast::DeclKind::Local(_) => true,
ast::DeclKind::Item(_) => false, ast::DeclKind::Item(_) => false,
} }
} }
ast::StmtExpr(ref e, _) => expr_requires_semi_to_be_stmt(e), ast::StmtKind::Expr(ref e, _) => expr_requires_semi_to_be_stmt(e),
ast::StmtSemi(..) => false, ast::StmtKind::Semi(..) => false,
ast::StmtMac(..) => false, ast::StmtKind::Mac(..) => false,
} }
} }

View file

@ -867,7 +867,7 @@ mod tests {
#[test] fn parse_stmt_1 () { #[test] fn parse_stmt_1 () {
assert!(string_to_stmt("b;".to_string()) == assert!(string_to_stmt("b;".to_string()) ==
Some(P(Spanned{ Some(P(Spanned{
node: ast::StmtExpr(P(ast::Expr { node: ast::StmtKind::Expr(P(ast::Expr {
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
node: ast::ExprKind::Path(None, ast::Path { node: ast::ExprKind::Path(None, ast::Path {
span:sp(0,1), span:sp(0,1),
@ -958,7 +958,7 @@ mod tests {
}, },
P(ast::Block { P(ast::Block {
stmts: vec!(P(Spanned{ stmts: vec!(P(Spanned{
node: ast::StmtSemi(P(ast::Expr{ node: ast::StmtKind::Semi(P(ast::Expr{
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
node: ast::ExprKind::Path(None, node: ast::ExprKind::Path(None,
ast::Path{ ast::Path{

View file

@ -36,8 +36,8 @@ use ast::NamedField;
use ast::{Pat, PatBox, PatEnum, PatIdent, PatLit, PatQPath, PatMac, PatRange}; use ast::{Pat, PatBox, PatEnum, PatIdent, PatLit, PatQPath, PatMac, PatRange};
use ast::{PatRegion, PatStruct, PatTup, PatVec, PatWild}; use ast::{PatRegion, PatStruct, PatTup, PatVec, PatWild};
use ast::{PolyTraitRef, QSelf}; use ast::{PolyTraitRef, QSelf};
use ast::{Stmt, StmtDecl}; use ast::{Stmt, StmtKind};
use ast::{StmtExpr, StmtSemi, StmtMac, VariantData, StructField}; use ast::{VariantData, StructField};
use ast::StrStyle; use ast::StrStyle;
use ast::SelfKind; use ast::SelfKind;
use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef}; use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef};
@ -3678,7 +3678,7 @@ impl<'a> Parser<'a> {
try!(self.expect_keyword(keywords::Let)); try!(self.expect_keyword(keywords::Let));
let decl = try!(self.parse_let(attrs.into_thin_attrs())); let decl = try!(self.parse_let(attrs.into_thin_attrs()));
let hi = decl.span.hi; 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) spanned(lo, hi, stmt)
} else if self.token.is_ident() } else if self.token.is_ident()
&& !self.token.is_any_keyword() && !self.token.is_any_keyword()
@ -3730,11 +3730,8 @@ impl<'a> Parser<'a> {
}; };
if id.name == token::special_idents::invalid.name { if id.name == token::special_idents::invalid.name {
let stmt = StmtMac(P(spanned(lo, let mac = P(spanned(lo, hi, Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT }));
hi, let stmt = StmtKind::Mac(mac, style, attrs.into_thin_attrs());
Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT })),
style,
attrs.into_thin_attrs());
spanned(lo, hi, stmt) spanned(lo, hi, stmt)
} else { } else {
// if it has a special ident, it's definitely an item // if it has a special ident, it's definitely an item
@ -3749,7 +3746,7 @@ impl<'a> Parser<'a> {
followed by a semicolon"); followed by a semicolon");
} }
} }
spanned(lo, hi, StmtDecl( spanned(lo, hi, StmtKind::Decl(
P(spanned(lo, hi, DeclKind::Item( P(spanned(lo, hi, DeclKind::Item(
self.mk_item( self.mk_item(
lo, hi, id /*id is good here*/, lo, hi, id /*id is good here*/,
@ -3764,7 +3761,7 @@ impl<'a> Parser<'a> {
Some(i) => { Some(i) => {
let hi = i.span.hi; let hi = i.span.hi;
let decl = P(spanned(lo, hi, DeclKind::Item(i))); 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 => { None => {
let unused_attrs = |attrs: &[_], s: &mut Self| { let unused_attrs = |attrs: &[_], s: &mut Self| {
@ -3790,7 +3787,7 @@ impl<'a> Parser<'a> {
let e = try!(self.parse_expr_res( let e = try!(self.parse_expr_res(
Restrictions::RESTRICTION_STMT_EXPR, Some(attrs.into_thin_attrs()))); Restrictions::RESTRICTION_STMT_EXPR, Some(attrs.into_thin_attrs())));
let hi = e.span.hi; 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) spanned(lo, hi, stmt)
} }
} }
@ -3844,16 +3841,16 @@ impl<'a> Parser<'a> {
continue; continue;
}; };
match node { match node {
StmtExpr(e, _) => { StmtKind::Expr(e, _) => {
try!(self.handle_expression_like_statement(e, span, &mut stmts, &mut expr)); 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 // statement macro without braces; might be an
// expr depending on whether a semicolon follows // expr depending on whether a semicolon follows
match self.token { match self.token {
token::Semi => { token::Semi => {
stmts.push(P(Spanned { stmts.push(P(Spanned {
node: StmtMac(mac, MacStmtWithSemicolon, attrs), node: StmtKind::Mac(mac, MacStmtWithSemicolon, attrs),
span: mk_sp(span.lo, self.span.hi), span: mk_sp(span.lo, self.span.hi),
})); }));
self.bump(); 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 // statement macro; might be an expr
match self.token { match self.token {
token::Semi => { token::Semi => {
stmts.push(P(Spanned { stmts.push(P(Spanned {
node: StmtMac(m, MacStmtWithSemicolon, attrs), node: StmtKind::Mac(m, MacStmtWithSemicolon, attrs),
span: mk_sp(span.lo, self.span.hi), span: mk_sp(span.lo, self.span.hi),
})); }));
self.bump(); self.bump();
@ -3892,7 +3889,7 @@ impl<'a> Parser<'a> {
} }
_ => { _ => {
stmts.push(P(Spanned { stmts.push(P(Spanned {
node: StmtMac(m, style, attrs), node: StmtKind::Mac(m, style, attrs),
span: span span: span
})); }));
} }
@ -3944,14 +3941,14 @@ impl<'a> Parser<'a> {
expn_id: span.expn_id, expn_id: span.expn_id,
}; };
stmts.push(P(Spanned { stmts.push(P(Spanned {
node: StmtSemi(e, ast::DUMMY_NODE_ID), node: StmtKind::Semi(e, ast::DUMMY_NODE_ID),
span: span_with_semi, span: span_with_semi,
})); }));
} }
token::CloseDelim(token::Brace) => *last_block_expr = Some(e), token::CloseDelim(token::Brace) => *last_block_expr = Some(e),
_ => { _ => {
stmts.push(P(Spanned { stmts.push(P(Spanned {
node: StmtExpr(e, ast::DUMMY_NODE_ID), node: StmtKind::Expr(e, ast::DUMMY_NODE_ID),
span: span span: span
})); }));
} }

View file

@ -1613,19 +1613,19 @@ impl<'a> State<'a> {
pub fn print_stmt(&mut self, st: &ast::Stmt) -> io::Result<()> { pub fn print_stmt(&mut self, st: &ast::Stmt) -> io::Result<()> {
try!(self.maybe_print_comment(st.span.lo)); try!(self.maybe_print_comment(st.span.lo));
match st.node { match st.node {
ast::StmtDecl(ref decl, _) => { ast::StmtKind::Decl(ref decl, _) => {
try!(self.print_decl(&**decl)); try!(self.print_decl(&**decl));
} }
ast::StmtExpr(ref expr, _) => { ast::StmtKind::Expr(ref expr, _) => {
try!(self.space_if_not_bol()); try!(self.space_if_not_bol());
try!(self.print_expr_outer_attr_style(&**expr, false)); 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.space_if_not_bol());
try!(self.print_expr_outer_attr_style(&**expr, false)); try!(self.print_expr_outer_attr_style(&**expr, false));
try!(word(&mut self.s, ";")); 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.space_if_not_bol());
try!(self.print_outer_attributes(attrs.as_attr_slice())); try!(self.print_outer_attributes(attrs.as_attr_slice()));
let delim = match style { let delim = match style {

View file

@ -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) { pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) {
match statement.node { match statement.node {
StmtDecl(ref declaration, _) => visitor.visit_decl(declaration), StmtKind::Decl(ref declaration, _) => visitor.visit_decl(declaration),
StmtExpr(ref expression, _) | StmtSemi(ref expression, _) => { StmtKind::Expr(ref expression, _) | StmtKind::Semi(ref expression, _) => {
visitor.visit_expr(expression) visitor.visit_expr(expression)
} }
StmtMac(ref mac, _, ref attrs) => { StmtKind::Mac(ref mac, _, ref attrs) => {
visitor.visit_mac(mac); visitor.visit_mac(mac);
for attr in attrs.as_attr_slice() { for attr in attrs.as_attr_slice() {
visitor.visit_attribute(attr); visitor.visit_attribute(attr);

View file

@ -152,5 +152,5 @@ fn stmt_let_undescore(cx: &mut ExtCtxt,
attrs: None, attrs: None,
}); });
let decl = respan(sp, ast::DeclKind::Local(local)); 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)))
} }

View file

@ -461,7 +461,7 @@ impl<'a, 'b> Context<'a, 'b> {
// Wrap the declaration in a block so that it forms a single expression. // Wrap the declaration in a block so that it forms a single expression.
ecx.expr_block(ecx.block(sp, 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)))) Some(ecx.expr_ident(sp, name))))
} }