Skip to content
Permalink
Browse files

Rename `Stmt.node` to `Stmt.kind`

  • Loading branch information...
varkor committed Sep 26, 2019
1 parent c3d8791 commit 21bf983acbb5d7ac8fb9462cbf2cc4c280abd857
@@ -262,7 +262,7 @@ impl CheckAttrVisitor<'tcx> {

fn check_stmt_attributes(&self, stmt: &hir::Stmt) {
// When checking statements ignore expressions, they will be checked later
if let hir::StmtKind::Local(ref l) = stmt.node {
if let hir::StmtKind::Local(ref l) = stmt.kind {
for attr in l.attrs.iter() {
if attr.check_name(sym::inline) {
self.check_inline(attr, &stmt.span, Target::Statement);
@@ -974,7 +974,7 @@ 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) {
visitor.visit_id(statement.hir_id);
match statement.node {
match statement.kind {
StmtKind::Local(ref local) => visitor.visit_local(local),
StmtKind::Item(item) => visitor.visit_nested_item(item),
StmtKind::Expr(ref expression) |
@@ -2660,7 +2660,7 @@ impl<'a> LoweringContext<'a> {

for (index, stmt) in b.stmts.iter().enumerate() {
if index == b.stmts.len() - 1 {
if let StmtKind::Expr(ref e) = stmt.node {
if let StmtKind::Expr(ref e) = stmt.kind {
expr = Some(P(self.lower_expr(e)));
} else {
stmts.extend(self.lower_stmt(stmt));
@@ -2931,7 +2931,7 @@ impl<'a> LoweringContext<'a> {
}

fn lower_stmt(&mut self, s: &Stmt) -> SmallVec<[hir::Stmt; 1]> {
let node = match s.node {
let kind = match s.kind {
StmtKind::Local(ref l) => {
let (l, item_ids) = self.lower_local(l);
let mut ids: SmallVec<[hir::Stmt; 1]> = item_ids
@@ -2944,7 +2944,7 @@ impl<'a> LoweringContext<'a> {
ids.push({
hir::Stmt {
hir_id: self.lower_node_id(s.id),
node: hir::StmtKind::Local(P(l)),
kind: hir::StmtKind::Local(P(l)),
span: s.span,
}
});
@@ -2962,7 +2962,7 @@ impl<'a> LoweringContext<'a> {

hir::Stmt {
hir_id,
node: hir::StmtKind::Item(item_id),
kind: hir::StmtKind::Item(item_id),
span: s.span,
}
})
@@ -2974,7 +2974,7 @@ impl<'a> LoweringContext<'a> {
};
smallvec![hir::Stmt {
hir_id: self.lower_node_id(s.id),
node,
kind,
span: s.span,
}]
}
@@ -3011,8 +3011,8 @@ impl<'a> LoweringContext<'a> {

// Helper methods for building HIR.

fn stmt(&mut self, span: Span, node: hir::StmtKind) -> hir::Stmt {
hir::Stmt { span, node, hir_id: self.next_id() }
fn stmt(&mut self, span: Span, kind: hir::StmtKind) -> hir::Stmt {
hir::Stmt { span, kind, hir_id: self.next_id() }
}

fn stmt_expr(&mut self, span: Span, expr: hir::Expr) -> hir::Stmt {
@@ -303,7 +303,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
}

fn visit_stmt(&mut self, stmt: &'a Stmt) {
match stmt.node {
match stmt.kind {
StmtKind::Mac(..) => self.visit_macro_invoc(stmt.id),
_ => visit::walk_stmt(self, stmt),
}
@@ -968,7 +968,7 @@ impl<'hir> Map<'hir> {
Some(Node::Variant(ref v)) => Some(&v.attrs[..]),
Some(Node::Field(ref f)) => Some(&f.attrs[..]),
Some(Node::Expr(ref e)) => Some(&*e.attrs),
Some(Node::Stmt(ref s)) => Some(s.node.attrs()),
Some(Node::Stmt(ref s)) => Some(s.kind.attrs()),
Some(Node::Arm(ref a)) => Some(&*a.attrs),
Some(Node::GenericParam(param)) => Some(&param.attrs[..]),
// Unit/tuple structs/variants take the attributes straight from
@@ -1221,7 +1221,7 @@ impl UnOp {
#[derive(RustcEncodable, RustcDecodable)]
pub struct Stmt {
pub hir_id: HirId,
pub node: StmtKind,
pub kind: StmtKind,
pub span: Span,
}

@@ -944,7 +944,7 @@ impl<'a> State<'a> {

pub fn print_stmt(&mut self, st: &hir::Stmt) {
self.maybe_print_comment(st.span.lo());
match st.node {
match st.kind {
hir::StmtKind::Local(ref loc) => {
self.print_local(loc.init.as_deref(), |this| this.print_local_decl(&loc));
}
@@ -961,7 +961,7 @@ impl<'a> State<'a> {
self.s.word(";");
}
}
if stmt_ends_with_semi(&st.node) {
if stmt_ends_with_semi(&st.kind) {
self.s.word(";");
}
self.maybe_print_trailing_comment(st.span, None)
@@ -158,7 +158,7 @@ impl_stable_hash_for_spanned!(hir::BinOpKind);

impl_stable_hash_for!(struct hir::Stmt {
hir_id,
node,
kind,
span,
});

@@ -590,7 +590,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
}

fn walk_stmt(&mut self, stmt: &hir::Stmt) {
match stmt.node {
match stmt.kind {
hir::StmtKind::Local(ref local) => {
self.walk_local(&local);
}
@@ -947,7 +947,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {

fn propagate_through_stmt(&mut self, stmt: &hir::Stmt, succ: LiveNode)
-> LiveNode {
match stmt.node {
match stmt.kind {
hir::StmtKind::Local(ref local) => {
// Note: we mark the variable as defined regardless of whether
// there is an initializer. Initially I had thought to only mark
@@ -796,7 +796,7 @@ fn resolve_block<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, blk: &'tcx h
// index information.)

for (i, statement) in blk.stmts.iter().enumerate() {
match statement.node {
match statement.kind {
hir::StmtKind::Local(..) |
hir::StmtKind::Item(..) => {
// Each declaration introduces a subscope for bindings
@@ -99,7 +99,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
}

fn stmt(&mut self, stmt: &hir::Stmt, pred: CFGIndex) -> CFGIndex {
let exit = match stmt.node {
let exit = match stmt.kind {
hir::StmtKind::Local(ref local) => {
let init_exit = self.opt_expr(&local.init, pred);
self.pat(&local.pat, init_exit)
@@ -841,7 +841,7 @@ impl<'a> MutVisitor for ReplaceBodyWithLoop<'a> {

ast::Stmt {
id: sess.next_node_id(),
node: ast::StmtKind::Expr(expr),
kind: ast::StmtKind::Expr(expr),
span: syntax_pos::DUMMY_SP,
}
}
@@ -857,7 +857,7 @@ impl<'a> MutVisitor for ReplaceBodyWithLoop<'a> {
let loop_stmt = ast::Stmt {
id: self.sess.next_node_id(),
span: syntax_pos::DUMMY_SP,
node: ast::StmtKind::Expr(loop_expr),
kind: ast::StmtKind::Expr(loop_expr),
};

if self.within_static_or_const {
@@ -772,7 +772,7 @@ impl EarlyLintPass for UnusedDocComment {
}

fn check_stmt(&mut self, cx: &EarlyContext<'_>, stmt: &ast::Stmt) {
let (kind, is_macro_expansion) = match stmt.node {
let (kind, is_macro_expansion) = match stmt.kind {
ast::StmtKind::Local(..) => ("statements", false),
ast::StmtKind::Item(..) => ("inner items", false),
ast::StmtKind::Mac(..) => ("macro expansions", true),
@@ -781,7 +781,7 @@ impl EarlyLintPass for UnusedDocComment {
ast::StmtKind::Expr(..) => return,
};

self.warn_if_doc(cx, stmt.span, kind, is_macro_expansion, stmt.node.attrs());
self.warn_if_doc(cx, stmt.span, kind, is_macro_expansion, stmt.kind.attrs());
}

fn check_arm(&mut self, cx: &EarlyContext<'_>, arm: &ast::Arm) {
@@ -12,7 +12,7 @@ declare_lint_pass!(RedundantSemicolon => [REDUNDANT_SEMICOLON]);

impl EarlyLintPass for RedundantSemicolon {
fn check_stmt(&mut self, cx: &EarlyContext<'_>, stmt: &Stmt) {
if let StmtKind::Semi(expr) = &stmt.node {
if let StmtKind::Semi(expr) = &stmt.kind {
if let ExprKind::Tup(ref v) = &expr.kind {
if v.is_empty() {
// Strings of excess semicolons are encoded as empty tuple expressions
@@ -38,7 +38,7 @@ declare_lint_pass!(UnusedResults => [UNUSED_MUST_USE, UNUSED_RESULTS]);

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
fn check_stmt(&mut self, cx: &LateContext<'_, '_>, s: &hir::Stmt) {
let expr = match s.node {
let expr = match s.kind {
hir::StmtKind::Semi(ref expr) => &**expr,
_ => return,
};
@@ -269,7 +269,7 @@ declare_lint_pass!(PathStatements => [PATH_STATEMENTS]);

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PathStatements {
fn check_stmt(&mut self, cx: &LateContext<'_, '_>, s: &hir::Stmt) {
if let hir::StmtKind::Semi(ref expr) = s.node {
if let hir::StmtKind::Semi(ref expr) = s.kind {
if let hir::ExprKind::Path(_) = expr.kind {
cx.span_lint(PATH_STATEMENTS, s.span, "path statement with no effect");
}
@@ -587,7 +587,7 @@ impl EarlyLintPass for UnusedParens {
}

fn check_stmt(&mut self, cx: &EarlyContext<'_>, s: &ast::Stmt) {
if let ast::StmtKind::Local(ref local) = s.node {
if let ast::StmtKind::Local(ref local) = s.kind {
self.check_unused_parens_pat(cx, &local.pat, false, false);

if let Some(ref value) = local.init {
@@ -49,7 +49,7 @@ fn mirror_stmts<'a, 'tcx>(
for (index, stmt) in stmts.iter().enumerate() {
let hir_id = stmt.hir_id;
let opt_dxn_ext = cx.region_scope_tree.opt_destruction_scope(hir_id.local_id);
match stmt.node {
match stmt.kind {
hir::StmtKind::Expr(ref expr) |
hir::StmtKind::Semi(ref expr) => {
result.push(StmtRef::Mirror(Box::new(Stmt {
@@ -212,7 +212,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
}

fn check_stmt(&mut self, stmt: &'tcx hir::Stmt) -> Promotability {
match stmt.node {
match stmt.kind {
hir::StmtKind::Local(ref local) => {
if self.remove_mut_rvalue_borrow(&local.pat) {
if let Some(init) = &local.init {
@@ -309,7 +309,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {

fn block_needs_anonymous_module(&mut self, block: &Block) -> bool {
// If any statements are items, we need to create an anonymous module
block.stmts.iter().any(|statement| match statement.node {
block.stmts.iter().any(|statement| match statement.kind {
StmtKind::Item(_) | StmtKind::Mac(_) => true,
_ => false,
})
@@ -1161,7 +1161,7 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
}

fn visit_stmt(&mut self, stmt: &'b ast::Stmt) {
if let ast::StmtKind::Mac(..) = stmt.node {
if let ast::StmtKind::Mac(..) = stmt.kind {
self.parent_scope.legacy = self.visit_invoc(stmt.id);
} else {
visit::walk_stmt(self, stmt);
@@ -1804,7 +1804,7 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {

// Descend into the block.
for stmt in &block.stmts {
if let StmtKind::Item(ref item) = stmt.node {
if let StmtKind::Item(ref item) = stmt.kind {
if let ItemKind::MacroDef(..) = item.node {
num_macro_definition_ribs += 1;
let res = self.r.definitions.local_def_id(item.id);
@@ -3860,7 +3860,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

pub fn check_stmt(&self, stmt: &'tcx hir::Stmt) {
// Don't do all the complex logic below for `DeclItem`.
match stmt.node {
match stmt.kind {
hir::StmtKind::Item(..) => return,
hir::StmtKind::Local(..) | hir::StmtKind::Expr(..) | hir::StmtKind::Semi(..) => {}
}
@@ -3873,7 +3873,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.diverges.set(Diverges::Maybe);
self.has_errors.set(false);

match stmt.node {
match stmt.kind {
hir::StmtKind::Local(ref l) => {
self.check_decl_local(&l);
}
@@ -4560,7 +4560,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Be helpful when the user wrote `{... expr;}` and
// taking the `;` off is enough to fix the error.
let last_stmt = blk.stmts.last()?;
let last_expr = match last_stmt.node {
let last_expr = match last_stmt.kind {
hir::StmtKind::Semi(ref e) => e,
_ => return None,
};
@@ -835,31 +835,31 @@ impl UnOp {
#[derive(Clone, RustcEncodable, RustcDecodable)]
pub struct Stmt {
pub id: NodeId,
pub node: StmtKind,
pub kind: StmtKind,
pub span: Span,
}

impl Stmt {
pub fn add_trailing_semicolon(mut self) -> Self {
self.node = match self.node {
self.kind = match self.kind {
StmtKind::Expr(expr) => StmtKind::Semi(expr),
StmtKind::Mac(mac) => {
StmtKind::Mac(mac.map(|(mac, _style, attrs)| (mac, MacStmtStyle::Semicolon, attrs)))
}
node => node,
kind => kind,
};
self
}

pub fn is_item(&self) -> bool {
match self.node {
match self.kind {
StmtKind::Item(_) => true,
_ => false,
}
}

pub fn is_expr(&self) -> bool {
match self.node {
match self.kind {
StmtKind::Expr(_) => true,
_ => false,
}
@@ -991,7 +991,7 @@ impl Expr {
/// for example, an `if` condition.
pub fn returns(&self) -> bool {
if let ExprKind::Block(ref block, _) = self.kind {
match block.stmts.last().map(|last_stmt| &last_stmt.node) {
match block.stmts.last().map(|last_stmt| &last_stmt.kind) {
// Implicit return
Some(&StmtKind::Expr(_)) => true,
Some(&StmtKind::Semi(ref expr)) => {
@@ -702,11 +702,11 @@ impl HasAttrs for StmtKind {

impl HasAttrs for Stmt {
fn attrs(&self) -> &[ast::Attribute] {
self.node.attrs()
self.kind.attrs()
}

fn visit_attrs<F: FnOnce(&mut Vec<ast::Attribute>)>(&mut self, f: F) {
self.node.visit_attrs(f);
self.kind.visit_attrs(f);
}
}

@@ -363,7 +363,7 @@ macro_rules! make_stmts_default {
$me.make_expr().map(|e| smallvec![ast::Stmt {
id: ast::DUMMY_NODE_ID,
span: e.span,
node: ast::StmtKind::Expr(e),
kind: ast::StmtKind::Expr(e),
}])
}
}
@@ -602,7 +602,7 @@ impl MacResult for DummyResult {
fn make_stmts(self: Box<DummyResult>) -> Option<SmallVec<[ast::Stmt; 1]>> {
Some(smallvec![ast::Stmt {
id: ast::DUMMY_NODE_ID,
node: ast::StmtKind::Expr(DummyResult::raw_expr(self.span, self.is_error)),
kind: ast::StmtKind::Expr(DummyResult::raw_expr(self.span, self.is_error)),
span: self.span,
}])
}

0 comments on commit 21bf983

Please sign in to comment.
You can’t perform that action at this time.