Skip to content

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

Closed
@maplant

Description

@maplant

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/git.colasdn.top-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/git.colasdn.top-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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.F-const_generics`#![feature(const_generics)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions