mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-26 13:01:27 +03:00
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:
@@ -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
|
||||
|
||||
@@ -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() {}
|
||||
|
||||
@@ -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() {}
|
||||
|
||||
@@ -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() {}
|
||||
|
||||
Reference in New Issue
Block a user