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.
This commit is contained in:
est31 2022-10-10 21:51:24 +02:00
parent 01e651f2fe
commit 748169deaa
2 changed files with 5 additions and 0 deletions

View File

@ -74,6 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualLetElse {
if let StmtKind::Local(local) = stmt.kind;
if let Some(init) = local.init;
if local.els.is_none();
if local.ty.is_none();
if init.span.ctxt() == stmt.span.ctxt();
if let Some(if_let_or_match) = IfLetOrMatch::parse(cx, init);
then {

View File

@ -197,4 +197,8 @@ fn not_fire() {
// Already a let-else
let Some(a) = (if let Some(b) = Some(Some(())) { b } else { return }) else { panic!() };
// If a type annotation is present, don't lint as
// expressing the type might be too hard
let v: () = if let Some(v_some) = g() { v_some } else { panic!() };
}