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 when returning mutable reference to array with const generic length #61337

Closed
carado opened this issue May 30, 2019 · 3 comments · Fixed by #61380
Closed

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

carado opened this issue May 30, 2019 · 3 comments · Fixed by #61380
Assignees
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) A-const-generics Area: const generics (parameters and arguments) 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

@carado
Copy link

carado commented May 30, 2019

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.aaakk.us.kg-1ecc6299db9ec823/backtrace-0.3.25/src/backtrace/libunwind.rs:97
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.aaakk.us.kg-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.

@carado carado changed the title ICE when unsizing mutable reference to array with const generic length ICE when returning mutable reference to array with const generic length May 30, 2019
@Centril Centril added I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-const-generics Area: const generics (parameters and arguments) A-const-eval Area: Constant evaluation (MIR interpretation) and removed I-nominated labels May 30, 2019
@Centril
Copy link
Contributor

Centril commented May 30, 2019

cc @varkor @oli-obk @eddyb

@varkor
Copy link
Member

varkor commented May 30, 2019

@carado: ah, I was looking for a test case for this error, thanks!

@varkor
Copy link
Member

varkor commented May 30, 2019

I have a fix for this.

@varkor varkor self-assigned this May 30, 2019
Centril added a commit to Centril/rust that referenced this issue Jun 2, 2019
…eddyb

Fix some issues with `unwrap_usize` instead of `assert_usize`

Fixes rust-lang#61337.
Fixes rust-lang#61341.
Fixes rust-lang#61422.

r? @eddyb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) A-const-generics Area: const generics (parameters and arguments) 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.

3 participants