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 const_generic + associated type + double return statement #64519

Closed
simon-auch opened this issue Sep 16, 2019 · 2 comments · Fixed by #64679
Closed

ICE with const_generic + associated type + double return statement #64519

simon-auch opened this issue Sep 16, 2019 · 2 comments · Fixed by #64679
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@simon-auch
Copy link

I tried this code:

#![feature(const_generics)]
#![feature(const_generic_impls_guard)]
use core::array::LengthAtMost32;

struct Foo<const D: usize> {
    state: Option<[u8;D]>,
}
impl<const D: usize> Iterator for Foo<{D}> where
    [u8;D]: LengthAtMost32,
{
    type Item = [u8; D];
    fn next(&mut self) -> Option<Self::Item> {
        return Some(self.state.unwrap().clone());
        return Some(self.state.unwrap().clone());
    }
}

I expected to see this happen:
It should build.

Instead, this happened:
rustc crashed with:
error: internal compiler error: src/librustc/infer/unify_key.rs:143: equating two const variables, both of which have known values

Possible workaround:
replace Self::Item with [u8;D].

Meta

playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=849c7ac992950ce15a2fcf075fd61828

rustc version: 1.39.0-nightly 2019-09-15 96d07e0

@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 16, 2019
@Centril Centril added the F-const_generics `#![feature(const_generics)]` label Sep 16, 2019
@mati865
Copy link
Contributor

mati865 commented Sep 17, 2019

cc @varkor: b872e63

@hellow554
Copy link
Contributor

hellow554 commented Sep 20, 2019

Also ICEs without explicit feature gate enabled :/

// #![feature(const_generics)]

trait F {
    type Item;
    fn next() -> Self::Item;
}

struct Foo<const D: usize>;
impl<const D: usize> F for Foo<{D}>
{
    type Item = [u8; D];
    fn next() -> Self::Item {
        return [0; D];
        return [0; D];
    }
}

Centril added a commit to Centril/rust that referenced this issue Sep 22, 2019
Infer consts more consistently

Moved some duplicated logic in `TypeRelation` methods into `super_combined_consts`. Before some `TypeRelation`s like `Lub` wasn't using `replace_if_possible`, meaning some inference types were staying around longer than they should be.

Fixes rust-lang#64519

r? @varkor
@bors bors closed this as completed in 78d715f Sep 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants