Change some matches!(.., .. if ..) with let-chains

This commit is contained in:
Esteban Küber 2025-12-26 20:23:50 +00:00
parent 2f1bd3f378
commit 814647f047
7 changed files with 24 additions and 16 deletions

View file

@ -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;

View file

@ -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))

View file

@ -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

View file

@ -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(());

View file

@ -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)

View file

@ -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;

View file

@ -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.