Skip to content

ICE when returning mutable reference to array with const generic length #61337

Closed
@carado

Description

@carado

EDIT: Generalized the error.

A clean rust project with just this code:

#![feature(const_generics)]

fn f<T, const N: usize>(v: &mut [T; N]) -> &mut [T; N] { v }
/* note that everything works fine if `&mut` is replaced with just `&` */

fn main() {}

Produces this error:

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

error: internal compiler error: src/librustc/ty/sty.rs:2311: expected constant usize, got Const {
    ty: usize,
    val: Param(
        N/#1,
    ),
}

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:637:9
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::begin_panic
   9: rustc_errors::Handler::bug
  10: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  11: rustc::ty::context::tls::with_opt::{{closure}}
  12: rustc::ty::context::tls::with_context_opt
  13: rustc::ty::context::tls::with_opt
  14: rustc::util::bug::opt_span_bug_fmt
  15: rustc::util::bug::bug_fmt
  16: rustc::ty::sty::Const::unwrap_usize::{{closure}}
  17: <rustc_mir::transform::qualify_consts::HasMutInterior as rustc_mir::transform::qualify_consts::Qualif>::in_rvalue
  18: rustc_mir::transform::qualify_consts::Checker::assign
  19: <rustc_mir::transform::qualify_consts::QualifyAndPromoteConstants as rustc_mir::transform::MirPass>::run_pass
  20: rustc_mir::transform::run_passes::{{closure}}
  21: rustc_mir::transform::run_passes
  22: rustc_mir::transform::mir_validated
  23: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::mir_validated>::compute
  24: rustc::dep_graph::graph::DepGraph::with_task_impl
  25: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query
  26: rustc::ty::query::plumbing::force_from_dep_node
  27: rustc::dep_graph::graph::DepGraph::try_mark_previous_green
  28: rustc::dep_graph::graph::DepGraph::try_mark_green
  29: rustc::dep_graph::graph::DepGraph::try_mark_green_and_read
  30: rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners
  31: rustc::util::common::time
  32: rustc_interface::passes::analysis
  33: rustc::ty::query::__query_compute::analysis
  34: rustc::dep_graph::graph::DepGraph::with_task_impl
  35: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  36: rustc::ty::context::tls::enter_global
  37: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  38: rustc_interface::passes::create_global_ctxt::{{closure}}
  39: rustc_interface::interface::run_compiler_in_existing_thread_pool
  40: std::thread::local::LocalKey<T>::with
  41: scoped_tls::ScopedKey<T>::set
  42: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
query stack during panic:
#0 [mir_validated] processing `f`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error


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 (37d001e4d 2019-05-29) running on x86_64-unknown-linux-gnu

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

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `rust4`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Assignees

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-const-genericsArea: const generics (parameters and arguments)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