Skip to content

Commit 041d07e

Browse files
committed
refactor a lil
Update bool_comparison.stderr
1 parent 83856cb commit 041d07e

File tree

2 files changed

+35
-28
lines changed

2 files changed

+35
-28
lines changed

clippy_lints/src/needless_impls.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
use clippy_utils::{diagnostics::span_lint_and_then, get_parent_node, match_qpath, path_res, ty::implements_trait};
1+
use clippy_utils::{
2+
diagnostics::span_lint_and_then, get_parent_node, is_res_lang_ctor, path_res, ty::implements_trait,
3+
};
24
use rustc_errors::Applicability;
3-
use rustc_hir::{def::Res, Expr, ExprKind, ImplItem, ImplItemKind, ItemKind, Node, PatKind};
5+
use rustc_hir::{def::Res, Expr, ExprKind, ImplItem, ImplItemKind, ItemKind, LangItem, Node, PatKind};
46
use rustc_hir_analysis::hir_ty_to_ty;
57
use rustc_lint::{LateContext, LateLintPass};
68
use rustc_middle::ty::EarlyBinder;
@@ -99,10 +101,15 @@ impl LateLintPass<'_> for NeedlessImpls {
99101
{
100102
if block.stmts.is_empty()
101103
&& let Some(expr) = block.expr
102-
&& let ExprKind::Call(Expr { kind: ExprKind::Path(some_path), .. }, [cmp_expr]) = expr.kind
103-
// TODO: We can likely use the `option_some_variant` lang item instead, but this may be tricky
104-
// due to the fact that `expr` is the constructor, not `option_some_variant` itself.
105-
&& match_qpath(some_path, &["Some"])
104+
&& let ExprKind::Call(
105+
Expr {
106+
kind: ExprKind::Path(some_path),
107+
hir_id: some_hir_id,
108+
..
109+
},
110+
[cmp_expr],
111+
) = expr.kind
112+
&& is_res_lang_ctor(cx, cx.qpath_res(some_path, *some_hir_id), LangItem::OptionSome)
106113
&& let ExprKind::MethodCall(cmp_path, _, [other_expr], ..) = cmp_expr.kind
107114
&& cmp_path.ident.name == sym::cmp
108115
&& let Res::Local(..) = path_res(cx, other_expr)

tests/ui/bool_comparison.stderr

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,133 @@
11
error: equality checks against true are unnecessary
2-
--> $DIR/bool_comparison.rs:8:8
2+
--> $DIR/bool_comparison.rs:9:8
33
|
44
LL | if x == true {
55
| ^^^^^^^^^ help: try simplifying it as shown: `x`
66
|
77
= note: `-D clippy::bool-comparison` implied by `-D warnings`
88

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)