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

Panic on constant index out of bounds in range expression #33287

Closed
nskinkel opened this issue Apr 30, 2016 · 1 comment
Closed

Panic on constant index out of bounds in range expression #33287

nskinkel opened this issue Apr 30, 2016 · 1 comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@nskinkel
Copy link

Summary

rustc 1.9.0-beta.1 panics when a constant index expression is out of bounds in a range expression.

Minimal Code to Reproduce

const A: [u32; 1] = [0];

fn test() {
    let range = A[1]..; // <- note range
}

Expected Behavior

Compilation failure and exit (without a panic). rustc 1.8.0 catches this properly without panicking:

src/lib.rs:4:14: 4:18 error: const index-expr is out of bounds [E0515]
src/lib.rs:4    let range = A[1]..;
                            ^~~~
src/lib.rs:4:14: 4:18 help: run `rustc --explain E0515` to see a detailed explanation
error: aborting due to previous error
Could not compile `rustc-bug`.

Actual Behavior

rustc 1.9.0-beta.1 also catches the error but then immediately panics:

src/lib.rs:4:14: 4:18 error: const index-expr is out of bounds [E0515]
src/lib.rs:4    let range = A[1]..;
                            ^~~~
src/lib.rs:4:14: 4:18 help: run `rustc --explain E0515` to see a detailed explanation
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
thread 'rustc' panicked at 'assertion failed: !is_undef(val)', ../src/librustc_trans/adt.rs:1442
note: Run with `RUST_BACKTRACE=1` for a backtrace.

error: Could not compile `rustc-bug`.

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

Meta

rustc version

rustc 1.9.0-beta.1 (37a2869af 2016-04-12)
binary: rustc
commit-hash: 37a2869afa7eb0813becaf0070874806030052df
commit-date: 2016-04-12
host: x86_64-unknown-linux-gnu
release: 1.9.0-beta.1

Backtrace

thread 'rustc' panicked at 'assertion failed: !is_undef(val)', ../src/librustc_trans/adt.rs:1442
stack backtrace:
   1:     0x7fd7dbc0b8f0 - std::sys::backtrace::tracing::imp::write::h25f26530b3b48a54
   2:     0x7fd7dbc18feb - std::panicking::default_hook::_$u7b$$u7b$closure$u7d$$u7d$::hb497e646e4148afc
   3:     0x7fd7dbc18b8c - std::panicking::default_hook::hd57825f8b5247927
   4:     0x7fd7dbbdd94f - std::sys_common::unwind::begin_unwind_inner::hf40013815c474ad4
   5:     0x7fd7dab6462f - std::sys_common::unwind::begin_unwind::h92dcc321186dc34c
   6:     0x7fd7daba4364 - rustc_trans::adt::build_const_struct::h7c2193a6829ece18
   7:     0x7fd7daba324b - rustc_trans::adt::trans_const::hef58b8dec6cea773
   8:     0x7fd7dac277e2 - rustc_trans::consts::const_expr_unadjusted::h2a808f520395dbc1
   9:     0x7fd7dac236f5 - rustc_trans::consts::const_expr::hd1077cfffb24f3fd
  10:     0x7fd7dac25d9a - rustc_trans::consts::const_expr_unadjusted::h2a808f520395dbc1
  11:     0x7fd7dac236f5 - rustc_trans::consts::const_expr::hd1077cfffb24f3fd
  12:     0x7fd7dac24bed - rustc_trans::consts::get_const_expr_as_global::h461bf6e23752d380
  13:     0x7fd7dabd2491 - rustc_trans::expr::trans_into::hec8593fa54ef6bb1
  14:     0x7fd7dac9541d - rustc_trans::_match::mk_binding_alloca::h371f10e5648554d4
  15:     0x7fd7dabb466d - rustc_trans::base::init_local::hfca9341188244db9
  16:     0x7fd7dabca274 - rustc_trans::controlflow::trans_block::h1af7b1b31248e1b6
  17:     0x7fd7dabc8ac5 - rustc_trans::base::trans_closure::h5d45bbd73c3a7a78
  18:     0x7fd7dabcaca5 - rustc_trans::base::trans_fn::h402b71919a8efd00
  19:     0x7fd7dabd52a1 - rustc_trans::base::trans_item::ha1b4ec4be38cfb98
  20:     0x7fd7dabedc9b - _<base..TransItemsWithinModVisitor<'a, 'tcx> as rustc..hir..intravisit..Visitor<'v>>::visit_item::h28deed87cec6b591
  21:     0x7fd7dabdc12b - rustc_trans::base::trans_crate::hb76ff2cab32def4b
  22:     0x7fd7dc16607f - rustc_driver::driver::phase_4_translate_to_llvm::h4ddb9e99a379fd22
  23:     0x7fd7dc16477b - rustc_driver::driver::compile_input::_$u7b$$u7b$closure$u7d$$u7d$::h055be3d7512cb25b
  24:     0x7fd7dc1610f0 - rustc_driver::driver::phase_3_run_analysis_passes::_$u7b$$u7b$closure$u7d$$u7d$::h8b22036e53339e21
  25:     0x7fd7dc15abcb - rustc::ty::context::TyCtxt::create_and_enter::h46f82c7d33538844
  26:     0x7fd7dc15767e - rustc_driver::driver::phase_3_run_analysis_passes::ha8983b62bc1b2b22
  27:     0x7fd7dc129ecf - rustc_driver::driver::compile_input::h03d180f0197cc850
  28:     0x7fd7dc110414 - rustc_driver::run_compiler::he6931cc1e4c34ecf
  29:     0x7fd7dc10d871 - std::sys_common::unwind::try::try_fn::h4268a1ea4d20bd31
  30:     0x7fd7dbc0908b - __rust_try
  31:     0x7fd7dbc0901d - std::sys_common::unwind::inner_try::h03f2e7dcfdd826c0
  32:     0x7fd7dc10e0ba - _<F as std..boxed..FnBox<A>>::call_box::h570318fe7233955a
  33:     0x7fd7dbc17184 - std::sys::thread::Thread::new::thread_start::h42a605e44c815beb
  34:     0x7fd7d462a453 - start_thread
  35:     0x7fd7db873edc - clone
  36:                0x0 - <unknown>
@apasel422 apasel422 added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jun 17, 2016
@c4rlo
Copy link
Contributor

c4rlo commented Nov 5, 2016

This was fixed. With Rust 1.12.1 and later, this is now a warning, with no panic:

warning: this expression will panic at run-time
 --> <anon>:4:17
  |
4 |     let range = A[1]..; // <- note range
  |                 ^^^^ index out of bounds: the len is 1 but the index is 1

wesleywiser added a commit to wesleywiser/rust that referenced this issue Apr 26, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this issue Apr 26, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this issue Apr 26, 2017
arielb1 pushed a commit to arielb1/rust that referenced this issue Apr 26, 2017
arielb1 pushed a commit to arielb1/rust that referenced this issue Apr 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

3 participants