Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

[ICE] with recursive impl trait and Iterator.by_ref() #67552

Closed

Description

@tage64

The compiler panics when compiling the following code.

I tried this code:

main.rs:

fn main() {
    rec(std::iter::empty::<()>(), 0);
}

fn rec(mut it: impl Iterator, n: u32) -> usize {
    if n == 0 {
        it.count()
    } else {
        rec(it.by_ref(), n - 1)
    }
}

I ran:

$ rustc main.rs

Rustc panics:

thread 'rustc' panicked at 'assertion failed: !substs.needs_infer()', src/librustc/traits/specialize/mod.rs:122:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.39.0 (4560ea788 2019-11-04) running on x86_64-unknown-linux-gnu

Meta

$ rustc --version --verbose
rustc 1.39.0 (4560ea7 2019-11-04)
binary: rustc
commit-hash: 4560ea7
commit-date: 2019-11-04
host: x86_64-unknown-linux-gnu
release: 1.39.0
LLVM version: 9.0

Activity

  1. jonas-schievink commented on Dec 23, 2019

    @jonas-schievink
    Contributor

    Reproduces on nightly as well. Playground link.

  2. added
    A-impl-trait
    C-bug
    I-ICE
    T-compiler
    on Dec 23, 2019
  3. pnkfelix commented on Jan 2, 2020

    @pnkfelix
    Contributor

    triage: P-high, removing nomination.

  4. added
    P-high
    and removed on Jan 2, 2020
  5. Centril commented on Jan 2, 2020

    @Centril
    Contributor

    Reduced:

    fn main() {
        rec(Empty);
    }
    
    struct Empty;
    
    impl Iterator for Empty {
        type Item = ();
        fn next<'a>(&'a mut self) -> core::option::Option<()> {
            None
        }
    }
    
    fn identity<T>(x: T) -> T {
        x
    }
    
    fn rec<T>(mut it: T)
    where
        T: Iterator,
    {
        if () == () {
            T::count(it);
        } else {
            rec(identity(&mut it))
        }
    }
  6. added
    glacier
    on Jan 5, 2020
  7. self-assigned this
    on May 24, 2020
  8. added a commit that references this issue on May 30, 2020
    f96e3e2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-impl-traitC-bugI-ICEP-highT-compilerglacier

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions