Skip to content

Commit

Permalink
Remove unit_types::utils::is_unit
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Nak committed Mar 16, 2021
1 parent 6211b49 commit 5a439f5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 11 deletions.
4 changes: 2 additions & 2 deletions clippy_lints/src/unit_types/let_unit_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use crate::utils::diagnostics::span_lint_and_then;
use crate::utils::higher;
use crate::utils::source::snippet_with_macro_callsite;

use super::{utils, LET_UNIT_VALUE};
use super::LET_UNIT_VALUE;

pub(super) fn check(cx: &LateContext<'_>, stmt: &Stmt<'_>) {
if let StmtKind::Local(ref local) = stmt.kind {
if utils::is_unit(cx.typeck_results().pat_ty(&local.pat)) {
if cx.typeck_results().pat_ty(&local.pat).is_unit() {
if in_external_macro(cx.sess(), stmt.span) || local.pat.span.from_expansion() {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/unit_types/unit_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
let args_to_recover = args
.iter()
.filter(|arg| {
if utils::is_unit(cx.typeck_results().expr_ty(arg)) && !utils::is_unit_literal(arg) {
if cx.typeck_results().expr_ty(arg).is_unit() && !utils::is_unit_literal(arg) {
!matches!(
&arg.kind,
ExprKind::Match(.., MatchSource::TryDesugar) | ExprKind::Path(..)
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/unit_types/unit_cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use rustc_span::hygiene::{ExpnKind, MacroKind};

use crate::utils::diagnostics::span_lint;

use super::{utils, UNIT_CMP};
use super::UNIT_CMP;

pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
if expr.span.from_expansion() {
if let Some(callee) = expr.span.source_callee() {
if let ExpnKind::Macro(MacroKind::Bang, symbol) = callee.kind {
if let ExprKind::Binary(ref cmp, ref left, _) = expr.kind {
let op = cmp.node;
if op.is_comparison() && utils::is_unit(cx.typeck_results().expr_ty(left)) {
if op.is_comparison() && cx.typeck_results().expr_ty(left).is_unit() {
let result = match &*symbol.as_str() {
"assert_eq" | "debug_assert_eq" => "succeed",
"assert_ne" | "debug_assert_ne" => "fail",
Expand All @@ -37,7 +37,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {

if let ExprKind::Binary(ref cmp, ref left, _) = expr.kind {
let op = cmp.node;
if op.is_comparison() && utils::is_unit(cx.typeck_results().expr_ty(left)) {
if op.is_comparison() && cx.typeck_results().expr_ty(left).is_unit() {
let result = match op {
BinOpKind::Eq | BinOpKind::Le | BinOpKind::Ge => "true",
_ => "false",
Expand Down
5 changes: 0 additions & 5 deletions clippy_lints/src/unit_types/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
use rustc_hir::{Expr, ExprKind};
use rustc_middle::ty::{self, Ty};

pub(super) fn is_unit(ty: Ty<'_>) -> bool {
matches!(ty.kind(), ty::Tuple(slice) if slice.is_empty())
}

pub(super) fn is_unit_literal(expr: &Expr<'_>) -> bool {
matches!(expr.kind, ExprKind::Tup(ref slice) if slice.is_empty())
Expand Down

0 comments on commit 5a439f5

Please sign in to comment.