Skip to content

Commit 6b12829

Browse files
committed
Move is_parent_stmt to clippy_utils
1 parent 4a8c949 commit 6b12829

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

clippy_lints/src/needless_bool.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg};
66
use clippy_utils::source::snippet_with_applicability;
77
use clippy_utils::sugg::Sugg;
88
use clippy_utils::{
9-
higher, is_else_clause, is_expn_of, peel_blocks, peel_blocks_with_stmt, span_extract_comment, SpanlessEq,
9+
higher, is_else_clause, is_expn_of, is_parent_stmt, peel_blocks, peel_blocks_with_stmt, span_extract_comment,
10+
SpanlessEq,
1011
};
1112
use rustc_ast::ast::LitKind;
1213
use rustc_errors::Applicability;
13-
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, HirId, Node, UnOp};
14+
use rustc_hir::{BinOpKind, Expr, ExprKind, UnOp};
1415
use rustc_lint::{LateContext, LateLintPass};
1516
use rustc_session::declare_lint_pass;
1617
use rustc_span::source_map::Spanned;
@@ -135,13 +136,6 @@ fn condition_needs_parentheses(e: &Expr<'_>) -> bool {
135136
false
136137
}
137138

138-
fn is_parent_stmt(cx: &LateContext<'_>, id: HirId) -> bool {
139-
matches!(
140-
cx.tcx.parent_hir_node(id),
141-
Node::Stmt(..) | Node::Block(Block { stmts: &[], .. })
142-
)
143-
}
144-
145139
impl<'tcx> LateLintPass<'tcx> for NeedlessBool {
146140
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
147141
use self::Expression::{Bool, RetBool};

clippy_utils/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3335,3 +3335,12 @@ fn maybe_get_relative_path(from: &DefPath, to: &DefPath, max_super: usize) -> St
33353335
repeat(String::from("super")).take(go_up_by).chain(path).join("::")
33363336
}
33373337
}
3338+
3339+
/// Returns true if the specified `HirId` is the top-level expression of a statement or the only
3340+
/// expression in a block.
3341+
pub fn is_parent_stmt(cx: &LateContext<'_>, id: HirId) -> bool {
3342+
matches!(
3343+
cx.tcx.parent_hir_node(id),
3344+
Node::Stmt(..) | Node::Block(Block { stmts: &[], .. })
3345+
)
3346+
}

0 commit comments

Comments
 (0)