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

Multiple ICE when trying to compile const generic based method #62222

Closed
maplant opened this issue Jun 28, 2019 · 2 comments
Closed

Multiple ICE when trying to compile const generic based method #62222

maplant opened this issue Jun 28, 2019 · 2 comments
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@maplant
Copy link

maplant commented Jun 28, 2019

This error is extremely similar to issue #62220. I figured I would post this one here as well because it gives a lot more errors. FTR I'm not even sure this code even typechecks, but multiple ICE is a compiler error regardless.

I'm trying to compile the following code:

#[repr(transparent)]
pub struct Vector<T, const N: usize>([T; N]);

impl<T, const N: usize> Vector<T, {N}> {
    pub fn x(self) -> T {
        let mut head = MaybeUninit::<T>::uninit();
        let mut tail = MaybeUninit::<[T; N - 1]>::uninit();
        let mut from = MaybeUninit::new(self);
        let tailp: *mut T = unsafe { mem::transmute(&mut tail) };
        let fromp: *mut MaybeUninit<T> = unsafe { mem::transmute(&mut from) };
        unsafe {
            head.as_mut_ptr().write(
                fromp
                    .replace(MaybeUninit::uninit())
                    .assume_init()
            );
        }
        for i in 1..N {
            unsafe {
                tailp.add(i - 1).write(
                    fromp
                        .add(i)
                        .replace(MaybeUninit::uninit())
                        .assume_init()
                );
            }
        }
        unsafe { tail.assume_init(); } // Drop the tail
        unsafe { head.assume_init() }
    }
}

This produces the following errors:

error: internal compiler error: constant in type had an ignored error: TooGeneric
   --> src/lib.rs:246:24
    |
246 |         let mut tail = MaybeUninit::<[T; N - 1]>::uninit();
    |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: constant in type had an ignored error: TooGeneric
   --> src/lib.rs:246:24
    |
246 |         let mut tail = MaybeUninit::<[T; N - 1]>::uninit();
    |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: constant in type had an ignored error: TooGeneric
   --> src/lib.rs:248:38
    |
248 |         let tailp: *mut T = unsafe { mem::transmute(&mut tail) };
    |                                      ^^^^^^^^^^^^^^

error: internal compiler error: constant in type had an ignored error: TooGeneric
   --> src/lib.rs:267:18
    |
267 |         unsafe { tail.assume_init(); } // Drop the tail
    |                  ^^^^^^^^^^^^^^^^^^

error: internal compiler error: broken MIR in DefId(0:68 ~ aljabar[46f5]::{{impl}}[4]::x[0]) (CanonicalUserTypeAnnotation { user_ty: Canonical { max_universe: U0, variables: [CanonicalVarInfo { kind: Ty(General(U0)) }], value: TypeOf(DefId(2:1068 ~ core[d3cb]::mem[0]::maybe_uninit[0]::{{impl}}[1]::uninit[0]), UserSubsts { substs: [^0], user_self_ty: Some(UserSelfTy { impl_def_id: DefId(2:1065 ~ core[d3cb]::mem[0]::maybe_uninit[0]::{{impl}}[1]), self_ty: std::mem::MaybeUninit<[T; _]> }) }) }, span: src/lib.rs:246:24: 246:57, inferred_ty: fn() -> std::mem::MaybeUninit<[T; _]> {std::mem::MaybeUninit::<[T; _]>::uninit} }): bad user type AscribeUserType(fn() -> std::mem::MaybeUninit<[T; _]> {std::mem::MaybeUninit::<[T; _]>::uninit}, DefId(2:1068 ~ core[d3cb]::mem[0]::maybe_uninit[0]::{{impl}}[1]::uninit[0]) UserSubsts { substs: [_], user_self_ty: Some(UserSelfTy { impl_def_id: DefId(2:1065 ~ core[d3cb]::mem[0]::maybe_uninit[0]::{{impl}}[1]), self_ty: std::mem::MaybeUninit<[T; _]> }) }): NoSolution

error: internal compiler error: broken MIR in DefId(0:68 ~ aljabar[46f5]::{{impl}}[4]::x[0]) (NoSolution): could not prove WellFormed(std::mem::MaybeUninit<[T; _]>)
   --> src/lib.rs:246:13
    |
246 |         let mut tail = MaybeUninit::<[T; N - 1]>::uninit();
    |             ^^^^^^^^

error: internal compiler error: broken MIR in DefId(0:68 ~ aljabar[46f5]::{{impl}}[4]::x[0]) (NoSolution): could not prove WellFormed(&mut std::mem::MaybeUninit<[T; _]>)
   --> src/lib.rs:248:53
    |
248 |         let tailp: *mut T = unsafe { mem::transmute(&mut tail) };
    |                                                     ^^^^^^^^^

error: internal compiler error: broken MIR in DefId(0:68 ~ aljabar[46f5]::{{impl}}[4]::x[0]) (NoSolution): could not prove WellFormed(std::mem::MaybeUninit<[T; _]>)
   --> src/lib.rs:267:18
    |
267 |         unsafe { tail.assume_init(); } // Drop the tail
    |                  ^^^^

error: internal compiler error: broken MIR in DefId(0:68 ~ aljabar[46f5]::{{impl}}[4]::x[0]) (NoSolution): could not prove WellFormed([T; _])
   --> src/lib.rs:267:18
    |
267 |         unsafe { tail.assume_init(); } // Drop the tail
    |                  ^^^^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:367:17
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:47
   3: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:36
   4: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   5: std::panicking::default_hook
             at src/libstd/panicking.rs:212
   6: rustc::util::common::panic_hook
   7: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:479
   8: std::panicking::begin_panic
   9: <rustc_errors::Handler as core::ops::drop::Drop>::drop
  10: core::ptr::real_drop_in_place
  11: <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop
  12: core::ptr::real_drop_in_place
  13: rustc_interface::interface::run_compiler_in_existing_thread_pool
  14: std::thread::local::LocalKey<T>::with
  15: scoped_tls::ScopedKey<T>::set
  16: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
query stack during panic:
end of query stack

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.37.0-nightly (8ebd67e4e 2019-06-27) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden
@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 Jun 28, 2019
@hameerabbasi
Copy link
Contributor

I may be wrong, but aren't you supposed to define a base case? Otherwise there's an infinite loop. You define let mut tail = MaybeUninit::<[T; N - 1]>::uninit(); in your code, but no special case for N == 0.

@Centril Centril added requires-nightly This issue requires a nightly compiler in some way. F-const_generics `#![feature(const_generics)]` labels Aug 6, 2019
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Oct 15, 2019
@Alexendoo
Copy link
Member

Fixed by #68388

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)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants