Skip to content

ICE: 'rustc' failed at 'index out of bounds: the len is 12 but the index is 12 - triggered by number of LoC #14091

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

Closed
japaric opened this issue May 10, 2014 · 9 comments · Fixed by #18324 or #19158
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@japaric
Copy link
Member

japaric commented May 10, 2014

Believed current test case

(pnkfelix says: "if you are looking at this bug, please try to keep this test up-to-date ... potentially by checking the newest linked dupes in the comment feed below.")

// Very

// sensitive
pub struct BytePos(pub u32);

// to particular

// line numberings / offsets

fn main() {
    let x = BytePos(1);

    assert!(x, x);
}

Original Bug Filed

Script to reproduce:

fn main() {
    // if any comment line is removed, the ICE disappears
    // adding more lines keep the ICE alive
    //
    //
    //
    //
    //
    //
    //
    //
    //
    assert!(vec!(1.0), vec!(1.0))
}

Backtrace:

$ RUST_BACKTRACE=1 rustc ice.rs
<std macros>:8:12: 13:23 error: cannot apply unary operator `!` to type `std::vec::Vec<<generic float #0>>`
<std macros>:8         if !$cond {
<std macros>:9             fail!($($arg),+)
<std macros>:10         }
<std macros>:11     );
<std macros>:12 )
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug.
note: we would appreciate a bug report: http://static.rust-lang.org/doc/master/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' failed at 'index out of bounds: the len is 12 but the index is 12', /var/tmp/paludis/build/dev-lang-rust-scm/work/rust-scm/src/libsyntax/lib.rs:1
stack backtrace:
   1:     0x7f0c3dda8180 - rt::backtrace::imp::write::h706b65acfe967902xTF::v0.11.pre
   2:     0x7f0c3dd11730 - rt::unwind::begin_unwind_inner::hcc57db58853efcfdAtF::v0.11.pre
   3:     0x7f0c3dda7e10 - <unknown>
   4:     0x7f0c3dda7d30 - rust_fail_bounds_check
   5:     0x7f0c3ddb9a90 - failure::fail_bounds_check::h8ed58f060b870dd6EwF::v0.11.pre
   6:     0x7f0c3d1d80f0 - codemap::FileMap::get_line::hbf104ad3bfda6f77Drd::v0.11.pre
   7:     0x7f0c3d1d4e90 - <unknown>
   8:     0x7f0c3d1ccd40 - diagnostic::EmitterWriter.Emitter::emit::h7c42f3840a82760aQcc::v0.11.pre
   9:     0x7f0c3d1c9f90 - diagnostic::Handler::emit::h971cc5635478154dV0b::v0.11.pre
  10:     0x7f0c3d1c8ec0 - diagnostic::SpanHandler::span_err::h3735f152282993cc3Sb::v0.11.pre
  11:     0x7f0c3eadda90 - middle::typeck::infer::InferCtxt<'a>::type_error_message_str_with_expected::he1b302cd7901cc2apJq::v0.11.pre
  12:     0x7f0c3eb7f0e0 - middle::typeck::infer::InferCtxt<'a>::type_error_message::h6e536a01d806a7af7Qq::v0.11.pre
  13:     0x7f0c3eb8d9f0 - <unknown>
  14:     0x7f0c3eb8b250 - <unknown>
  15:     0x7f0c3eb8d650 - <unknown>
  16:     0x7f0c3eb7fb20 - <unknown>
  17:     0x7f0c3eb7fb20 - <unknown>
  18:     0x7f0c3eb5fd00 - middle::typeck::check::check_block_with_expected::hec61a0d86b711c5ck7c::v0.11.pre
  19:     0x7f0c3eb5af90 - <unknown>
  20:     0x7f0c3eb5ad30 - <unknown>
  21:     0x7f0c3eb53790 - middle::typeck::check::check_item::he7c19452bac809220R8::v0.11.pre
  22:     0x7f0c3eb5ab30 - middle::typeck::check::check_item_types::hca38e25e2d3c1969ek8::v0.11.pre
  23:     0x7f0c3ec9d280 - <unknown>
  24:     0x7f0c3ec9c090 - middle::typeck::check_crate::h540b9b663571145fQgw::v0.11.pre
  25:     0x7f0c3f0e8e90 - driver::driver::phase_3_run_analysis_passes::h129732fc31300f8bbei::v0.11.pre
  26:     0x7f0c3f0eef10 - driver::driver::compile_input::h36b4d97be6c65511gEi::v0.11.pre
  27:     0x7f0c3f1143c0 - run_compiler::hd111892d49d8dfe1saq::v0.11.pre
  28:     0x7f0c3f12ffb0 - <unknown>
  29:     0x7f0c3f12e860 - <unknown>
  30:     0x7f0c3f129020 - <unknown>
  31:     0x7f0c3e2ce670 - <unknown>
  32:     0x7f0c3dd9f430 - <unknown>
  33:     0x7f0c3ddc04a0 - rust_try
  34:     0x7f0c3dd9f270 - rt::task::Task::run::hd2e6ec18f16de5eeiiD::v0.11.pre
  35:     0x7f0c3e2ce440 - <unknown>
  36:     0x7f0c3dda6c60 - <unknown>
  37:     0x7f0c3ba9c000 - start_thread
  38:     0x7f0c3d9e43d9 - clone
  39:                0x0 - <unknown>

Version:

$ rustc --version
rustc 0.11-pre (1001635 2014-05-10 09:56:34 -0700)
host: x86_64-unknown-linux-gnu
@erickt
Copy link
Contributor

erickt commented May 10, 2014

I've auto-reduced this down to:

fn main() {
  //
  //
  //
  //
  //
  //
  //
  //
  //
  //
  //
  assert !(vec !(), vec !())
}

thanks creduce and @regehr!

@klutzy
Copy link
Contributor

klutzy commented May 17, 2014

macros.rs:

#![macro_escape]
macro_rules! assert_ (
    ($cond:expr, $($arg:expr)+) => (
        if !$cond { fail!($($arg),+) }
    )
) // 6 lines

main.rs:

#![feature(macro_rules)]




mod macros;
fn main(){assert_!(1,1)} // 7th line
task 'rustc' failed at 'index out of bounds: the len is 6 but the index is 6', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libsyntax/lib.rs:1

Seems like something is wrong in filemap.

@tshepang
Copy link
Member

I can't repdrouce this no more on master branch: http://is.gd/9Is9bB.

@klutzy
Copy link
Contributor

klutzy commented Aug 28, 2014

It's still present with assert!(1u, 1u);.

@klutzy
Copy link
Contributor

klutzy commented Aug 28, 2014

The core issue is: the assertion is expanded into if !1u { ... } which causes type error as expected. However, ! token is from macro (if !$cond), while 1u is from assert!(1u, 1u). They are even in different files! Here span computation goes bad, and printer tries to print wrong code area.

@sfackler
Copy link
Member

Was closed by typo

@sfackler sfackler reopened this Oct 29, 2014
@aatxe
Copy link
Member

aatxe commented Oct 29, 2014













fn main(){assert!(1,1);} 

This also causes the issue. I believe this is the simplest case that causes it. Any fewer new lines and it stops occurring. The text is on the 13th line. You can confirm that the offset in the line doesn't matter by putting the assert! on a newline and deleting one of the new lines before the fn main().

@Siosm
Copy link
Contributor

Siosm commented Nov 4, 2014

It looks like I'm affected by this one too.
Here is a non minimal test case: https://github.com/Siosm/repoman
On Arch Linux:
rustc 0.13.0-nightly (b87619e 2014-11-02 23:27:10 +0000)
binary: rustc
commit-hash: b87619e
commit-date: 2014-11-02 23:27:10 +0000
host: x86_64-unknown-linux-gnu
release: 0.13.0-nightly
Full backtrace:

$ RUST_BACKTRACE=1 cargo test
   Compiling repoman v0.0.1 (file:///home/tim/projects/perso/rust/repoman)
/home/tim/projects/perso/rust/repoman/src/package.rs:47:9: 50:6 error: mismatched types: expected `core::option::Option<package::Package>`, found `()` (expected enum core::option::Option, found ())
/home/tim/projects/perso/rust/repoman/src/package.rs:47         for i in s.graphemes(true).rev() {
/home/tim/projects/perso/rust/repoman/src/package.rs:48             // if 
/home/tim/projects/perso/rust/repoman/src/package.rs:49         }
/home/tim/projects/perso/rust/repoman/src/package.rs:50     }
/home/tim/projects/perso/rust/repoman/src/package.rs:67:29: 67:71 error: mismatched types: expected `package::Package`, found `core::option::Option<_>` (expected struct package::Package, found enum core::option::Option)
/home/tim/projects/perso/rust/repoman/src/package.rs:67     let package1: Package = from_str("lnav-0.5.1-1-x86_64.pkg.tar.xz");
                                                                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<std macros>:8:12: 69:21 error: cannot apply unary operator `!` to type `package::Package`
<std macros>:8         if !$cond {
<std macros>:9             panic!($($arg),+)
<std macros>:10         }
<std macros>:11     );
<std macros>:12 )
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' panicked at 'index out of bounds: the len is 12 but the index is 12', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libsyntax/codemap.rs:296

stack backtrace:
   1:     0x7f8d8c6a0db0 - rt::backtrace::imp::write::hfcc56047c8677681dcq
   2:     0x7f8d8c6a3eb0 - failure::on_fail::h56735b7b61c170bezxq
   3:     0x7f8d8ce35b00 - unwind::begin_unwind_inner::h7023b6652e7e5a93ZSd
   4:     0x7f8d8ce35750 - unwind::begin_unwind_fmt::h0e9ac2335b083bc1rQd
   5:     0x7f8d8ce35710 - rust_begin_unwind
   6:     0x7f8d8ce80f60 - panicking::panic_fmt::hdece59d38ae06313V6j
   7:     0x7f8d8ce80db0 - panicking::panic_bounds_check::h8e39cee29604d35eu5j
   8:     0x7f8d8b138ce0 - codemap::FileMap::get_line::hd58d1686dbf46629ffF
   9:     0x7f8d8b166a40 - diagnostic::emit::h12ba7a29b479ec9aaEG
  10:     0x7f8d8b163ca0 - diagnostic::EmitterWriter.Emitter::emit::h4f79bd6e9eeee7ecZzG
  11:     0x7f8d8b162500 - diagnostic::Handler::emit::hdd43971400185998qiG
  12:     0x7f8d8b135570 - diagnostic::SpanHandler::span_err::h65e13d2c8ffec314q6F
  13:     0x7f8d8d831610 - middle::typeck::infer::InferCtxt<'a, 'tcx>::type_error_message_str_with_expected::he148908c47756db1JJh
  14:     0x7f8d8d7667a0 - middle::typeck::infer::InferCtxt<'a, 'tcx>::type_error_message::hc03252dd89bc3f86VOh
  15:     0x7f8d8d7952e0 - middle::typeck::check::check_expr_with_unifier::check_user_unop::closure.133104
  16:     0x7f8d8d7947b0 - middle::typeck::check::check_expr_with_unifier::lookup_op_method::h925b57359fc7c14cKeZ
  17:     0x7f8d8d776490 - middle::typeck::check::check_expr_with_unifier::check_user_unop::h2153e474e2d365fbUsZ
  18:     0x7f8d8d76acd0 - middle::typeck::check::check_expr_with_unifier::hc017bd90e7abbc35l3Y
  19:     0x7f8d8d76acd0 - middle::typeck::check::check_expr_with_unifier::hc017bd90e7abbc35l3Y
  20:     0x7f8d8d7c1750 - middle::typeck::check::check_stmt::h76df15d5e1964844450
  21:     0x7f8d8d735140 - middle::typeck::check::check_block_with_expected::h7d0af6847d3f929bda1
  22:     0x7f8d8d7306f0 - middle::typeck::check::check_fn::h0cd0ebef9d88ad0bxPV
  23:     0x7f8d8d730430 - middle::typeck::check::check_bare_fn::h43a8375bf2965f78MEV
  24:     0x7f8d8d72c180 - middle::typeck::check::check_item::h2141c51e729a2e29VYV
  25:     0x7f8d8d72fbb0 - visit::Visitor::visit_mod::h11718002965167792138
  26:     0x7f8d8d72e6e0 - visit::walk_item::h1923608722162431246
  27:     0x7f8d8d72ff00 - middle::typeck::check::check_item_types::h21c4d2e562b90154WDV
  28:     0x7f8d8d232570 - util::common::time::h4350920800167001695
  29:     0x7f8d8da0bf50 - middle::typeck::check_crate::h29145ae1f68971acnmo
  30:     0x7f8d8da75b90 - driver::driver::phase_3_run_analysis_passes::h46c788750669329bn7A
  31:     0x7f8d8da70330 - driver::driver::compile_input::hb8c2da13155ca3868NA
  32:     0x7f8d8daf2a60 - driver::run_compiler::h9cc567da53bf425bMAE
  33:     0x7f8d8daf2950 - driver::run::closure.145705
  34:     0x7f8d8d24b800 - task::TaskBuilder<S>::try_future::closure.104009
  35:     0x7f8d8d24b5f0 - task::TaskBuilder<S>::spawn_internal::closure.103980
  36:     0x7f8d8e36f4e0 - task::NativeSpawner.Spawner::spawn::closure.8441
  37:     0x7f8d8ce8ec70 - rust_try_inner
  38:     0x7f8d8ce8ec60 - rust_try
  39:     0x7f8d8ce33430 - unwind::try::hfb30d5c8546abbdfjHd
  40:     0x7f8d8ce332c0 - task::Task::run::h04bab45a966850d49Mc
  41:     0x7f8d8e36f220 - task::NativeSpawner.Spawner::spawn::closure.8379
  42:     0x7f8d8ce34ad0 - thread::thread_start::h17b6830d32612a2do8c
  43:     0x7f8d8c16f250 - start_thread
  44:     0x7f8d8cb0f3b9 - clone
  45:                0x0 - <unknown>

Could not compile `repoman`.

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

Edit: I've fixed my code to use assert_eq!(), which does not trigger the bug for me.

@russmack
Copy link
Contributor

russmack commented Oct 1, 2016

I'm getting this on the rust playground rustc 1.12.0, using assert!(1, 1) and also vecs.

bors added a commit to rust-lang-ci/rust that referenced this issue Feb 13, 2023
Support sysroot library source being defined inside the workspace

With this you can now specify `cargo.sysrootSrc`. This is required for the rust workspace such that the `library` folder inside the workspace can be used as the sysroot library sources. We now also recognize if these sources are inside the workspace, tagging the as workspace members.

This does duplicate the sysroot crates still, but I don't think that causes too many problems.
flip1995 pushed a commit to flip1995/rust that referenced this issue Mar 20, 2025
)

Closes rust-lang#14020
Closes rust-lang#14290
Closes rust-lang#14091

Add checks for unstable const traits.

changelog: [`missing_const_for_fn`] fix FP on unstable const traits
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

Successfully merging a pull request may close this issue.

9 participants