Skip to content

ICE on type mismatch: Index out of bounds #31964

Closed

Description

@crumblingstatue

Test case:

fn main() {
    let mut buffer = Vec::new();
    std::io::stdin().read_line(&mut buffer);
}

Output:

src/main.rs:3:32: 3:43 error: mismatched types:
 expected `&mut collections::string::String`,
    found `&mut collections::vec::Vec<_>`
(expected struct `collections::string::String`,
    found struct `collections::vec::Vec`) [E0308]
src/main.rs:3     std::io::stdin().read_line(&mut buffer);
                                             ^~~~~~~~~~~
src/main.rs:3:32: 3:43 help: run `rustc --explain E0308` 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 'index out of bounds: the len is 4 but the index is 6', ../src/libcollections/vec.rs:1178
stack backtrace:
   1:     0x7f4effa18110 - sys::backtrace::tracing::imp::write::h7af3c3cfd3e65a783bv
   2:     0x7f4effa2146b - panicking::default_handler::_$u7b$$u7b$closure$u7d$$u7d$::closure.44497
   3:     0x7f4effa20fc3 - panicking::default_handler::h75ebcc0c8bcd1085rRz
   4:     0x7f4eff9e585c - sys_common::unwind::begin_unwind_inner::hcec45e84262f1855m0t
   5:     0x7f4eff9e62f8 - sys_common::unwind::begin_unwind_fmt::h62c174e37e54c321sZt
   6:     0x7f4effa15b71 - rust_begin_unwind
   7:     0x7f4effa6856f - panicking::panic_fmt::h5f920bbc722cd548lcM
   8:     0x7f4effa68752 - panicking::panic_bounds_check::hc7552cae568055c9rbM
   9:     0x7f4efcd4069f - middle::infer::InferCtxt<'a, 'tcx>::shallow_resolve::hf6ff75a42cfc2abfCiE
  10:     0x7f4efce10abb - middle::traits::fulfill::process_predicate::hba0cba8efbf8acdawyU
  11:     0x7f4efce0f7e7 - obligation_forest::ObligationForest<O, T>::process_obligations::h16997701126397106394
  12:     0x7f4efce0ae6f - middle::traits::fulfill::FulfillmentContext<'tcx>::select_where_possible::h1b112c81d6b103c5BqU
  13:     0x7f4efefa2ed1 - check::FnCtxt<'a, 'tcx>::select_obligations_where_possible::h3110f11e9a68791ajDq
  14:     0x7f4efefc9c0c - check::check_argument_types::h3e4bc8dcbdfe3e47j3q
  15:     0x7f4efefc8f24 - check::check_method_argument_types::h2b421829214fc9bfK0q
  16:     0x7f4efefdc038 - check::check_expr_with_unifier::check_method_call::h40605e88d809513emFr
  17:     0x7f4eff00523f - check::check_expr_with_unifier::h7435735517896598653
  18:     0x7f4eff018a71 - check::check_stmt::h27f273f9d63167496Vs
  19:     0x7f4efefa9303 - check::check_block_with_expected::h6ffc0ae0594a45f7TZs
  20:     0x7f4efefa0289 - check::check_fn::h2545140b5fe4a17bYPo
  21:     0x7f4efef9d99f - check::check_bare_fn::h92b85a4e7b67d57asFo
  22:     0x7f4efef98846 - check::check_item_body::hf143be9d0498177aY4o
  23:     0x7f4efef8f2fb - check::check_item_bodies::hfdadc35dd9e39914fDo
  24:     0x7f4efef86b83 - check_crate::he92b840a76d6d63cOEC
  25:     0x7f4efff43517 - driver::phase_3_run_analysis_passes::_$u7b$$u7b$closure$u7d$$u7d$::closure.28579
  26:     0x7f4efff41985 - middle::ty::context::ctxt<'tcx>::create_and_enter::h6681449678745636205
  27:     0x7f4efff3e4df - driver::phase_3_run_analysis_passes::h3690321397878926181
  28:     0x7f4efff11845 - driver::compile_input::hf5b4c0cfabf44771Hca
  29:     0x7f4efff00997 - run_compiler::h382da26f627d0d776Oc
  30:     0x7f4effefe111 - sys_common::unwind::try::try_fn::h10497329671291346377
  31:     0x7f4effa15afb - __rust_try
  32:     0x7f4effa0e0ad - sys_common::unwind::inner_try::h27915955daa5bb0coXt
  33:     0x7f4effefe960 - boxed::F.FnBox<A>::call_box::h12722420362853020748
  34:     0x7f4effa1fa39 - sys::thread::Thread::new::thread_start::h47cad50136a0a353LOy
  35:     0x7f4ef81a5423 - start_thread
  36:     0x7f4eff697cbc - clone
  37:                0x0 - <unknown>

Activity

  1. added
    I-ICE
    on Mar 1, 2016
  2. TimNN commented on Apr 15, 2016

    @TimNN
    Contributor

    Even smaller test case:

    fn main() {
        // each statement produces the same ICE
        let _: &mut String = &mut Vec::new();
        let _: &String = &Vec::new();
        let _: &() = &Vec::new();
    }

    (Edited with more examples).

  3. added
    regression-from-stable-to-beta
    T-compiler
    on Apr 20, 2016
  4. alexcrichton commented on Apr 20, 2016

    @alexcrichton
    Member

    Nominating because this seems to be coming up all over the place, I think we've gotten 3-4 separate reports about this ICE (a regression on beta).

    Note that an ICE happens on stable, but a worse ICE happens on beta/nightly...

  5. TimNN commented on Apr 20, 2016

    @TimNN
    Contributor

    To be more precise, the regression is that the actual error message about mismatched types only shows up on stable and not on beta or nightly.

  6. nikomatsakis commented on Apr 21, 2016

    @nikomatsakis
    Contributor

    related to #25801

  7. nikomatsakis commented on Apr 21, 2016

    @nikomatsakis
    Contributor

    triage: P-high

    This core issue according to @arielb1 is the problem of the OF not doing snapshotting, but method resolution assumes it does. An older fix was #26324.

  8. self-assigned this
    on Apr 21, 2016
  9. added
    P-high
    and removed on Apr 21, 2016
  10. arielb1 commented on Apr 21, 2016

    @arielb1
    Contributor

    Not method resolution, but rather coercion (autoderef in deref-coerce).

  11. Don42 commented on May 2, 2016

    @Don42

    I am running rustc 1.8.0 from debian SID and I get the same error, but
    when I set the RUST_BACKTRACE env variable, the proper 'mismatched types' message
    is shown.

  12. nikomatsakis commented on May 23, 2016

    @nikomatsakis
    Contributor

    So I tried to use the snapshotting mechanism in the ObligationGraph in a similar fashion to #26324, but it does not work since coercion executes select_where_possible. I thought -- and still sort of think? -- that we should not need to do snapshotting over such an action, but without further restructuring of the code that is clearly not the case. Certainly it'd be possible to extend the obligation graph to support full snapshots (poor @soltanmm produced a series of PRs in this direction that I didn't merge, perhaps wrongly).

  13. eddyb commented on May 24, 2016

    @eddyb
    Contributor

    @nikomatsakis I thought I fixed coercion to never use select_where_possible (AFAIK it shouldn't), were my changes reverted accidentally? Or did I miss a spot?

  14. nikomatsakis commented on May 24, 2016

    @nikomatsakis
    Contributor

    @eddyb Probably the latter. Coercion calls into autoderef which calls into lookup_method_in_trait, which calls select_where_possible.

  15. nikomatsakis commented on May 24, 2016

    @nikomatsakis
    Contributor

    It may be possible to refactor this call upward, not sure.

  16. eddyb commented on May 24, 2016

    @eddyb
    Contributor

    @nikomatsakis Oh, I had removed only the call from within autoderef itself (when it tries to resolve a type), since that was blocking the PR with unify-lub.
    I wanted to make it an error to call select_where_possible from within a snapshot but that information wasn't there and I ended up not doing it.

  17. arielb1 commented on May 24, 2016

    @arielb1
    Contributor

    I suppose we could manually call normalize(<T as Deref>::Deref) and pass the obligations around. autoderef also inserts the MethodCallee, but we should not be doing that within a snapshot too.

  18. added a commit that references this issue on May 24, 2016
    c209d44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

I-ICEP-highT-compilerregression-from-stable-to-beta

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions