Skip to content

ICE with core::iter::adapters::peekable + recursion + pattern matching on peek #131342

Open
@Borgerr

Description

@Borgerr

I tried this code:

fn main() {
  let mut items = vec![1, 2, 3, 4, 5].into_iter();
  problem_thingy(&mut items);
}

fn problem_thingy(items: &mut impl Iterator<Item = u8>) {
  let mut peeker = items.peekable();
  match peeker.peek() {
    Some(_) => (),
    None => return (),
  }
  problem_thingy(&mut peeker);
}

I expected to see this happen: either continuously have the first item be "peeked" at, or return () on the final iteration after exhausting other peeks.

Instead, this happened: compiler panicked with an unbearably large error message. I believe this has to do with allocation and pointer safety with Peekable, but I could be way off.

Meta

rustc --version --verbose:

rustc 1.81.0 (eeb90cda1 2024-09-04)                                                  
binary: rustc                                                                        
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c                                
commit-date: 2024-09-04                                                              
host: x86_64-unknown-linux-gnu                                                       
release: 1.81.0                                                                      
LLVM version: 18.1.7        

Backtrace and compiler output are unbearably large for this issue, so I've attached them below.

thread 'rustc' panicked at /rust/deps/ena-0.14.3/src/snapshot_vec.rs:199:10:
index out of bounds: the len is 0 but the index is 0

bare_build.txt
backtrace_build.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions