Skip to content

for x in xs over a &[T] parameter fails MIR lowering #1197

Closed

Description

@ehartford

Spec §13 (iteration): a slice is iterable. A for over a &[T] parameter fails MIR lowering, for T = i32 and T = str alike.

fn show(xs: &[i32]):
    for x in xs: print(f"{x}")
fn main:
    let a = [1, 2]
    show(a[..])
[mir-lower-fail] kind=37 fn=show span=25..46        (WITH_MIR_AUDIT=1; kind 37 = NK_FOR)
error: MIR lowering failed for function 'show' in sl_i.w; AST codegen was removed, so this function cannot be compiled

Sema accepts it; the failure is loud but has no source diagnostic. for i in 0..xs.len(): xs[i] works.

Workaround in use: indexed loop in test/behavior/behav_c_abi_small_structs.w (#1195); restore for line in expected when fixed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions