Do not trigger let_and_return on let else (#16829)

changelog: [`let_and_return_on`]: do not trigger on `let else` construct

Fixes rust-lang/rust-clippy#16820
This commit is contained in:
Samuel Tardieu
2026-04-16 15:37:47 +00:00
committed by GitHub
4 changed files with 31 additions and 0 deletions
@@ -19,6 +19,7 @@ pub(super) fn check_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'_>)
&& let Some(stmt) = block.stmts.last()
&& let StmtKind::Let(local) = &stmt.kind
&& local.ty.is_none()
&& local.els.is_none()
&& cx.tcx.hir_attrs(local.hir_id).is_empty()
&& let Some(initexpr) = &local.init
&& let PatKind::Binding(_, local_id, _, _) = local.pat.kind
+10
View File
@@ -292,4 +292,14 @@ fn wrongly_unmangled_macros() -> i32 {
//~^ let_and_return
}
fn issue16820() -> Option<i32> {
let value = Some(42);
let v @ None = value else {
panic!("uh oh!");
};
v
}
fn main() {}
+10
View File
@@ -292,4 +292,14 @@ fn wrongly_unmangled_macros() -> i32 {
//~^ let_and_return
}
fn issue16820() -> Option<i32> {
let value = Some(42);
let v @ None = value else {
panic!("uh oh!");
};
v
}
fn main() {}
+10
View File
@@ -292,4 +292,14 @@ macro_rules! plus_one {
//~^ let_and_return
}
fn issue16820() -> Option<i32> {
let value = Some(42);
let v @ None = value else {
panic!("uh oh!");
};
v
}
fn main() {}