From 457f8ba447a2f2d3fc20ad2b0d779d49c9883485 Mon Sep 17 00:00:00 2001 From: dianqk Date: Sat, 24 May 2025 19:43:26 +0800 Subject: mir-opt: Do not transform non-int type in match_branches --- compiler/rustc_mir_transform/src/match_branches.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'compiler') diff --git a/compiler/rustc_mir_transform/src/match_branches.rs b/compiler/rustc_mir_transform/src/match_branches.rs index 8c0c3096899..5e511f1a418 100644 --- a/compiler/rustc_mir_transform/src/match_branches.rs +++ b/compiler/rustc_mir_transform/src/match_branches.rs @@ -284,12 +284,14 @@ fn can_cast( let v = match src_layout.ty.kind() { ty::Uint(_) => from_scalar.to_uint(src_layout.size), ty::Int(_) => from_scalar.to_int(src_layout.size) as u128, - _ => unreachable!("invalid int"), + // We can also transform the values of other integer representations (such as char), + // although this may not be practical in real-world scenarios. + _ => return false, }; let size = match *cast_ty.kind() { ty::Int(t) => Integer::from_int_ty(&tcx, t).size(), ty::Uint(t) => Integer::from_uint_ty(&tcx, t).size(), - _ => unreachable!("invalid int"), + _ => return false, }; let v = size.truncate(v); let cast_scalar = ScalarInt::try_from_uint(v, size).unwrap(); -- cgit 1.4.1-3-g733a5