From 814647f047e277399b6185b9e94f6096edb16a07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Fri, 26 Dec 2025 20:23:50 +0000 Subject: [PATCH] Change some `matches!(.., .. if ..)` with let-chains --- compiler/rustc_const_eval/src/check_consts/check.rs | 13 +++++++------ .../rustc_lint/src/early/diagnostics/check_cfg.rs | 2 +- compiler/rustc_lint/src/transmute.rs | 4 +++- compiler/rustc_middle/src/mir/pretty.rs | 7 +++++-- compiler/rustc_parse/src/parser/diagnostics.rs | 4 +++- compiler/rustc_parse/src/parser/mod.rs | 7 +++---- .../src/error_reporting/traits/suggestions.rs | 3 ++- 7 files changed, 24 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_const_eval/src/check_consts/check.rs b/compiler/rustc_const_eval/src/check_consts/check.rs index b06b407a6085a..3a85ca3760d20 100644 --- a/compiler/rustc_const_eval/src/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/check_consts/check.rs @@ -833,12 +833,13 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { // const-eval of `panic_display` assumes the argument is `&&str` if tcx.is_lang_item(callee, LangItem::PanicDisplay) { - match args[0].node.ty(&self.ccx.body.local_decls, tcx).kind() { - ty::Ref(_, ty, _) if matches!(ty.kind(), ty::Ref(_, ty, _) if ty.is_str()) => - {} - _ => { - self.check_op(ops::PanicNonStr); - } + if let ty::Ref(_, ty, _) = + args[0].node.ty(&self.ccx.body.local_decls, tcx).kind() + && let ty::Ref(_, ty, _) = ty.kind() + && ty.is_str() + { + } else { + self.check_op(ops::PanicNonStr); } // Allow this call, skip all the checks below. return; diff --git a/compiler/rustc_lint/src/early/diagnostics/check_cfg.rs b/compiler/rustc_lint/src/early/diagnostics/check_cfg.rs index 0c8d7523a9dc5..fab0e9e863dc5 100644 --- a/compiler/rustc_lint/src/early/diagnostics/check_cfg.rs +++ b/compiler/rustc_lint/src/early/diagnostics/check_cfg.rs @@ -70,7 +70,7 @@ fn cargo_help_sub( // `build_script_build`) to try to figure out if we are building a Cargo build script let unescaped = &inst(EscapeQuotes::No); - if matches!(&sess.opts.crate_name, Some(crate_name) if crate_name == "build_script_build") { + if let Some("build_script_build") = sess.opts.crate_name.as_deref() { lints::UnexpectedCfgCargoHelp::lint_cfg(unescaped) } else { lints::UnexpectedCfgCargoHelp::lint_cfg_and_build_rs(unescaped, &inst(EscapeQuotes::Yes)) diff --git a/compiler/rustc_lint/src/transmute.rs b/compiler/rustc_lint/src/transmute.rs index 98510eea73b8f..6bc4617eb2dcf 100644 --- a/compiler/rustc_lint/src/transmute.rs +++ b/compiler/rustc_lint/src/transmute.rs @@ -152,7 +152,9 @@ fn check_int_to_ptr_transmute<'tcx>( return; }; // bail-out if the argument is literal 0 as we have other lints for those cases - if matches!(arg.kind, hir::ExprKind::Lit(hir::Lit { node: LitKind::Int(v, _), .. }) if v == 0) { + if let hir::ExprKind::Lit(hir::Lit { node: LitKind::Int(v, _), .. }) = arg.kind + && v == 0 + { return; } // bail-out if the inner type is a ZST diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index a31f03362a3d3..ded02595563c9 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -1871,13 +1871,16 @@ fn pretty_print_const_value_tcx<'tcx>( let u8_type = tcx.types.u8; match (ct, ty.kind()) { // Byte/string slices, printed as (byte) string literals. - (_, ty::Ref(_, inner_ty, _)) if matches!(inner_ty.kind(), ty::Str) => { + (_, ty::Ref(_, inner_ty, _)) if let ty::Str = inner_ty.kind() => { if let Some(data) = ct.try_get_slice_bytes_for_diagnostics(tcx) { fmt.write_str(&format!("{:?}", String::from_utf8_lossy(data)))?; return Ok(()); } } - (_, ty::Ref(_, inner_ty, _)) if matches!(inner_ty.kind(), ty::Slice(t) if *t == u8_type) => { + (_, ty::Ref(_, inner_ty, _)) + if let ty::Slice(t) = inner_ty.kind() + && *t == u8_type => + { if let Some(data) = ct.try_get_slice_bytes_for_diagnostics(tcx) { pretty_print_byte_str(fmt, data)?; return Ok(()); diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 70ec80a508126..2fd1d146b1f61 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -761,7 +761,9 @@ impl<'a> Parser<'a> { } // Check for misspelled keywords if there are no suggestions added to the diagnostic. - if matches!(&err.suggestions, Suggestions::Enabled(list) if list.is_empty()) { + if let Suggestions::Enabled(list) = &err.suggestions + && list.is_empty() + { self.check_for_misspelled_kw(&mut err, &expected); } Err(err) diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 4dade1d012828..d6e99bc540f74 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -1203,10 +1203,9 @@ impl<'a> Parser<'a> { let mut token = Token::dummy(); while i < dist { token = cursor.next().0; - if matches!( - token.kind, - token::OpenInvisible(origin) | token::CloseInvisible(origin) if origin.skip() - ) { + if let token::OpenInvisible(origin) | token::CloseInvisible(origin) = token.kind + && origin.skip() + { continue; } i += 1; diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 511e9e85b5f60..507371425e4f6 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -4722,7 +4722,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { // slices of `element_ty` with `mutability`. let mut is_slice = |candidate: Ty<'tcx>| match *candidate.kind() { ty::RawPtr(t, m) | ty::Ref(_, t, m) => { - if matches!(*t.kind(), ty::Slice(e) if e == element_ty) + if let ty::Slice(e) = *t.kind() + && e == element_ty && m == mutability.unwrap_or(m) { // Use the candidate's mutability going forward.