Skip to content

Commit 132837a

Browse files
committed
Change some matches!(.., .. if ..) with let-chains
1 parent 04813e4 commit 132837a

File tree

7 files changed

+24
-16
lines changed

7 files changed

+24
-16
lines changed

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -833,12 +833,13 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
833833

834834
// const-eval of `panic_display` assumes the argument is `&&str`
835835
if tcx.is_lang_item(callee, LangItem::PanicDisplay) {
836-
match args[0].node.ty(&self.ccx.body.local_decls, tcx).kind() {
837-
ty::Ref(_, ty, _) if matches!(ty.kind(), ty::Ref(_, ty, _) if ty.is_str()) =>
838-
{}
839-
_ => {
840-
self.check_op(ops::PanicNonStr);
841-
}
836+
if let ty::Ref(_, ty, _) =
837+
args[0].node.ty(&self.ccx.body.local_decls, tcx).kind()
838+
&& let ty::Ref(_, ty, _) = ty.kind()
839+
&& ty.is_str()
840+
{
841+
} else {
842+
self.check_op(ops::PanicNonStr);
842843
}
843844
// Allow this call, skip all the checks below.
844845
return;

compiler/rustc_lint/src/early/diagnostics/check_cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn cargo_help_sub(
7070
// `build_script_build`) to try to figure out if we are building a Cargo build script
7171

7272
let unescaped = &inst(EscapeQuotes::No);
73-
if matches!(&sess.opts.crate_name, Some(crate_name) if crate_name == "build_script_build") {
73+
if let Some("build_script_build") = sess.opts.crate_name.as_deref() {
7474
lints::UnexpectedCfgCargoHelp::lint_cfg(unescaped)
7575
} else {
7676
lints::UnexpectedCfgCargoHelp::lint_cfg_and_build_rs(unescaped, &inst(EscapeQuotes::Yes))

compiler/rustc_lint/src/transmute.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ fn check_int_to_ptr_transmute<'tcx>(
152152
return;
153153
};
154154
// bail-out if the argument is literal 0 as we have other lints for those cases
155-
if matches!(arg.kind, hir::ExprKind::Lit(hir::Lit { node: LitKind::Int(v, _), .. }) if v == 0) {
155+
if let hir::ExprKind::Lit(hir::Lit { node: LitKind::Int(v, _), .. }) = arg.kind
156+
&& v == 0
157+
{
156158
return;
157159
}
158160
// bail-out if the inner type is a ZST

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,13 +1871,16 @@ fn pretty_print_const_value_tcx<'tcx>(
18711871
let u8_type = tcx.types.u8;
18721872
match (ct, ty.kind()) {
18731873
// Byte/string slices, printed as (byte) string literals.
1874-
(_, ty::Ref(_, inner_ty, _)) if matches!(inner_ty.kind(), ty::Str) => {
1874+
(_, ty::Ref(_, inner_ty, _)) if let ty::Str = inner_ty.kind() => {
18751875
if let Some(data) = ct.try_get_slice_bytes_for_diagnostics(tcx) {
18761876
fmt.write_str(&format!("{:?}", String::from_utf8_lossy(data)))?;
18771877
return Ok(());
18781878
}
18791879
}
1880-
(_, ty::Ref(_, inner_ty, _)) if matches!(inner_ty.kind(), ty::Slice(t) if *t == u8_type) => {
1880+
(_, ty::Ref(_, inner_ty, _))
1881+
if let ty::Slice(t) = inner_ty.kind()
1882+
&& *t == u8_type =>
1883+
{
18811884
if let Some(data) = ct.try_get_slice_bytes_for_diagnostics(tcx) {
18821885
pretty_print_byte_str(fmt, data)?;
18831886
return Ok(());

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,9 @@ impl<'a> Parser<'a> {
761761
}
762762

763763
// Check for misspelled keywords if there are no suggestions added to the diagnostic.
764-
if matches!(&err.suggestions, Suggestions::Enabled(list) if list.is_empty()) {
764+
if let Suggestions::Enabled(list) = &err.suggestions
765+
&& list.is_empty()
766+
{
765767
self.check_for_misspelled_kw(&mut err, &expected);
766768
}
767769
Err(err)

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,10 +1203,9 @@ impl<'a> Parser<'a> {
12031203
let mut token = Token::dummy();
12041204
while i < dist {
12051205
token = cursor.next().0;
1206-
if matches!(
1207-
token.kind,
1208-
token::OpenInvisible(origin) | token::CloseInvisible(origin) if origin.skip()
1209-
) {
1206+
if let token::OpenInvisible(origin) | token::CloseInvisible(origin) = token.kind
1207+
&& origin.skip()
1208+
{
12101209
continue;
12111210
}
12121211
i += 1;

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4691,7 +4691,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
46914691
// slices of `element_ty` with `mutability`.
46924692
let mut is_slice = |candidate: Ty<'tcx>| match *candidate.kind() {
46934693
ty::RawPtr(t, m) | ty::Ref(_, t, m) => {
4694-
if matches!(*t.kind(), ty::Slice(e) if e == element_ty)
4694+
if let ty::Slice(e) = *t.kind()
4695+
&& e == element_ty
46954696
&& m == mutability.unwrap_or(m)
46964697
{
46974698
// Use the candidate's mutability going forward.

0 commit comments

Comments
 (0)