fix overflow in array length computation

This commit is contained in:
reez12g 2023-08-29 16:02:18 +09:00
parent a517049d8c
commit 6672b862c4

View File

@ -643,15 +643,15 @@ fn check_must_not_suspend_ty<'tcx>(
} }
ty::Array(ty, len) => { ty::Array(ty, len) => {
let descr_pre = &format!("{}array{} of ", data.descr_pre, plural_suffix); let descr_pre = &format!("{}array{} of ", data.descr_pre, plural_suffix);
let target_usize = len.try_eval_target_usize(fcx.tcx, fcx.param_env).unwrap_or(0) as usize;
let plural_len = target_usize.saturating_add(1);
check_must_not_suspend_ty( check_must_not_suspend_ty(
fcx, fcx,
ty, ty,
hir_id, hir_id,
SuspendCheckData { SuspendCheckData {
descr_pre, descr_pre,
plural_len: len.try_eval_target_usize(fcx.tcx, fcx.param_env).unwrap_or(0) plural_len,
as usize
+ 1,
..data ..data
}, },
) )