Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tage64 opened this issue Dec 23, 2019 · 3 comments
Open

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

tage64 opened this issue Dec 23, 2019 · 3 comments

Comments

@tage64
Copy link

@tage64 tage64 commented Dec 23, 2019

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

@jonas-schievink

This comment has been minimized.

Copy link
Member

@jonas-schievink jonas-schievink commented Dec 23, 2019

Reproduces on nightly as well. Playground link.

@pnkfelix

This comment has been minimized.

Copy link
Member

@pnkfelix pnkfelix commented Jan 2, 2020

triage: P-high, removing nomination.

@pnkfelix pnkfelix added P-high and removed I-nominated labels Jan 2, 2020
@Centril

This comment has been minimized.

Copy link
Member

@Centril Centril commented Jan 2, 2020

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))
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.