Skip to content

Commit b491315

Browse files
committed
Don't fire the lint if there is a type annotation
Sometimes type annotations are needed for type inferrence to work, or because of coercions. We don't know this, and we also don't want users to possibly repeat the entire pattern.
1 parent 8d75c38 commit b491315

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

clippy_lints/src/manual_let_else.rs

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualLetElse {
7474
if let StmtKind::Local(local) = stmt.kind;
7575
if let Some(init) = local.init;
7676
if local.els.is_none();
77+
if local.ty.is_none();
7778
if init.span.ctxt() == stmt.span.ctxt();
7879
if let Some(if_let_or_match) = IfLetOrMatch::parse(cx, init);
7980
then {

tests/ui/manual_let_else.rs

+4
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,8 @@ fn not_fire() {
197197

198198
// Already a let-else
199199
let Some(a) = (if let Some(b) = Some(Some(())) { b } else { return }) else { panic!() };
200+
201+
// If a type annotation is present, don't lint as
202+
// expressing the type might be too hard
203+
let v: () = if let Some(v_some) = g() { v_some } else { panic!() };
200204
}

0 commit comments

Comments
 (0)