about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-09-11 17:03:29 +0200
committerGitHub <noreply@github.com>2023-09-11 17:03:29 +0200
commitb99af95713964eff0817d910fcc50c08a82c9aa8 (patch)
tree71025205421c6fd63bdfe284b789807f719df6ef
parent68c2f5ba0ffb6f7f0724dd62c7562daa634caaec (diff)
parent8bf075f2d00751c2910bc5ce69374efa82d8b0b9 (diff)
downloadrust-b99af95713964eff0817d910fcc50c08a82c9aa8.tar.gz
rust-b99af95713964eff0817d910fcc50c08a82c9aa8.zip
Rollup merge of #115335 - reez12g:issue-114912, r=davidtwco
fix overflow in array length computation

addressing https://github.com/rust-lang/rust/issues/114912
-rw-r--r--compiler/rustc_hir_typeck/src/generator_interior/mod.rs11
1 files changed, 4 insertions, 7 deletions
diff --git a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs
index 6a817122491..566dc09cdd2 100644
--- a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs
+++ b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs
@@ -643,17 +643,14 @@ fn check_must_not_suspend_ty<'tcx>(
         }
         ty::Array(ty, len) => {
             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(
                 fcx,
                 ty,
                 hir_id,
-                SuspendCheckData {
-                    descr_pre,
-                    plural_len: len.try_eval_target_usize(fcx.tcx, fcx.param_env).unwrap_or(0)
-                        as usize
-                        + 1,
-                    ..data
-                },
+                SuspendCheckData { descr_pre, plural_len, ..data },
             )
         }
         // If drop tracking is enabled, we want to look through references, since the referent