Skip to content

Commit 37bffb7

Browse files
committed
Extract utility functions to utils.rs
1 parent ecbef77 commit 37bffb7

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

clippy_lints/src/unit_types/mod.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
mod utils;
2+
13
use rustc_errors::Applicability;
24
use rustc_hir as hir;
35
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, MatchSource, Node, Stmt, StmtKind};
46
use rustc_lint::{LateContext, LateLintPass, LintContext};
57
use rustc_middle::lint::in_external_macro;
6-
use rustc_middle::ty::{self, Ty};
78
use rustc_session::{declare_lint_pass, declare_tool_lint};
89
use rustc_span::hygiene::{ExpnKind, MacroKind};
910

@@ -13,6 +14,8 @@ use crate::utils::diagnostics::{span_lint, span_lint_and_then};
1314
use crate::utils::higher;
1415
use crate::utils::source::{indent_of, reindent_multiline, snippet_opt, snippet_with_macro_callsite};
1516

17+
use utils::{is_unit, is_unit_literal};
18+
1619
declare_clippy_lint! {
1720
/// **What it does:** Checks for binding a unit value.
1821
///
@@ -244,14 +247,6 @@ fn is_questionmark_desugar_marked_call(expr: &Expr<'_>) -> bool {
244247
}
245248
}
246249

247-
fn is_unit(ty: Ty<'_>) -> bool {
248-
matches!(ty.kind(), ty::Tuple(slice) if slice.is_empty())
249-
}
250-
251-
fn is_unit_literal(expr: &Expr<'_>) -> bool {
252-
matches!(expr.kind, ExprKind::Tup(ref slice) if slice.is_empty())
253-
}
254-
255250
fn lint_unit_args(cx: &LateContext<'_>, expr: &Expr<'_>, args_to_recover: &[&Expr<'_>]) {
256251
let mut applicability = Applicability::MachineApplicable;
257252
let (singular, plural) = if args_to_recover.len() > 1 {

clippy_lints/src/unit_types/utils.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use rustc_hir::{Expr, ExprKind};
2+
use rustc_middle::ty::{self, Ty};
3+
4+
pub(super) fn is_unit(ty: Ty<'_>) -> bool {
5+
matches!(ty.kind(), ty::Tuple(slice) if slice.is_empty())
6+
}
7+
8+
pub(super) fn is_unit_literal(expr: &Expr<'_>) -> bool {
9+
matches!(expr.kind, ExprKind::Tup(ref slice) if slice.is_empty())
10+
}

0 commit comments

Comments
 (0)