diff --git a/clippy_lints/src/returns/let_and_return.rs b/clippy_lints/src/returns/let_and_return.rs index 5b455f5f47f1..57f33632a5bc 100644 --- a/clippy_lints/src/returns/let_and_return.rs +++ b/clippy_lints/src/returns/let_and_return.rs @@ -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 diff --git a/tests/ui/let_and_return.edition2021.fixed b/tests/ui/let_and_return.edition2021.fixed index 42970e294b3d..1c814f54c939 100644 --- a/tests/ui/let_and_return.edition2021.fixed +++ b/tests/ui/let_and_return.edition2021.fixed @@ -292,4 +292,14 @@ fn wrongly_unmangled_macros() -> i32 { //~^ let_and_return } +fn issue16820() -> Option { + let value = Some(42); + + let v @ None = value else { + panic!("uh oh!"); + }; + + v +} + fn main() {} diff --git a/tests/ui/let_and_return.edition2024.fixed b/tests/ui/let_and_return.edition2024.fixed index fe8cac06ee83..b0c5a8359b7a 100644 --- a/tests/ui/let_and_return.edition2024.fixed +++ b/tests/ui/let_and_return.edition2024.fixed @@ -292,4 +292,14 @@ fn wrongly_unmangled_macros() -> i32 { //~^ let_and_return } +fn issue16820() -> Option { + let value = Some(42); + + let v @ None = value else { + panic!("uh oh!"); + }; + + v +} + fn main() {} diff --git a/tests/ui/let_and_return.rs b/tests/ui/let_and_return.rs index 187b12abe905..57660f7e031a 100644 --- a/tests/ui/let_and_return.rs +++ b/tests/ui/let_and_return.rs @@ -292,4 +292,14 @@ macro_rules! plus_one { //~^ let_and_return } +fn issue16820() -> Option { + let value = Some(42); + + let v @ None = value else { + panic!("uh oh!"); + }; + + v +} + fn main() {}