@@ -342,12 +342,27 @@ pub fn access_needs_check(
342342 Some ( length)
343343}
344344
345+ /// Items returned by the [`bounds_check_iter`] iterator.
346+ #[ cfg_attr( not( feature = "msl-out" ) , allow( dead_code) ) ]
347+ pub ( crate ) struct BoundsCheck {
348+ /// The base of the [`Access`] or [`AccessIndex`] expression.
349+ ///
350+ /// [`Access`]: crate::Expression::Access
351+ /// [`AccessIndex`]: crate::Expression::AccessIndex
352+ pub base : Handle < crate :: Expression > ,
353+
354+ /// The index being accessed.
355+ pub index : GuardedIndex ,
356+
357+ /// The length of `base`.
358+ pub length : IndexableLength ,
359+ }
360+
345361/// Returns an iterator of accesses within the chain of `Access` and
346362/// `AccessIndex` expressions starting from `chain` that may need to be
347363/// bounds-checked at runtime.
348364///
349- /// They're yielded as `(base, index)` pairs, where `base` is the type that the
350- /// access expression will produce and `index` is the index being used.
365+ /// Items are yielded as [`BoundsCheck`] instances.
351366///
352367/// Accesses through a struct are omitted, since you never need a bounds check
353368/// for accessing a struct field.
@@ -359,7 +374,7 @@ pub(crate) fn bounds_check_iter<'a>(
359374 module : & ' a crate :: Module ,
360375 function : & ' a crate :: Function ,
361376 info : & ' a valid:: FunctionInfo ,
362- ) -> impl Iterator < Item = ( Handle < crate :: Expression > , GuardedIndex , IndexableLength ) > + ' a {
377+ ) -> impl Iterator < Item = BoundsCheck > + ' a {
363378 iter:: from_fn ( move || {
364379 let ( next_expr, result) = match function. expressions [ chain] {
365380 crate :: Expression :: Access { base, index } => {
@@ -384,8 +399,13 @@ pub(crate) fn bounds_check_iter<'a>(
384399 } )
385400 . flatten ( )
386401 . filter_map ( |( base, index) | {
387- access_needs_check ( base, index, module, & function. expressions , info)
388- . map ( |length| ( base, index, length) )
402+ access_needs_check ( base, index, module, & function. expressions , info) . map ( |length| {
403+ BoundsCheck {
404+ base,
405+ index,
406+ length,
407+ }
408+ } )
389409 } )
390410}
391411
0 commit comments