Fix clippy lint for identical if
/else
contraining ?
expressions
Follow up to #114819.
This commit is contained in:
parent
50f7f8e0f8
commit
32eecd4b88
@ -10,6 +10,7 @@
|
||||
GenericArgs, Guard, HirId, HirIdMap, InlineAsmOperand, Let, Lifetime, LifetimeName, Pat, PatField, PatKind, Path,
|
||||
PathSegment, PrimTy, QPath, Stmt, StmtKind, Ty, TyKind, TypeBinding,
|
||||
};
|
||||
use rustc_hir::MatchSource::TryDesugar;
|
||||
use rustc_lexer::{tokenize, TokenKind};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::ty::TypeckResults;
|
||||
@ -311,7 +312,7 @@ pub fn eq_expr(&mut self, left: &Expr<'_>, right: &Expr<'_>) -> bool {
|
||||
lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.name == r.ident.name)
|
||||
},
|
||||
(&ExprKind::Match(le, la, ref ls), &ExprKind::Match(re, ra, ref rs)) => {
|
||||
ls == rs
|
||||
(ls == rs || (matches!((ls, rs), (TryDesugar(_), TryDesugar(_)))))
|
||||
&& self.eq_expr(le, re)
|
||||
&& over(la, ra, |l, r| {
|
||||
self.eq_pat(l.pat, r.pat)
|
||||
|
@ -98,7 +98,7 @@ fn if_same_then_else2() -> Result<&'static str, ()> {
|
||||
};
|
||||
|
||||
if true {
|
||||
// FIXME: should emit "this `if` has identical blocks"
|
||||
//~^ ERROR: this `if` has identical blocks
|
||||
Ok("foo")?;
|
||||
} else {
|
||||
Ok("foo")?;
|
||||
|
@ -82,6 +82,25 @@ LL | | f32::NAN
|
||||
LL | | };
|
||||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/if_same_then_else2.rs:100:13
|
||||
|
|
||||
LL | if true {
|
||||
| _____________^
|
||||
LL | |
|
||||
LL | | Ok("foo")?;
|
||||
LL | | } else {
|
||||
| |_____^
|
||||
|
|
||||
note: same as this
|
||||
--> $DIR/if_same_then_else2.rs:103:12
|
||||
|
|
||||
LL | } else {
|
||||
| ____________^
|
||||
LL | | Ok("foo")?;
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: this `if` has identical blocks
|
||||
--> $DIR/if_same_then_else2.rs:124:20
|
||||
|
|
||||
@ -103,5 +122,5 @@ LL | | return Ok(&foo[0..]);
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user