Skip to content

"Broken MIR" ICE while creating array with const generic length from single value #61336

Closed
@carado

Description

@carado

A clean project with this code:

#![feature(const_generics)]

fn f<T: Copy /* ICE's just as badly without Copy */, const N: usize>(x: T) -> [T; N] {
	[x; N]
}

fn main() {}

Produces this error:

    Checking rust5 v0.1.0 (/home/carado/tmp/rust5)
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> src/main.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^

thread 'rustc' panicked at 'index out of bounds: the len is 1 but the index is 1', /rustc/37d001e4deb206ed954fde5d91690221e8306fc3/src/libcore/slice/mod.rs:2695:10
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.25/src/backtrace/libunwind.rs:97
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.25/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:197
   5: std::panicking::default_hook
             at src/libstd/panicking.rs:211
   6: rustc::util::common::panic_hook
   7: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:478
   8: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:381
   9: rust_begin_unwind
             at src/libstd/panicking.rs:308
  10: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
  11: core::panicking::panic_bounds_check
             at src/libcore/panicking.rs:61
  12: rustc_mir::borrow_check::nll::type_check::type_check
  13: rustc_mir::borrow_check::nll::compute_regions
  14: rustc_mir::borrow_check::do_mir_borrowck
  15: rustc::ty::context::GlobalCtxt::enter_local
  16: rustc_mir::borrow_check::mir_borrowck
  17: rustc::ty::query::__query_compute::mir_borrowck
  18: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::mir_borrowck>::compute
  19: rustc::dep_graph::graph::DepGraph::with_task_impl
  20: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  21: rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners
  22: rustc::util::common::time
  23: rustc_interface::passes::analysis
  24: rustc::ty::query::__query_compute::analysis
  25: rustc::dep_graph::graph::DepGraph::with_task_impl
  26: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  27: rustc::ty::context::tls::enter_global
  28: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  29: rustc_interface::passes::create_global_ctxt::{{closure}}
  30: rustc_interface::interface::run_compiler_in_existing_thread_pool
  31: std::thread::local::LocalKey<T>::with
  32: scoped_tls::ScopedKey<T>::set
  33: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
query stack during panic:
#0 [mir_borrowck] processing `f`
#1 [analysis] running analysis passes on this crate
end of query stack
error: internal compiler error: cat_expr Errd
 --> src/main.rs:3:47
  |
3 |   fn f<T: Copy, const N: usize>(x: T) -> [T; N] {
  |  _______________________________________________^
4 | |     [x; N]
5 | | }
  | |_^

error: internal compiler error: cat_expr Errd
 --> src/main.rs:4:2
  |
4 |     [x; N]
  |     ^^^^^^

error: internal compiler error: QualifyAndPromoteConstants: MIR had errors
 --> src/main.rs:3:1
  |
3 | / fn f<T: Copy, const N: usize>(x: T) -> [T; N] {
4 | |     [x; N]
5 | | }
  | |_^

error: internal compiler error: broken MIR in DefId(0:12 ~ rust5[a994]::f[0]) ("return type"): bad type [type error]
 --> src/main.rs:3:1
  |
3 | / fn f<T: Copy, const N: usize>(x: T) -> [T; N] {
4 | |     [x; N]
5 | | }
  | |_^

error: internal compiler error: broken MIR in DefId(0:12 ~ rust5[a994]::f[0]) (LocalDecl { mutability: Mut, is_user_variable: None, internal: false, is_block_tail: None, ty: [type error], user_ty: UserTypeProjections { contents: [] }, name: None, source_info: SourceInfo { span: src/main.rs:3:1: 5:2, scope: scope[0] }, visibility_scope: scope[0] }): bad type [type error]
 --> src/main.rs:3:1
  |
3 | / fn f<T: Copy, const N: usize>(x: T) -> [T; N] {
4 | |     [x; N]
5 | | }
  | |_^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:356:17
stack backtrace:
   0:     0x7eff9d7fbcfa - backtrace::backtrace::libunwind::trace::h27e79239ae132594
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.25/src/backtrace/libunwind.rs:97
   1:     0x7eff9d7fbcfa - backtrace::backtrace::trace_unsynchronized::h4d06032f1d31ea4f
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.25/src/backtrace/mod.rs:66
   2:     0x7eff9d7fbcfa - std::sys_common::backtrace::_print::h87f958e4afa789cc
                               at src/libstd/sys_common/backtrace.rs:47
   3:     0x7eff9d7fbcfa - std::sys_common::backtrace::print::h9701366bda361a82
                               at src/libstd/sys_common/backtrace.rs:36
   4:     0x7eff9d7fbcfa - std::panicking::default_hook::{{closure}}::hdeb6e1bffcdd7ad2
                               at src/libstd/panicking.rs:197
   5:     0x7eff9d7fb9fb - std::panicking::default_hook::hda59c88c4e0c7e8b
                               at src/libstd/panicking.rs:211
   6:     0x7eff9b5774c0 - rustc::util::common::panic_hook::h5c18c3a9efba48a4
   7:     0x7eff9d7fc558 - std::panicking::rust_panic_with_hook::hb309d4b58eca6d76
                               at src/libstd/panicking.rs:478
   8:     0x7eff9a1eaf04 - std::panicking::begin_panic::h4630c81ce88a3b0e
   9:     0x7eff9a205cb4 - <rustc_errors::Handler as core::ops::drop::Drop>::drop::h72e0d28e271712f9
  10:     0x7eff9db28951 - core::ptr::real_drop_in_place::h2f95b5568cdff1bc
  11:     0x7eff9db32a30 - core::ptr::real_drop_in_place::hf9944cf4ccd8b0f9
  12:     0x7eff9db34b03 - <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop::h9ab61e1d23124c65
  13:     0x7eff9dafc9ab - core::ptr::real_drop_in_place::h500d402def4b18fe
  14:     0x7eff9dafa3f6 - rustc_interface::interface::run_compiler_in_existing_thread_pool::hdc9adcf187c1c745
  15:     0x7eff9db62a45 - std::thread::local::LocalKey<T>::with::hb4d77454d8f5b39f
  16:     0x7eff9db10304 - scoped_tls::ScopedKey<T>::set::hf0af9addd0db626a
  17:     0x7eff9db25103 - syntax::with_globals::hf05470816f33fc03
  18:     0x7eff9db53d2c - std::sys_common::backtrace::__rust_begin_short_backtrace::hfd0071cd5db5cd9e
  19:     0x7eff9d80d499 - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:85
  20:     0x7eff9dadde58 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h101536dc4ddcc287
  21:     0x7eff9d7dfa9e - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h08bd7d4edd708d24
                               at /rustc/37d001e4deb206ed954fde5d91690221e8306fc3/src/liballoc/boxed.rs:746
  22:     0x7eff9d80c16f - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::he2a07dcda49e9385
                               at /rustc/37d001e4deb206ed954fde5d91690221e8306fc3/src/liballoc/boxed.rs:746
  23:     0x7eff9d80c16f - std::sys_common::thread::start_thread::h9f229612a1fc41e1
                               at src/libstd/sys_common/thread.rs:13
  24:     0x7eff9d80c16f - std::sys::unix::thread::Thread::new::thread_start::h5b2c91946063a815
                               at src/libstd/sys/unix/thread.rs:79
  25:     0x7eff9d743fa7 - start_thread
                               at /builddir/glibc-2.29/nptl/pthread_create.c:486
  26:     0x7eff9d665a1e - __GI___clone
  27:                0x0 - <unknown>
query stack during panic:
end of query stack
thread panicked while panicking. aborting.
error: Could not compile `rust5`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name rust5 src/main.rs --color always --crate-type bin --emit=dep-info,metadata -C debuginfo=2 -C metadata=a524629e5b525adf -C extra-filename=-a524629e5b525adf --out-dir /home/carado/tmp/rust5/target/debug/deps -C incremental=/home/carado/tmp/rust5/target/debug/incremental -L dependency=/home/carado/tmp/rust5/target/debug/deps` (signal: 4, SIGILL: illegal instruction)

Metadata

Metadata

Assignees

Labels

A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-const-genericsArea: const generics (parameters and arguments)A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions