Skip to content

Commit

Permalink
refactor a lil
Browse files Browse the repository at this point in the history
Update bool_comparison.stderr
  • Loading branch information
Centri3 committed Jun 12, 2023
1 parent aa1389b commit 1af0124
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
19 changes: 13 additions & 6 deletions clippy_lints/src/needless_impls.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use clippy_utils::{diagnostics::span_lint_and_then, get_parent_node, match_qpath, path_res, ty::implements_trait};
use clippy_utils::{
diagnostics::span_lint_and_then, get_parent_node, is_res_lang_ctor, path_res, ty::implements_trait,
};
use rustc_errors::Applicability;
use rustc_hir::{def::Res, Expr, ExprKind, ImplItem, ImplItemKind, ItemKind, Node, PatKind};
use rustc_hir::{def::Res, Expr, ExprKind, ImplItem, ImplItemKind, ItemKind, LangItem, Node, PatKind};
use rustc_hir_analysis::hir_ty_to_ty;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::EarlyBinder;
Expand Down Expand Up @@ -99,10 +101,15 @@ impl LateLintPass<'_> for NeedlessImpls {
{
if block.stmts.is_empty()
&& let Some(expr) = block.expr
&& let ExprKind::Call(Expr { kind: ExprKind::Path(some_path), .. }, [cmp_expr]) = expr.kind
// TODO: We can likely use the `option_some_variant` lang item instead, but this may be tricky
// due to the fact that `expr` is the constructor, not `option_some_variant` itself.
&& match_qpath(some_path, &["Some"])
&& let ExprKind::Call(
Expr {
kind: ExprKind::Path(some_path),
hir_id: some_hir_id,
..
},
[cmp_expr],
) = expr.kind
&& is_res_lang_ctor(cx, cx.qpath_res(some_path, *some_hir_id), LangItem::OptionSome)
&& let ExprKind::MethodCall(cmp_path, _, [other_expr], ..) = cmp_expr.kind
&& cmp_path.ident.name == sym::cmp
&& let Res::Local(..) = path_res(cx, other_expr)
Expand Down
44 changes: 22 additions & 22 deletions tests/ui/bool_comparison.stderr
Original file line number Diff line number Diff line change
@@ -1,133 +1,133 @@
error: equality checks against true are unnecessary
--> $DIR/bool_comparison.rs:8:8
--> $DIR/bool_comparison.rs:9:8
|
LL | if x == true {
| ^^^^^^^^^ help: try simplifying it as shown: `x`
|
= note: `-D clippy::bool-comparison` implied by `-D warnings`

error: equality checks against false can be replaced by a negation
--> $DIR/bool_comparison.rs:13:8
--> $DIR/bool_comparison.rs:14:8
|
LL | if x == false {
| ^^^^^^^^^^ help: try simplifying it as shown: `!x`

error: equality checks against true are unnecessary
--> $DIR/bool_comparison.rs:18:8
--> $DIR/bool_comparison.rs:19:8
|
LL | if true == x {
| ^^^^^^^^^ help: try simplifying it as shown: `x`

error: equality checks against false can be replaced by a negation
--> $DIR/bool_comparison.rs:23:8
--> $DIR/bool_comparison.rs:24:8
|
LL | if false == x {
| ^^^^^^^^^^ help: try simplifying it as shown: `!x`

error: inequality checks against true can be replaced by a negation
--> $DIR/bool_comparison.rs:28:8
--> $DIR/bool_comparison.rs:29:8
|
LL | if x != true {
| ^^^^^^^^^ help: try simplifying it as shown: `!x`

error: inequality checks against false are unnecessary
--> $DIR/bool_comparison.rs:33:8
--> $DIR/bool_comparison.rs:34:8
|
LL | if x != false {
| ^^^^^^^^^^ help: try simplifying it as shown: `x`

error: inequality checks against true can be replaced by a negation
--> $DIR/bool_comparison.rs:38:8
--> $DIR/bool_comparison.rs:39:8
|
LL | if true != x {
| ^^^^^^^^^ help: try simplifying it as shown: `!x`

error: inequality checks against false are unnecessary
--> $DIR/bool_comparison.rs:43:8
--> $DIR/bool_comparison.rs:44:8
|
LL | if false != x {
| ^^^^^^^^^^ help: try simplifying it as shown: `x`

error: less than comparison against true can be replaced by a negation
--> $DIR/bool_comparison.rs:48:8
--> $DIR/bool_comparison.rs:49:8
|
LL | if x < true {
| ^^^^^^^^ help: try simplifying it as shown: `!x`

error: greater than checks against false are unnecessary
--> $DIR/bool_comparison.rs:53:8
--> $DIR/bool_comparison.rs:54:8
|
LL | if false < x {
| ^^^^^^^^^ help: try simplifying it as shown: `x`

error: greater than checks against false are unnecessary
--> $DIR/bool_comparison.rs:58:8
--> $DIR/bool_comparison.rs:59:8
|
LL | if x > false {
| ^^^^^^^^^ help: try simplifying it as shown: `x`

error: less than comparison against true can be replaced by a negation
--> $DIR/bool_comparison.rs:63:8
--> $DIR/bool_comparison.rs:64:8
|
LL | if true > x {
| ^^^^^^^^ help: try simplifying it as shown: `!x`

error: order comparisons between booleans can be simplified
--> $DIR/bool_comparison.rs:69:8
--> $DIR/bool_comparison.rs:70:8
|
LL | if x < y {
| ^^^^^ help: try simplifying it as shown: `!x & y`

error: order comparisons between booleans can be simplified
--> $DIR/bool_comparison.rs:74:8
--> $DIR/bool_comparison.rs:75:8
|
LL | if x > y {
| ^^^^^ help: try simplifying it as shown: `x & !y`

error: this comparison might be written more concisely
--> $DIR/bool_comparison.rs:122:8
--> $DIR/bool_comparison.rs:123:8
|
LL | if a == !b {};
| ^^^^^^^ help: try simplifying it as shown: `a != b`

error: this comparison might be written more concisely
--> $DIR/bool_comparison.rs:123:8
--> $DIR/bool_comparison.rs:124:8
|
LL | if !a == b {};
| ^^^^^^^ help: try simplifying it as shown: `a != b`

error: this comparison might be written more concisely
--> $DIR/bool_comparison.rs:127:8
--> $DIR/bool_comparison.rs:128:8
|
LL | if b == !a {};
| ^^^^^^^ help: try simplifying it as shown: `b != a`

error: this comparison might be written more concisely
--> $DIR/bool_comparison.rs:128:8
--> $DIR/bool_comparison.rs:129:8
|
LL | if !b == a {};
| ^^^^^^^ help: try simplifying it as shown: `b != a`

error: equality checks against false can be replaced by a negation
--> $DIR/bool_comparison.rs:152:8
--> $DIR/bool_comparison.rs:153:8
|
LL | if false == m!(func) {}
| ^^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `!m!(func)`

error: equality checks against false can be replaced by a negation
--> $DIR/bool_comparison.rs:153:8
--> $DIR/bool_comparison.rs:154:8
|
LL | if m!(func) == false {}
| ^^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `!m!(func)`

error: equality checks against true are unnecessary
--> $DIR/bool_comparison.rs:154:8
--> $DIR/bool_comparison.rs:155:8
|
LL | if true == m!(func) {}
| ^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `m!(func)`

error: equality checks against true are unnecessary
--> $DIR/bool_comparison.rs:155:8
--> $DIR/bool_comparison.rs:156:8
|
LL | if m!(func) == true {}
| ^^^^^^^^^^^^^^^^ help: try simplifying it as shown: `m!(func)`
Expand Down

0 comments on commit 1af0124

Please sign in to comment.