Skip to content

Commit 867a12d

Browse files
authored
Rollup merge of #115122 - estebank:fix-clippy, r=Manishearth
Fix clippy lint for identical `if`/`else` contraining `?` expressions Follow up to #114819.
2 parents 0a78123 + 91cf04d commit 867a12d

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/tools/clippy/clippy_utils/src/hir_utils.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_hir::{
1010
GenericArgs, Guard, HirId, HirIdMap, InlineAsmOperand, Let, Lifetime, LifetimeName, Pat, PatField, PatKind, Path,
1111
PathSegment, PrimTy, QPath, Stmt, StmtKind, Ty, TyKind, TypeBinding,
1212
};
13+
use rustc_hir::MatchSource::TryDesugar;
1314
use rustc_lexer::{tokenize, TokenKind};
1415
use rustc_lint::LateContext;
1516
use rustc_middle::ty::TypeckResults;
@@ -311,7 +312,7 @@ impl HirEqInterExpr<'_, '_, '_> {
311312
lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.name == r.ident.name)
312313
},
313314
(&ExprKind::Match(le, la, ref ls), &ExprKind::Match(re, ra, ref rs)) => {
314-
ls == rs
315+
(ls == rs || (matches!((ls, rs), (TryDesugar(_), TryDesugar(_)))))
315316
&& self.eq_expr(le, re)
316317
&& over(la, ra, |l, r| {
317318
self.eq_pat(l.pat, r.pat)

src/tools/clippy/tests/ui/if_same_then_else2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ fn if_same_then_else2() -> Result<&'static str, ()> {
9898
};
9999

100100
if true {
101-
// FIXME: should emit "this `if` has identical blocks"
101+
//~^ ERROR: this `if` has identical blocks
102102
Ok("foo")?;
103103
} else {
104104
Ok("foo")?;

src/tools/clippy/tests/ui/if_same_then_else2.stderr

+20-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,25 @@ LL | | f32::NAN
8282
LL | | };
8383
| |_____^
8484

85+
error: this `if` has identical blocks
86+
--> $DIR/if_same_then_else2.rs:100:13
87+
|
88+
LL | if true {
89+
| _____________^
90+
LL | |
91+
LL | | Ok("foo")?;
92+
LL | | } else {
93+
| |_____^
94+
|
95+
note: same as this
96+
--> $DIR/if_same_then_else2.rs:103:12
97+
|
98+
LL | } else {
99+
| ____________^
100+
LL | | Ok("foo")?;
101+
LL | | }
102+
| |_____^
103+
85104
error: this `if` has identical blocks
86105
--> $DIR/if_same_then_else2.rs:124:20
87106
|
@@ -103,5 +122,5 @@ LL | | return Ok(&foo[0..]);
103122
LL | | }
104123
| |_____^
105124

106-
error: aborting due to 5 previous errors
125+
error: aborting due to 6 previous errors
107126

0 commit comments

Comments
 (0)