Skip to content

ICE on for n in [1, 2, 3].iter() if the type of 1, 2, 3 cannot be inferred #15984

Closed
@apoelstra

Description

@apoelstra

The following program ICE's on the playpen (will update to git HEAD and check there):

fn main() {
  for n in [1, 2, 3, 4].iter() {}
}

If you remove the for loop it is better, it will say "please add a suffix to 1" or something like that. (Maybe this was fixed by the recent changes in the for loop implementation?)

Exact ICE is

anon>:17:18: 17:27 error: internal compiler error: borrow-vec associated with bad sty: &ty_err
<anon>:17         for n in [1, 2, 3].iter() { }
                           ^~~~~~~~~
note: the compiler hit an unexpected failure path. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' failed at 'Box<Any>', /build/rust-git/src/rust/src/libsyntax/ast_util.rs:784

Edit: The new for loop changes allow the above program to compile. But you can still access the bug with

fn main() {
  let x = [1, 2, 3, 4].iter();
}

which ICEs even with git HEAD. (Above I said "if you remove the for loop it doesn't crash" but evidently I was wrong.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions