Skip to content

Commit 962d5c1

Browse files
committed
Fix fallout
1 parent b5dbe01 commit 962d5c1

File tree

21 files changed

+307
-384
lines changed

21 files changed

+307
-384
lines changed

src/librustc/hir/lowering.rs

+17-22
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,6 @@ impl<'a> LoweringContext<'a> {
237237
}
238238
}
239239

240-
fn lower_decl(&mut self, d: &Decl) -> P<hir::Decl> {
241-
match d.node {
242-
DeclKind::Local(ref l) => P(Spanned {
243-
node: hir::DeclLocal(self.lower_local(l)),
244-
span: d.span,
245-
}),
246-
DeclKind::Item(ref it) => P(Spanned {
247-
node: hir::DeclItem(self.lower_item_id(it)),
248-
span: d.span,
249-
}),
250-
}
251-
}
252-
253240
fn lower_ty_binding(&mut self, b: &TypeBinding) -> hir::TypeBinding {
254241
hir::TypeBinding {
255242
id: b.id,
@@ -1579,21 +1566,29 @@ impl<'a> LoweringContext<'a> {
15791566

15801567
fn lower_stmt(&mut self, s: &Stmt) -> hir::Stmt {
15811568
match s.node {
1582-
StmtKind::Decl(ref d, id) => {
1583-
Spanned {
1584-
node: hir::StmtDecl(self.lower_decl(d), id),
1569+
StmtKind::Local(ref l) => Spanned {
1570+
node: hir::StmtDecl(P(Spanned {
1571+
node: hir::DeclLocal(self.lower_local(l)),
15851572
span: s.span,
1586-
}
1587-
}
1588-
StmtKind::Expr(ref e, id) => {
1573+
}), s.id),
1574+
span: s.span,
1575+
},
1576+
StmtKind::Item(ref it) => Spanned {
1577+
node: hir::StmtDecl(P(Spanned {
1578+
node: hir::DeclItem(self.lower_item_id(it)),
1579+
span: s.span,
1580+
}), s.id),
1581+
span: s.span,
1582+
},
1583+
StmtKind::Expr(ref e) => {
15891584
Spanned {
1590-
node: hir::StmtExpr(self.lower_expr(e), id),
1585+
node: hir::StmtExpr(self.lower_expr(e), s.id),
15911586
span: s.span,
15921587
}
15931588
}
1594-
StmtKind::Semi(ref e, id) => {
1589+
StmtKind::Semi(ref e) => {
15951590
Spanned {
1596-
node: hir::StmtSemi(self.lower_expr(e), id),
1591+
node: hir::StmtSemi(self.lower_expr(e), s.id),
15971592
span: s.span,
15981593
}
15991594
}

src/librustc/lint/context.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1005,11 +1005,6 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> {
10051005
ast_visit::walk_arm(self, a);
10061006
}
10071007

1008-
fn visit_decl(&mut self, d: &ast::Decl) {
1009-
run_lints!(self, check_decl, early_passes, d);
1010-
ast_visit::walk_decl(self, d);
1011-
}
1012-
10131008
fn visit_expr_post(&mut self, e: &ast::Expr) {
10141009
run_lints!(self, check_expr_post, early_passes, e);
10151010
}

src/librustc/lint/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ pub trait EarlyLintPass: LintPass {
195195
fn check_stmt(&mut self, _: &EarlyContext, _: &ast::Stmt) { }
196196
fn check_arm(&mut self, _: &EarlyContext, _: &ast::Arm) { }
197197
fn check_pat(&mut self, _: &EarlyContext, _: &ast::Pat) { }
198-
fn check_decl(&mut self, _: &EarlyContext, _: &ast::Decl) { }
199198
fn check_expr(&mut self, _: &EarlyContext, _: &ast::Expr) { }
200199
fn check_expr_post(&mut self, _: &EarlyContext, _: &ast::Expr) { }
201200
fn check_ty(&mut self, _: &EarlyContext, _: &ast::Ty) { }

src/librustc_lint/unused.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,9 @@ 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::StmtKind::Decl(ref decl, _) => match decl.node {
369-
ast::DeclKind::Local(ref local) => match local.init {
370-
Some(ref value) => (value, "assigned value"),
371-
None => return
372-
},
373-
_ => return
368+
ast::StmtKind::Local(ref local) => match local.init {
369+
Some(ref value) => (value, "assigned value"),
370+
None => return
374371
},
375372
_ => return
376373
};

src/librustc_resolve/build_reduced_graph.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ use syntax::attr;
3131
use syntax::parse::token;
3232
use syntax::codemap::{Span, DUMMY_SP};
3333

34-
use syntax::ast::{Block, Crate, DeclKind};
34+
use syntax::ast::{Block, Crate};
3535
use syntax::ast::{ForeignItem, ForeignItemKind, Item, ItemKind};
3636
use syntax::ast::{Mutability, PathListItemKind};
37-
use syntax::ast::{Stmt, StmtKind, TraitItemKind};
37+
use syntax::ast::{StmtKind, TraitItemKind};
3838
use syntax::ast::{Variant, ViewPathGlob, ViewPathList, ViewPathSimple};
3939
use syntax::visit::{self, Visitor};
4040

@@ -84,17 +84,11 @@ impl<'b> Resolver<'b> {
8484
}
8585

8686
fn block_needs_anonymous_module(&mut self, block: &Block) -> bool {
87-
fn is_item(statement: &Stmt) -> bool {
88-
if let StmtKind::Decl(ref declaration, _) = statement.node {
89-
if let DeclKind::Item(_) = declaration.node {
90-
return true;
91-
}
92-
}
93-
false
94-
}
95-
9687
// If any statements are items, we need to create an anonymous module
97-
block.stmts.iter().any(is_item)
88+
block.stmts.iter().any(|statement| match statement.node {
89+
StmtKind::Item(_) => true,
90+
_ => false,
91+
})
9892
}
9993

10094
/// Constructs the reduced graph for one item.

src/librustc_save_analysis/dump_visitor.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1421,8 +1421,7 @@ impl<'v, 'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor<'v> for DumpVisitor<'l, 'tcx,
14211421
}
14221422

14231423
fn visit_stmt(&mut self, s: &ast::Stmt) {
1424-
let id = s.node.id();
1425-
self.process_macro_use(s.span, id.unwrap());
1424+
self.process_macro_use(s.span, s.id);
14261425
visit::walk_stmt(self, s)
14271426
}
14281427

src/libsyntax/ast.rs

+1-20
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use ptr::P;
2929

3030
use std::fmt;
3131
use std::rc::Rc;
32-
use std::borrow::Cow;
3332
use std::hash::{Hash, Hasher};
3433
use serialize::{Encodable, Decodable, Encoder, Decoder};
3534

@@ -795,10 +794,7 @@ pub struct Stmt {
795794

796795
impl fmt::Debug for Stmt {
797796
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
798-
write!(f, "stmt({}: {})",
799-
self.node.id()
800-
.map_or(Cow::Borrowed("<macro>"),|id|Cow::Owned(id.to_string())),
801-
pprust::stmt_to_string(self))
797+
write!(f, "stmt({}: {})", self.id.to_string(), pprust::stmt_to_string(self))
802798
}
803799
}
804800

@@ -821,15 +817,6 @@ pub enum StmtKind {
821817
}
822818

823819
impl StmtKind {
824-
pub fn id(&self) -> Option<NodeId> {
825-
match *self {
826-
StmtKind::Decl(_, id) => Some(id),
827-
StmtKind::Expr(_, id) => Some(id),
828-
StmtKind::Semi(_, id) => Some(id),
829-
StmtKind::Mac(..) => None,
830-
}
831-
}
832-
833820
pub fn attrs(&self) -> &[Attribute] {
834821
HasAttrs::attrs(self)
835822
}
@@ -868,12 +855,6 @@ impl Local {
868855
}
869856
}
870857

871-
impl Decl {
872-
pub fn attrs(&self) -> &[Attribute] {
873-
HasAttrs::attrs(self)
874-
}
875-
}
876-
877858
/// represents one arm of a 'match'
878859
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
879860
pub struct Arm {

src/libsyntax/attr.rs

+17-27
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ pub use self::IntType::*;
1616

1717
use ast;
1818
use ast::{AttrId, Attribute, Attribute_, MetaItem, MetaItemKind};
19-
use ast::{Stmt, StmtKind, DeclKind};
20-
use ast::{Expr, Item, Local, Decl};
19+
use ast::{Stmt, StmtKind};
20+
use ast::{Expr, Item, Local};
2121
use codemap::{Span, Spanned, spanned, dummy_spanned};
2222
use codemap::BytePos;
2323
use errors::Handler;
@@ -924,38 +924,28 @@ impl<T: HasAttrs + 'static> HasAttrs for P<T> {
924924
}
925925
}
926926

927-
impl HasAttrs for DeclKind {
928-
fn attrs(&self) -> &[Attribute] {
929-
match *self {
930-
DeclKind::Local(ref local) => local.attrs(),
931-
DeclKind::Item(ref item) => item.attrs(),
932-
}
933-
}
934-
935-
fn map_attrs<F: FnOnce(Vec<Attribute>) -> Vec<Attribute>>(self, f: F) -> Self {
936-
match self {
937-
DeclKind::Local(local) => DeclKind::Local(local.map_attrs(f)),
938-
DeclKind::Item(item) => DeclKind::Item(item.map_attrs(f)),
939-
}
940-
}
941-
}
942-
943927
impl HasAttrs for StmtKind {
944928
fn attrs(&self) -> &[Attribute] {
945929
match *self {
946-
StmtKind::Decl(ref decl, _) => decl.attrs(),
947-
StmtKind::Expr(ref expr, _) | StmtKind::Semi(ref expr, _) => expr.attrs(),
948-
StmtKind::Mac(_, _, ref attrs) => attrs.attrs(),
930+
StmtKind::Local(ref local) => local.attrs(),
931+
StmtKind::Item(ref item) => item.attrs(),
932+
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => expr.attrs(),
933+
StmtKind::Mac(ref mac) => {
934+
let (_, _, ref attrs) = **mac;
935+
attrs.attrs()
936+
}
949937
}
950938
}
951939

952940
fn map_attrs<F: FnOnce(Vec<Attribute>) -> Vec<Attribute>>(self, f: F) -> Self {
953941
match self {
954-
StmtKind::Decl(decl, id) => StmtKind::Decl(decl.map_attrs(f), id),
955-
StmtKind::Expr(expr, id) => StmtKind::Expr(expr.map_attrs(f), id),
956-
StmtKind::Semi(expr, id) => StmtKind::Semi(expr.map_attrs(f), id),
957-
StmtKind::Mac(mac, style, attrs) =>
958-
StmtKind::Mac(mac, style, attrs.map_attrs(f)),
942+
StmtKind::Local(local) => StmtKind::Local(local.map_attrs(f)),
943+
StmtKind::Item(item) => StmtKind::Item(item.map_attrs(f)),
944+
StmtKind::Expr(expr) => StmtKind::Expr(expr.map_attrs(f)),
945+
StmtKind::Semi(expr) => StmtKind::Semi(expr.map_attrs(f)),
946+
StmtKind::Mac(mac) => StmtKind::Mac(mac.map(|(mac, style, attrs)| {
947+
(mac, style, attrs.map_attrs(f))
948+
})),
959949
}
960950
}
961951
}
@@ -982,4 +972,4 @@ derive_has_attrs_from_field! {
982972
Item, Expr, Local, ast::ForeignItem, ast::StructField, ast::ImplItem, ast::TraitItem, ast::Arm
983973
}
984974

985-
derive_has_attrs_from_field! { Decl: .node, Stmt: .node, ast::Variant: .node.attrs }
975+
derive_has_attrs_from_field! { Stmt: .node, ast::Variant: .node.attrs }

src/libsyntax/config.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,10 @@ impl<'a> fold::Folder for StripUnconfigured<'a> {
212212
}
213213

214214
fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVector<ast::Stmt> {
215-
let is_item = match stmt.node {
216-
ast::StmtKind::Decl(ref decl, _) => match decl.node {
217-
ast::DeclKind::Item(_) => true,
218-
_ => false,
219-
},
220-
_ => false,
221-
};
222-
223215
// avoid calling `visit_stmt_or_expr_attrs` on items
224-
if !is_item {
225-
self.visit_stmt_or_expr_attrs(stmt.attrs());
216+
match stmt.node {
217+
ast::StmtKind::Item(_) => {}
218+
_ => self.visit_stmt_or_expr_attrs(stmt.attrs()),
226219
}
227220

228221
self.configure(stmt).map(|stmt| fold::noop_fold_stmt(stmt, self))

src/libsyntax/ext/base.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,11 @@ impl<F> IdentMacroExpander for F
202202
// Use a macro because forwarding to a simple function has type system issues
203203
macro_rules! make_stmts_default {
204204
($me:expr) => {
205-
$me.make_expr().map(|e| {
206-
SmallVector::one(codemap::respan(
207-
e.span, ast::StmtKind::Expr(e, ast::DUMMY_NODE_ID)))
208-
})
205+
$me.make_expr().map(|e| SmallVector::one(ast::Stmt {
206+
id: ast::DUMMY_NODE_ID,
207+
span: e.span,
208+
node: ast::StmtKind::Expr(e),
209+
}))
209210
}
210211
}
211212

@@ -399,10 +400,11 @@ impl MacResult for DummyResult {
399400
}
400401

401402
fn make_stmts(self: Box<DummyResult>) -> Option<SmallVector<ast::Stmt>> {
402-
Some(SmallVector::one(
403-
codemap::respan(self.span,
404-
ast::StmtKind::Expr(DummyResult::raw_expr(self.span),
405-
ast::DUMMY_NODE_ID))))
403+
Some(SmallVector::one(ast::Stmt {
404+
id: ast::DUMMY_NODE_ID,
405+
node: ast::StmtKind::Expr(DummyResult::raw_expr(self.span)),
406+
span: self.span,
407+
}))
406408
}
407409
}
408410

src/libsyntax/ext/build.rs

+20-7
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,11 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
508508
}
509509

510510
fn stmt_expr(&self, expr: P<ast::Expr>) -> ast::Stmt {
511-
respan(expr.span, ast::StmtKind::Semi(expr, ast::DUMMY_NODE_ID))
511+
ast::Stmt {
512+
id: ast::DUMMY_NODE_ID,
513+
span: expr.span,
514+
node: ast::StmtKind::Semi(expr),
515+
}
512516
}
513517

514518
fn stmt_let(&self, sp: Span, mutbl: bool, ident: ast::Ident,
@@ -527,8 +531,11 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
527531
span: sp,
528532
attrs: None,
529533
});
530-
let decl = respan(sp, ast::DeclKind::Local(local));
531-
respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID))
534+
ast::Stmt {
535+
id: ast::DUMMY_NODE_ID,
536+
node: ast::StmtKind::Local(local),
537+
span: sp,
538+
}
532539
}
533540

534541
fn stmt_let_typed(&self,
@@ -552,8 +559,11 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
552559
span: sp,
553560
attrs: None,
554561
});
555-
let decl = respan(sp, ast::DeclKind::Local(local));
556-
P(respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID)))
562+
P(ast::Stmt {
563+
id: ast::DUMMY_NODE_ID,
564+
node: ast::StmtKind::Local(local),
565+
span: sp,
566+
})
557567
}
558568

559569
fn block(&self, span: Span, stmts: Vec<ast::Stmt>,
@@ -562,8 +572,11 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
562572
}
563573

564574
fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> ast::Stmt {
565-
let decl = respan(sp, ast::DeclKind::Item(item));
566-
respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID))
575+
ast::Stmt {
576+
id: ast::DUMMY_NODE_ID,
577+
node: ast::StmtKind::Item(item),
578+
span: sp,
579+
}
567580
}
568581

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

0 commit comments

Comments
 (0)