Replace manual let else patterns with let else

This commit is contained in:
est31 2022-10-10 22:37:42 +02:00
parent cf72565a12
commit f48d13f8d1
32 changed files with 73 additions and 150 deletions

View File

@ -36,9 +36,8 @@ impl ClippyProjectInfo {
} }
pub fn setup_rustc_src(rustc_path: &str) { pub fn setup_rustc_src(rustc_path: &str) {
let rustc_source_dir = match check_and_get_rustc_dir(rustc_path) { let Ok(rustc_source_dir) = check_and_get_rustc_dir(rustc_path) else {
Ok(path) => path, return
Err(_) => return,
}; };
for project in CLIPPY_PROJECTS { for project in CLIPPY_PROJECTS {
@ -172,14 +171,10 @@ pub fn remove_rustc_src() {
} }
fn remove_rustc_src_from_project(project: &ClippyProjectInfo) -> bool { fn remove_rustc_src_from_project(project: &ClippyProjectInfo) -> bool {
let mut cargo_content = if let Ok(content) = read_project_file(project.cargo_file) { let Ok(mut cargo_content) = read_project_file(project.cargo_file) else {
content
} else {
return false; return false;
}; };
let section_start = if let Some(section_start) = cargo_content.find(RUSTC_PATH_SECTION) { let Some(section_start) = cargo_content.find(RUSTC_PATH_SECTION) else {
section_start
} else {
println!( println!(
"info: dependencies could not be found in `{}` for {}, skipping file", "info: dependencies could not be found in `{}` for {}, skipping file",
project.cargo_file, project.name project.cargo_file, project.name
@ -187,9 +182,7 @@ fn remove_rustc_src_from_project(project: &ClippyProjectInfo) -> bool {
return true; return true;
}; };
let end_point = if let Some(end_point) = cargo_content.find(DEPENDENCIES_SECTION) { let Some(end_point) = cargo_content.find(DEPENDENCIES_SECTION) else {
end_point
} else {
eprintln!( eprintln!(
"error: the end of the rustc dependencies section could not be found in `{}`", "error: the end of the rustc dependencies section could not be found in `{}`",
project.cargo_file project.cargo_file

View File

@ -869,13 +869,11 @@ fn clippy_lints_src_files() -> impl Iterator<Item = (PathBuf, DirEntry)> {
macro_rules! match_tokens { macro_rules! match_tokens {
($iter:ident, $($token:ident $({$($fields:tt)*})? $(($capture:ident))?)*) => { ($iter:ident, $($token:ident $({$($fields:tt)*})? $(($capture:ident))?)*) => {
{ {
$($(let $capture =)? if let Some(LintDeclSearchResult { $(#[allow(clippy::redundant_pattern)] let Some(LintDeclSearchResult {
token_kind: TokenKind::$token $({$($fields)*})?, token_kind: TokenKind::$token $({$($fields)*})?,
content: _x, content: $($capture @)? _,
.. ..
}) = $iter.next() { }) = $iter.next() else {
_x
} else {
continue; continue;
};)* };)*
#[allow(clippy::unused_unit)] #[allow(clippy::unused_unit)]

View File

@ -339,10 +339,7 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &h
Some(id) if trait_ref.trait_def_id() == Some(id) => id, Some(id) if trait_ref.trait_def_id() == Some(id) => id,
_ => return, _ => return,
}; };
let copy_id = match cx.tcx.lang_items().copy_trait() { let Some(copy_id) = cx.tcx.lang_items().copy_trait() else { return };
Some(id) => id,
None => return,
};
let (ty_adt, ty_subs) = match *ty.kind() { let (ty_adt, ty_subs) = match *ty.kind() {
// Unions can't derive clone. // Unions can't derive clone.
ty::Adt(adt, subs) if !adt.is_union() => (adt, subs), ty::Adt(adt, subs) if !adt.is_union() => (adt, subs),

View File

@ -94,9 +94,8 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedMethods {
} else { } else {
path_def_id(cx, expr) path_def_id(cx, expr)
}; };
let def_id = match uncalled_path.or_else(|| fn_def_id(cx, expr)) { let Some(def_id) = uncalled_path.or_else(|| fn_def_id(cx, expr)) else {
Some(def_id) => def_id, return
None => return,
}; };
let conf = match self.disallowed.get(&def_id) { let conf = match self.disallowed.get(&def_id) {
Some(&index) => &self.conf_disallowed[index], Some(&index) => &self.conf_disallowed[index],

View File

@ -65,28 +65,24 @@ declare_lint_pass!(HashMapPass => [MAP_ENTRY]);
impl<'tcx> LateLintPass<'tcx> for HashMapPass { impl<'tcx> LateLintPass<'tcx> for HashMapPass {
#[expect(clippy::too_many_lines)] #[expect(clippy::too_many_lines)]
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
let (cond_expr, then_expr, else_expr) = match higher::If::hir(expr) { let Some(higher::If { cond: cond_expr, then: then_expr, r#else: else_expr }) = higher::If::hir(expr) else {
Some(higher::If { cond, then, r#else }) => (cond, then, r#else), return
_ => return,
}; };
let (map_ty, contains_expr) = match try_parse_contains(cx, cond_expr) { let Some((map_ty, contains_expr)) = try_parse_contains(cx, cond_expr) else {
Some(x) => x, return
None => return,
}; };
let then_search = match find_insert_calls(cx, &contains_expr, then_expr) { let Some(then_search) = find_insert_calls(cx, &contains_expr, then_expr) else {
Some(x) => x, return
None => return,
}; };
let mut app = Applicability::MachineApplicable; let mut app = Applicability::MachineApplicable;
let map_str = snippet_with_context(cx, contains_expr.map.span, contains_expr.call_ctxt, "..", &mut app).0; let map_str = snippet_with_context(cx, contains_expr.map.span, contains_expr.call_ctxt, "..", &mut app).0;
let key_str = snippet_with_context(cx, contains_expr.key.span, contains_expr.call_ctxt, "..", &mut app).0; let key_str = snippet_with_context(cx, contains_expr.key.span, contains_expr.call_ctxt, "..", &mut app).0;
let sugg = if let Some(else_expr) = else_expr { let sugg = if let Some(else_expr) = else_expr {
let else_search = match find_insert_calls(cx, &contains_expr, else_expr) { let Some(else_search) = find_insert_calls(cx, &contains_expr, else_expr) else {
Some(search) => search, return;
None => return,
}; };
if then_search.edits.is_empty() && else_search.edits.is_empty() { if then_search.edits.is_empty() && else_search.edits.is_empty() {

View File

@ -213,9 +213,8 @@ fn check_sig<'tcx>(cx: &LateContext<'tcx>, closure_ty: Ty<'tcx>, call_ty: Ty<'tc
if !closure_ty.has_late_bound_regions() { if !closure_ty.has_late_bound_regions() {
return true; return true;
} }
let substs = match closure_ty.kind() { let ty::Closure(_, substs) = closure_ty.kind() else {
ty::Closure(_, substs) => substs, return false;
_ => return false,
}; };
let closure_sig = cx.tcx.signature_unclosure(substs.as_closure().sig(), Unsafety::Normal); let closure_sig = cx.tcx.signature_unclosure(substs.as_closure().sig(), Unsafety::Normal);
cx.tcx.erase_late_bound_regions(closure_sig) == cx.tcx.erase_late_bound_regions(call_sig) cx.tcx.erase_late_bound_regions(closure_sig) == cx.tcx.erase_late_bound_regions(call_sig)

View File

@ -22,9 +22,8 @@ pub(super) fn check_fn(
return; return;
} }
let code_snippet = match snippet_opt(cx, body.value.span) { let Some(code_snippet) = snippet_opt(cx, body.value.span) else {
Some(s) => s, return
_ => return,
}; };
let mut line_count: u64 = 0; let mut line_count: u64 = 0;
let mut in_comment = false; let mut in_comment = false;

View File

@ -145,9 +145,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidUpcastComparisons {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if let ExprKind::Binary(ref cmp, lhs, rhs) = expr.kind { if let ExprKind::Binary(ref cmp, lhs, rhs) = expr.kind {
let normalized = comparisons::normalize_comparison(cmp.node, lhs, rhs); let normalized = comparisons::normalize_comparison(cmp.node, lhs, rhs);
let (rel, normalized_lhs, normalized_rhs) = if let Some(val) = normalized { let Some((rel, normalized_lhs, normalized_rhs)) = normalized else {
val
} else {
return; return;
}; };

View File

@ -124,9 +124,8 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
} }
if let ItemKind::Enum(ref def, _) = item.kind { if let ItemKind::Enum(ref def, _) = item.kind {
let ty = cx.tcx.type_of(item.def_id); let ty = cx.tcx.type_of(item.def_id);
let (adt, subst) = match ty.kind() { let Adt(adt, subst) = ty.kind() else {
Adt(adt, subst) => (adt, subst), panic!("already checked whether this is an enum")
_ => panic!("already checked whether this is an enum"),
}; };
if adt.variants().len() <= 1 { if adt.variants().len() <= 1 {
return; return;

View File

@ -331,9 +331,8 @@ fn needs_mutable_borrow(cx: &LateContext<'_>, iter_expr: &IterExpr, loop_expr: &
} }
if let Some(e) = get_enclosing_loop_or_multi_call_closure(cx, loop_expr) { if let Some(e) = get_enclosing_loop_or_multi_call_closure(cx, loop_expr) {
let local_id = match iter_expr.path { let Res::Local(local_id) = iter_expr.path else {
Res::Local(id) => id, return true
_ => return true,
}; };
let mut v = NestedLoopVisitor { let mut v = NestedLoopVisitor {
cx, cx,

View File

@ -60,9 +60,8 @@ where
return None; return None;
} }
let some_expr = match get_some_expr_fn(cx, some_pat, some_expr, expr_ctxt) { let Some(some_expr) = get_some_expr_fn(cx, some_pat, some_expr, expr_ctxt) else {
Some(expr) => expr, return None;
None => return None,
}; };
// These two lints will go back and forth with each other. // These two lints will go back and forth with each other.

View File

@ -221,7 +221,6 @@ fn iter_matching_struct_fields<'a>(
#[expect(clippy::similar_names)] #[expect(clippy::similar_names)]
impl<'a> NormalizedPat<'a> { impl<'a> NormalizedPat<'a> {
#[expect(clippy::too_many_lines)]
fn from_pat(cx: &LateContext<'_>, arena: &'a DroplessArena, pat: &'a Pat<'_>) -> Self { fn from_pat(cx: &LateContext<'_>, arena: &'a DroplessArena, pat: &'a Pat<'_>) -> Self {
match pat.kind { match pat.kind {
PatKind::Wild | PatKind::Binding(.., None) => Self::Wild, PatKind::Wild | PatKind::Binding(.., None) => Self::Wild,
@ -235,9 +234,8 @@ impl<'a> NormalizedPat<'a> {
Self::Struct(cx.qpath_res(path, pat.hir_id).opt_def_id(), fields) Self::Struct(cx.qpath_res(path, pat.hir_id).opt_def_id(), fields)
}, },
PatKind::TupleStruct(ref path, pats, wild_idx) => { PatKind::TupleStruct(ref path, pats, wild_idx) => {
let adt = match cx.typeck_results().pat_ty(pat).ty_adt_def() { let Some(adt) = cx.typeck_results().pat_ty(pat).ty_adt_def() else {
Some(x) => x, return Self::Wild
None => return Self::Wild,
}; };
let (var_id, variant) = if adt.is_enum() { let (var_id, variant) = if adt.is_enum() {
match cx.qpath_res(path, pat.hir_id).opt_def_id() { match cx.qpath_res(path, pat.hir_id).opt_def_id() {

View File

@ -42,9 +42,8 @@ pub(super) fn check(
fn ty_has_iter_method(cx: &LateContext<'_>, self_ref_ty: Ty<'_>) -> Option<(Symbol, &'static str)> { fn ty_has_iter_method(cx: &LateContext<'_>, self_ref_ty: Ty<'_>) -> Option<(Symbol, &'static str)> {
has_iter_method(cx, self_ref_ty).map(|ty_name| { has_iter_method(cx, self_ref_ty).map(|ty_name| {
let mutbl = match self_ref_ty.kind() { let ty::Ref(_, _, mutbl) = self_ref_ty.kind() else {
ty::Ref(_, _, mutbl) => mutbl, unreachable!()
_ => unreachable!(),
}; };
let method_name = match mutbl { let method_name = match mutbl {
hir::Mutability::Not => "iter", hir::Mutability::Not => "iter",

View File

@ -21,11 +21,7 @@ pub fn check(
return; return;
} }
let mm = if let Some(mm) = is_min_or_max(cx, unwrap_arg) { let Some(mm) = is_min_or_max(cx, unwrap_arg) else { return };
mm
} else {
return;
};
if ty.is_signed() { if ty.is_signed() {
use self::{ use self::{
@ -33,9 +29,7 @@ pub fn check(
Sign::{Neg, Pos}, Sign::{Neg, Pos},
}; };
let sign = if let Some(sign) = lit_sign(arith_rhs) { let Some(sign) = lit_sign(arith_rhs) else {
sign
} else {
return; return;
}; };

View File

@ -3851,9 +3851,8 @@ impl SelfKind {
hir::Mutability::Mut => &paths::ASMUT_TRAIT, hir::Mutability::Mut => &paths::ASMUT_TRAIT,
}; };
let trait_def_id = match get_trait_def_id(cx, trait_path) { let Some(trait_def_id) = get_trait_def_id(cx, trait_path) else {
Some(did) => did, return false
None => return false,
}; };
implements_trait(cx, ty, trait_def_id, &[parent_ty.into()]) implements_trait(cx, ty, trait_def_id, &[parent_ty.into()])
} }

View File

@ -289,9 +289,7 @@ fn parse_iter_usage<'tcx>(
) -> Option<IterUsage> { ) -> Option<IterUsage> {
let (kind, span) = match iter.next() { let (kind, span) = match iter.next() {
Some((_, Node::Expr(e))) if e.span.ctxt() == ctxt => { Some((_, Node::Expr(e))) if e.span.ctxt() == ctxt => {
let (name, args) = if let ExprKind::MethodCall(name, _, [args @ ..], _) = e.kind { let ExprKind::MethodCall(name, _, [args @ ..], _) = e.kind else {
(name, args)
} else {
return None; return None;
}; };
let did = cx.typeck_results().type_dependent_def_id(e.hir_id)?; let did = cx.typeck_results().type_dependent_def_id(e.hir_id)?;

View File

@ -6,9 +6,7 @@ use rustc_lint::EarlyContext;
use super::{SEPARATED_LITERAL_SUFFIX, UNSEPARATED_LITERAL_SUFFIX}; use super::{SEPARATED_LITERAL_SUFFIX, UNSEPARATED_LITERAL_SUFFIX};
pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, lit_snip: &str, suffix: &str, sugg_type: &str) { pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, lit_snip: &str, suffix: &str, sugg_type: &str) {
let maybe_last_sep_idx = if let Some(val) = lit_snip.len().checked_sub(suffix.len() + 1) { let Some(maybe_last_sep_idx) = lit_snip.len().checked_sub(suffix.len() + 1) else {
val
} else {
return; // It's useless so shouldn't lint. return; // It's useless so shouldn't lint.
}; };
// Do not lint when literal is unsuffixed. // Do not lint when literal is unsuffixed.

View File

@ -5,9 +5,7 @@ use rustc_lint::EarlyContext;
use super::MIXED_CASE_HEX_LITERALS; use super::MIXED_CASE_HEX_LITERALS;
pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, suffix: &str, lit_snip: &str) { pub(super) fn check(cx: &EarlyContext<'_>, lit: &Lit, suffix: &str, lit_snip: &str) {
let maybe_last_sep_idx = if let Some(val) = lit_snip.len().checked_sub(suffix.len() + 1) { let Some(maybe_last_sep_idx) = lit_snip.len().checked_sub(suffix.len() + 1) else {
val
} else {
return; // It's useless so shouldn't lint. return; // It's useless so shouldn't lint.
}; };
if maybe_last_sep_idx <= 2 { if maybe_last_sep_idx <= 2 {

View File

@ -70,9 +70,8 @@ impl<'tcx> LateLintPass<'tcx> for TypeParamMismatch {
// find the type that the Impl is for // find the type that the Impl is for
// only lint on struct/enum/union for now // only lint on struct/enum/union for now
let defid = match path.res { let Res::Def(DefKind::Struct | DefKind::Enum | DefKind::Union, defid) = path.res else {
Res::Def(DefKind::Struct | DefKind::Enum | DefKind::Union, defid) => defid, return
_ => return,
}; };
// get the names of the generic parameters in the type // get the names of the generic parameters in the type

View File

@ -190,10 +190,7 @@ fn check_for_unsequenced_reads(vis: &mut ReadVisitor<'_, '_>) {
if parent_id == cur_id { if parent_id == cur_id {
break; break;
} }
let parent_node = match map.find(parent_id) { let Some(parent_node) = map.find(parent_id) else { break };
Some(parent) => parent,
None => break,
};
let stop_early = match parent_node { let stop_early = match parent_node {
Node::Expr(expr) => check_expr(vis, expr), Node::Expr(expr) => check_expr(vis, expr),

View File

@ -49,9 +49,8 @@ declare_lint_pass!(NeedlessForEach => [NEEDLESS_FOR_EACH]);
impl<'tcx> LateLintPass<'tcx> for NeedlessForEach { impl<'tcx> LateLintPass<'tcx> for NeedlessForEach {
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) { fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
let expr = match stmt.kind { let (StmtKind::Expr(expr) | StmtKind::Semi(expr)) = stmt.kind else {
StmtKind::Expr(expr) | StmtKind::Semi(expr) => expr, return
_ => return,
}; };
if_chain! { if_chain! {

View File

@ -357,9 +357,8 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
} }
// Make sure it is a const item. // Make sure it is a const item.
let item_def_id = match cx.qpath_res(qpath, expr.hir_id) { let Res::Def(DefKind::Const | DefKind::AssocConst, item_def_id) = cx.qpath_res(qpath, expr.hir_id) else {
Res::Def(DefKind::Const | DefKind::AssocConst, did) => did, return
_ => return,
}; };
// Climb up to resolve any field access and explicit referencing. // Climb up to resolve any field access and explicit referencing.

View File

@ -55,9 +55,8 @@ impl<'tcx> LateLintPass<'tcx> for NonOctalUnixPermissions {
if let ExprKind::Lit(_) = param.kind; if let ExprKind::Lit(_) = param.kind;
then { then {
let snip = match snippet_opt(cx, param.span) { let Some(snip) = snippet_opt(cx, param.span) else {
Some(s) => s, return
_ => return,
}; };
if !snip.starts_with("0o") { if !snip.starts_with("0o") {
@ -72,16 +71,10 @@ impl<'tcx> LateLintPass<'tcx> for NonOctalUnixPermissions {
if let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id(); if let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id();
if match_def_path(cx, def_id, &paths::PERMISSIONS_FROM_MODE); if match_def_path(cx, def_id, &paths::PERMISSIONS_FROM_MODE);
if let ExprKind::Lit(_) = param.kind; if let ExprKind::Lit(_) = param.kind;
if let Some(snip) = snippet_opt(cx, param.span);
if !snip.starts_with("0o");
then { then {
let snip = match snippet_opt(cx, param.span) { show_error(cx, param);
Some(s) => s,
_ => return,
};
if !snip.starts_with("0o") {
show_error(cx, param);
}
} }
} }
}, },

View File

@ -552,9 +552,8 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args:
} }
// Check if this is local we care about // Check if this is local we care about
let args_idx = match path_to_local(e).and_then(|id| self.bindings.get(&id)) { let Some(&args_idx) = path_to_local(e).and_then(|id| self.bindings.get(&id)) else {
Some(&i) => i, return walk_expr(self, e);
None => return walk_expr(self, e),
}; };
let args = &self.args[args_idx]; let args = &self.args[args_idx];
let result = &mut self.results[args_idx]; let result = &mut self.results[args_idx];
@ -609,9 +608,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args:
} }
} }
let id = if let Some(x) = self.cx.typeck_results().type_dependent_def_id(e.hir_id) { let Some(id) = self.cx.typeck_results().type_dependent_def_id(e.hir_id) else {
x
} else {
set_skip_flag(); set_skip_flag();
return; return;
}; };

View File

@ -49,15 +49,13 @@ declare_lint_pass!(PtrOffsetWithCast => [PTR_OFFSET_WITH_CAST]);
impl<'tcx> LateLintPass<'tcx> for PtrOffsetWithCast { impl<'tcx> LateLintPass<'tcx> for PtrOffsetWithCast {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
// Check if the expressions is a ptr.offset or ptr.wrapping_offset method call // Check if the expressions is a ptr.offset or ptr.wrapping_offset method call
let (receiver_expr, arg_expr, method) = match expr_as_ptr_offset_call(cx, expr) { let Some((receiver_expr, arg_expr, method)) = expr_as_ptr_offset_call(cx, expr) else {
Some(call_arg) => call_arg, return
None => return,
}; };
// Check if the argument to the method call is a cast from usize // Check if the argument to the method call is a cast from usize
let cast_lhs_expr = match expr_as_cast_from_usize(cx, arg_expr) { let Some(cast_lhs_expr) = expr_as_cast_from_usize(cx, arg_expr) else {
Some(cast_lhs_expr) => cast_lhs_expr, return
None => return,
}; };
let msg = format!("use of `{method}` with a `usize` casted to an `isize`"); let msg = format!("use of `{method}` with a `usize` casted to an `isize`");

View File

@ -106,10 +106,7 @@ impl_lint_pass!(Shadow => [SHADOW_SAME, SHADOW_REUSE, SHADOW_UNRELATED]);
impl<'tcx> LateLintPass<'tcx> for Shadow { impl<'tcx> LateLintPass<'tcx> for Shadow {
fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) { fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>) {
let (id, ident) = match pat.kind { let PatKind::Binding(_, id, ident, _) = pat.kind else { return };
PatKind::Binding(_, hir_id, ident, _) => (hir_id, ident),
_ => return,
};
if pat.span.desugaring_kind().is_some() { if pat.span.desugaring_kind().is_some() {
return; return;

View File

@ -26,10 +26,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
if !cx.tcx.is_diagnostic_item(sym::Vec, id) { if !cx.tcx.is_diagnostic_item(sym::Vec, id) {
return false; return false;
} }
let qpath = match &ty.kind { let TyKind::Path(qpath) = &ty.kind else { return false };
TyKind::Path(qpath) => qpath,
_ => return false,
};
let inner_span = match qpath_generic_tys(qpath).next() { let inner_span = match qpath_generic_tys(qpath).next() {
Some(ty) => ty.span, Some(ty) => ty.span,
None => return false, None => return false,
@ -65,10 +62,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
if !cx.tcx.is_diagnostic_item(sym::Vec, id) { if !cx.tcx.is_diagnostic_item(sym::Vec, id) {
return false; return false;
} }
let qpath = match &ty.kind { let TyKind::Path(qpath) = &ty.kind else { return false };
TyKind::Path(qpath) => qpath,
_ => return false,
};
let inner_span = match qpath_generic_tys(qpath).next() { let inner_span = match qpath_generic_tys(qpath).next() {
Some(ty) => ty.span, Some(ty) => ty.span,
None => return false, None => return false,

View File

@ -47,9 +47,8 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
_ => return false, _ => return false,
}; };
let inner_qpath = match &ty.kind { let TyKind::Path(inner_qpath) = &ty.kind else {
TyKind::Path(inner_qpath) => inner_qpath, return false
_ => return false,
}; };
let inner_span = match qpath_generic_tys(inner_qpath).next() { let inner_span = match qpath_generic_tys(inner_qpath).next() {
Some(ty) => { Some(ty) => {

View File

@ -163,9 +163,8 @@ fn unnest_or_patterns(pat: &mut P<Pat>) -> bool {
noop_visit_pat(p, self); noop_visit_pat(p, self);
// Don't have an or-pattern? Just quit early on. // Don't have an or-pattern? Just quit early on.
let alternatives = match &mut p.kind { let Or(alternatives) = &mut p.kind else {
Or(ps) => ps, return
_ => return,
}; };
// Collapse or-patterns directly nested in or-patterns. // Collapse or-patterns directly nested in or-patterns.

View File

@ -47,9 +47,8 @@ declare_lint_pass!(UnusedIoAmount => [UNUSED_IO_AMOUNT]);
impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount { impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount {
fn check_stmt(&mut self, cx: &LateContext<'_>, s: &hir::Stmt<'_>) { fn check_stmt(&mut self, cx: &LateContext<'_>, s: &hir::Stmt<'_>) {
let expr = match s.kind { let (hir::StmtKind::Semi(expr) | hir::StmtKind::Expr(expr)) = s.kind else {
hir::StmtKind::Semi(expr) | hir::StmtKind::Expr(expr) => expr, return
_ => return,
}; };
match expr.kind { match expr.kind {

View File

@ -55,9 +55,8 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
match e.kind { match e.kind {
ExprKind::Match(_, arms, MatchSource::TryDesugar) => { ExprKind::Match(_, arms, MatchSource::TryDesugar) => {
let e = match arms[0].body.kind { let (ExprKind::Ret(Some(e)) | ExprKind::Break(_, Some(e))) = arms[0].body.kind else {
ExprKind::Ret(Some(e)) | ExprKind::Break(_, Some(e)) => e, return
_ => return,
}; };
if let ExprKind::Call(_, [arg, ..]) = e.kind { if let ExprKind::Call(_, [arg, ..]) = e.kind {
self.try_desugar_arm.push(arg.hir_id); self.try_desugar_arm.push(arg.hir_id);

View File

@ -1402,18 +1402,12 @@ impl<'tcx> LateLintPass<'tcx> for IfChainStyle {
} else { } else {
return; return;
}; };
let then_block = match then.kind { let ExprKind::Block(then_block, _) = then.kind else { return };
ExprKind::Block(block, _) => block,
_ => return,
};
let if_chain_span = is_expn_of(expr.span, "if_chain"); let if_chain_span = is_expn_of(expr.span, "if_chain");
if !els { if !els {
check_nested_if_chains(cx, expr, then_block, if_chain_span); check_nested_if_chains(cx, expr, then_block, if_chain_span);
} }
let if_chain_span = match if_chain_span { let Some(if_chain_span) = if_chain_span else { return };
None => return,
Some(span) => span,
};
// check for `if a && b;` // check for `if a && b;`
if_chain! { if_chain! {
if let ExprKind::Binary(op, _, _) = cond.kind; if let ExprKind::Binary(op, _, _) = cond.kind;