Skip to content

Commit 8290c95

Browse files
committed
[breaking-change] don't pub export ast::Stmt_ variants
1 parent 498a2e4 commit 8290c95

File tree

17 files changed

+87
-92
lines changed

17 files changed

+87
-92
lines changed

src/librustc_front/lowering.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,25 +1534,25 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {
15341534

15351535
pub fn lower_stmt(lctx: &LoweringContext, s: &Stmt) -> hir::Stmt {
15361536
match s.node {
1537-
StmtDecl(ref d, id) => {
1537+
StmtKind::Decl(ref d, id) => {
15381538
Spanned {
15391539
node: hir::StmtDecl(lower_decl(lctx, d), id),
15401540
span: s.span,
15411541
}
15421542
}
1543-
StmtExpr(ref e, id) => {
1543+
StmtKind::Expr(ref e, id) => {
15441544
Spanned {
15451545
node: hir::StmtExpr(lower_expr(lctx, e), id),
15461546
span: s.span,
15471547
}
15481548
}
1549-
StmtSemi(ref e, id) => {
1549+
StmtKind::Semi(ref e, id) => {
15501550
Spanned {
15511551
node: hir::StmtSemi(lower_expr(lctx, e), id),
15521552
span: s.span,
15531553
}
15541554
}
1555-
StmtMac(..) => panic!("Shouldn't exist here"),
1555+
StmtKind::Mac(..) => panic!("Shouldn't exist here"),
15561556
}
15571557
}
15581558

src/librustc_lint/unused.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ impl EarlyLintPass for UnusedParens {
365365

366366
fn check_stmt(&mut self, cx: &EarlyContext, s: &ast::Stmt) {
367367
let (value, msg) = match s.node {
368-
ast::StmtDecl(ref decl, _) => match decl.node {
368+
ast::StmtKind::Decl(ref decl, _) => match decl.node {
369369
ast::DeclKind::Local(ref local) => match local.init {
370370
Some(ref value) => (value, "assigned value"),
371371
None => return

src/librustc_passes/const_fn.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ fn check_block(sess: &Session, b: &ast::Block, kind: &'static str) {
5757
// Check all statements in the block
5858
for stmt in &b.stmts {
5959
let span = match stmt.node {
60-
ast::StmtDecl(ref decl, _) => {
60+
ast::StmtKind::Decl(ref decl, _) => {
6161
match decl.node {
6262
ast::DeclKind::Local(_) => decl.span,
6363

6464
// Item statements are allowed
6565
ast::DeclKind::Item(_) => continue,
6666
}
6767
}
68-
ast::StmtExpr(ref expr, _) => expr.span,
69-
ast::StmtSemi(ref semi, _) => semi.span,
70-
ast::StmtMac(..) => unreachable!(),
68+
ast::StmtKind::Expr(ref expr, _) => expr.span,
69+
ast::StmtKind::Semi(ref semi, _) => semi.span,
70+
ast::StmtKind::Mac(..) => unreachable!(),
7171
};
7272
span_err!(sess, span, E0016,
7373
"blocks in {}s are limited to items and tail expressions", kind);

src/libsyntax/ast.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ pub use self::MetaItem_::*;
1818
pub use self::Mutability::*;
1919
pub use self::Pat_::*;
2020
pub use self::PathListItem_::*;
21-
pub use self::Stmt_::*;
2221
pub use self::StrStyle::*;
2322
pub use self::StructFieldKind::*;
2423
pub use self::TraitItem_::*;
@@ -735,7 +734,7 @@ impl UnOp {
735734
}
736735

737736
/// A statement
738-
pub type Stmt = Spanned<Stmt_>;
737+
pub type Stmt = Spanned<StmtKind>;
739738

740739
impl fmt::Debug for Stmt {
741740
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -748,36 +747,36 @@ impl fmt::Debug for Stmt {
748747

749748

750749
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash)]
751-
pub enum Stmt_ {
750+
pub enum StmtKind {
752751
/// Could be an item or a local (let) binding:
753-
StmtDecl(P<Decl>, NodeId),
752+
Decl(P<Decl>, NodeId),
754753

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

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

761-
StmtMac(P<Mac>, MacStmtStyle, ThinAttributes),
760+
Mac(P<Mac>, MacStmtStyle, ThinAttributes),
762761
}
763762

764-
impl Stmt_ {
763+
impl StmtKind {
765764
pub fn id(&self) -> Option<NodeId> {
766765
match *self {
767-
StmtDecl(_, id) => Some(id),
768-
StmtExpr(_, id) => Some(id),
769-
StmtSemi(_, id) => Some(id),
770-
StmtMac(..) => None,
766+
StmtKind::Decl(_, id) => Some(id),
767+
StmtKind::Expr(_, id) => Some(id),
768+
StmtKind::Semi(_, id) => Some(id),
769+
StmtKind::Mac(..) => None,
771770
}
772771
}
773772

774773
pub fn attrs(&self) -> &[Attribute] {
775774
match *self {
776-
StmtDecl(ref d, _) => d.attrs(),
777-
StmtExpr(ref e, _) |
778-
StmtSemi(ref e, _) => e.attrs(),
779-
StmtMac(_, _, Some(ref b)) => b,
780-
StmtMac(_, _, None) => &[],
775+
StmtKind::Decl(ref d, _) => d.attrs(),
776+
StmtKind::Expr(ref e, _) |
777+
StmtKind::Semi(ref e, _) => e.attrs(),
778+
StmtKind::Mac(_, _, Some(ref b)) => b,
779+
StmtKind::Mac(_, _, None) => &[],
781780
}
782781
}
783782
}

src/libsyntax/attr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub use self::IntType::*;
1616

1717
use ast;
1818
use ast::{AttrId, Attribute, Attribute_, MetaItem, MetaWord, MetaNameValue, MetaList};
19-
use ast::{Stmt, StmtDecl, StmtExpr, StmtMac, StmtSemi, DeclKind};
19+
use ast::{Stmt, StmtKind, DeclKind};
2020
use ast::{Expr, Item, Local, Decl};
2121
use codemap::{Span, Spanned, spanned, dummy_spanned};
2222
use codemap::BytePos;
@@ -947,12 +947,12 @@ impl WithAttrs for P<Stmt> {
947947
Spanned {
948948
span: span,
949949
node: match node {
950-
StmtDecl(decl, id) => StmtDecl(decl.with_attrs(attrs), id),
951-
StmtExpr(expr, id) => StmtExpr(expr.with_attrs(attrs), id),
952-
StmtSemi(expr, id) => StmtSemi(expr.with_attrs(attrs), id),
953-
StmtMac(mac, style, mut ats) => {
950+
StmtKind::Decl(decl, id) => StmtKind::Decl(decl.with_attrs(attrs), id),
951+
StmtKind::Expr(expr, id) => StmtKind::Expr(expr.with_attrs(attrs), id),
952+
StmtKind::Semi(expr, id) => StmtKind::Semi(expr.with_attrs(attrs), id),
953+
StmtKind::Mac(mac, style, mut ats) => {
954954
ats.update(|a| a.append(attrs));
955-
StmtMac(mac, style, ats)
955+
StmtKind::Mac(mac, style, ats)
956956
}
957957
},
958958
}

src/libsyntax/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ impl<'v, 'a, 'b> visit::Visitor<'v> for StmtExprAttrFeatureVisitor<'a, 'b> {
372372
let stmt_attrs = s.node.attrs();
373373
if stmt_attrs.len() > 0 {
374374
// attributes on items are fine
375-
if let ast::StmtDecl(ref decl, _) = s.node {
375+
if let ast::StmtKind::Decl(ref decl, _) = s.node {
376376
if let ast::DeclKind::Item(_) = decl.node {
377377
visit::walk_stmt(self, s);
378378
return;

src/libsyntax/ext/base.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ macro_rules! make_stmts_default {
205205
($me:expr) => {
206206
$me.make_expr().map(|e| {
207207
SmallVector::one(P(codemap::respan(
208-
e.span, ast::StmtExpr(e, ast::DUMMY_NODE_ID))))
208+
e.span, ast::StmtKind::Expr(e, ast::DUMMY_NODE_ID))))
209209
})
210210
}
211211
}
@@ -402,8 +402,8 @@ impl MacResult for DummyResult {
402402
fn make_stmts(self: Box<DummyResult>) -> Option<SmallVector<P<ast::Stmt>>> {
403403
Some(SmallVector::one(P(
404404
codemap::respan(self.span,
405-
ast::StmtExpr(DummyResult::raw_expr(self.span),
406-
ast::DUMMY_NODE_ID)))))
405+
ast::StmtKind::Expr(DummyResult::raw_expr(self.span),
406+
ast::DUMMY_NODE_ID)))))
407407
}
408408
}
409409

src/libsyntax/ext/build.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
506506
}
507507

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

512512
fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident,
@@ -525,7 +525,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
525525
attrs: None,
526526
});
527527
let decl = respan(sp, ast::DeclKind::Local(local));
528-
P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID)))
528+
P(respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID)))
529529
}
530530

531531
fn stmt_let_typed(&self,
@@ -549,7 +549,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
549549
attrs: None,
550550
});
551551
let decl = respan(sp, ast::DeclKind::Local(local));
552-
P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID)))
552+
P(respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID)))
553553
}
554554

555555
fn block(&self, span: Span, stmts: Vec<P<ast::Stmt>>,
@@ -559,7 +559,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
559559

560560
fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> P<ast::Stmt> {
561561
let decl = respan(sp, ast::DeclKind::Item(item));
562-
P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID)))
562+
P(respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID)))
563563
}
564564

565565
fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block> {

src/libsyntax/ext/expand.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
use ast::{Block, Crate, DeclKind, PatMac};
1212
use ast::{Local, Ident, Mac_, Name};
13-
use ast::{ItemMac, MacStmtWithSemicolon, Mrk, Stmt, StmtDecl, StmtMac};
14-
use ast::{StmtExpr, StmtSemi};
13+
use ast::{ItemMac, MacStmtWithSemicolon, Mrk, Stmt, StmtKind};
1514
use ast::TokenTree;
1615
use ast;
1716
use ext::mtwt;
@@ -507,7 +506,7 @@ pub fn expand_item_mac(it: P<ast::Item>,
507506
fn expand_stmt(stmt: P<Stmt>, fld: &mut MacroExpander) -> SmallVector<P<Stmt>> {
508507
let stmt = stmt.and_then(|stmt| stmt);
509508
let (mac, style, attrs) = match stmt.node {
510-
StmtMac(mac, style, attrs) => (mac, style, attrs),
509+
StmtKind::Mac(mac, style, attrs) => (mac, style, attrs),
511510
_ => return expand_non_macro_stmt(stmt, fld)
512511
};
513512

@@ -539,7 +538,7 @@ fn expand_stmt(stmt: P<Stmt>, fld: &mut MacroExpander) -> SmallVector<P<Stmt>> {
539538
let new_stmt = stmt.map(|Spanned {node, span}| {
540539
Spanned {
541540
node: match node {
542-
StmtExpr(e, stmt_id) => StmtSemi(e, stmt_id),
541+
StmtKind::Expr(e, stmt_id) => StmtKind::Semi(e, stmt_id),
543542
_ => node /* might already have a semi */
544543
},
545544
span: span
@@ -558,7 +557,7 @@ fn expand_non_macro_stmt(Spanned {node, span: stmt_span}: Stmt, fld: &mut MacroE
558557
-> SmallVector<P<Stmt>> {
559558
// is it a let?
560559
match node {
561-
StmtDecl(decl, node_id) => decl.and_then(|Spanned {node: decl, span}| match decl {
560+
StmtKind::Decl(decl, node_id) => decl.and_then(|Spanned {node: decl, span}| match decl {
562561
DeclKind::Local(local) => {
563562
// take it apart:
564563
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
596595
}
597596
});
598597
SmallVector::one(P(Spanned {
599-
node: StmtDecl(P(Spanned {
598+
node: StmtKind::Decl(P(Spanned {
600599
node: DeclKind::Local(rewritten_local),
601600
span: span
602601
}),
@@ -606,7 +605,7 @@ fn expand_non_macro_stmt(Spanned {node, span: stmt_span}: Stmt, fld: &mut MacroE
606605
}
607606
_ => {
608607
noop_fold_stmt(Spanned {
609-
node: StmtDecl(P(Spanned {
608+
node: StmtKind::Decl(P(Spanned {
610609
node: decl,
611610
span: span
612611
}),

src/libsyntax/fold.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,39 +1347,39 @@ pub fn noop_fold_stmt<T: Folder>(Spanned {node, span}: Stmt, folder: &mut T)
13471347
-> SmallVector<P<Stmt>> {
13481348
let span = folder.new_span(span);
13491349
match node {
1350-
StmtDecl(d, id) => {
1350+
StmtKind::Decl(d, id) => {
13511351
let id = folder.new_id(id);
13521352
folder.fold_decl(d).into_iter().map(|d| P(Spanned {
1353-
node: StmtDecl(d, id),
1353+
node: StmtKind::Decl(d, id),
13541354
span: span
13551355
})).collect()
13561356
}
1357-
StmtExpr(e, id) => {
1357+
StmtKind::Expr(e, id) => {
13581358
let id = folder.new_id(id);
13591359
if let Some(e) = folder.fold_opt_expr(e) {
13601360
SmallVector::one(P(Spanned {
1361-
node: StmtExpr(e, id),
1361+
node: StmtKind::Expr(e, id),
13621362
span: span
13631363
}))
13641364
} else {
13651365
SmallVector::zero()
13661366
}
13671367
}
1368-
StmtSemi(e, id) => {
1368+
StmtKind::Semi(e, id) => {
13691369
let id = folder.new_id(id);
13701370
if let Some(e) = folder.fold_opt_expr(e) {
13711371
SmallVector::one(P(Spanned {
1372-
node: StmtSemi(e, id),
1372+
node: StmtKind::Semi(e, id),
13731373
span: span
13741374
}))
13751375
} else {
13761376
SmallVector::zero()
13771377
}
13781378
}
1379-
StmtMac(mac, semi, attrs) => SmallVector::one(P(Spanned {
1380-
node: StmtMac(mac.map(|m| folder.fold_mac(m)),
1381-
semi,
1382-
attrs.map_thin_attrs(|v| fold_attrs(v, folder))),
1379+
StmtKind::Mac(mac, semi, attrs) => SmallVector::one(P(Spanned {
1380+
node: StmtKind::Mac(mac.map(|m| folder.fold_mac(m)),
1381+
semi,
1382+
attrs.map_thin_attrs(|v| fold_attrs(v, folder))),
13831383
span: span
13841384
}))
13851385
}

0 commit comments

Comments
 (0)