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 const generic with where clause #87964

Closed
PsychicNoodles opened this issue Aug 12, 2021 · 1 comment · Fixed by #90023
Closed

ICE const generic with where clause #87964

PsychicNoodles opened this issue Aug 12, 2021 · 1 comment · Fixed by #90023
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` F-generic_const_exprs `#![feature(generic_const_exprs)]` 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

@PsychicNoodles
Copy link

I found a compiler bug when trying out const generics on the nightly compiler. The key part here seems to be the where [(); T::LENGTH]: Sized addition as removing that allows it to build with no issues (the where clause is there so the Container struct can have a field that takes T::LENGTH as a type parameter). I also managed to replicate this in the Rust Playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=65d8aa6be2347f0b9af2e5afb6e7d5c9.

Interestingly, by adding 'static + to both the T definitions a different error message appears, although I'm not sure if they're directly related or not. When I try to add that to <details> sections it seems to break GitHub Markdown, but you can find that in this Playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=45a573b960365ffa48a56e0f246a43a8. If it would be better to open a separate issue for that I can do so as well.

Code

#![feature(const_generics)]
#![feature(const_evaluatable_checked)]

pub trait Target {
    const LENGTH: usize;
}


pub struct Container<T: Target>
where
    [(); T::LENGTH]: Sized,
{
    target: T,
}

impl<T: Target> Container<T>
where
    [(); T::LENGTH]: Sized,
{
    pub fn start(
        target: T,
    ) -> Container<T> {
        Container { target }
    }
}

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (ccffcafd5 2021-08-11)
binary: rustc
commit-hash: ccffcafd55e58f769d4b0efc0064bf65e76998e4
commit-date: 2021-08-11
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 12.0.1

Error output

error: internal compiler error: Encountered error `Unimplemented` selecting `Binder(<^0 as Target>, [Ty(Anon)])` during codegen
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/codegen.rs:68:32

error: internal compiler error: ty::ConstKind::Error constructed but no error reported.
  |
  = note: delayed at /rustc/ccffcafd55e58f769d4b0efc0064bf65e76998e4/compiler/rustc_middle/src/ty/consts.rs:184:43
Backtrace

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:1134:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/ccffcafd55e58f769d4b0efc0064bf65e76998e4/library/std/src/panicking.rs:517:5
   1: std::panicking::begin_panic_fmt
             at /rustc/ccffcafd55e58f769d4b0efc0064bf65e76998e4/library/std/src/panicking.rs:460:5
   2: rustc_errors::HandlerInner::flush_delayed
   3: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
   4: core::ptr::drop_in_place<rustc_session::parse::ParseSess>
   5: <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop
   6: core::ptr::drop_in_place<rustc_interface::interface::Compiler>
   7: rustc_span::with_source_map
   8: rustc_interface::interface::create_compiler_and_run
   9: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@PsychicNoodles PsychicNoodles added 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 Aug 12, 2021
@BoxyUwU
Copy link
Member

BoxyUwU commented Aug 12, 2021

can be fixed by writing Container::<T> { target } in fn start

@BoxyUwU BoxyUwU added A-const-generics Area: const generics (parameters and arguments) F-generic_const_exprs `#![feature(generic_const_exprs)]` F-const_generics `#![feature(const_generics)]` labels Aug 12, 2021
@bors bors closed this as completed in 1f2a26e Dec 5, 2021
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)]` F-generic_const_exprs `#![feature(generic_const_exprs)]` 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.

2 participants