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 on type mismatch: Index out of bounds #31964

Closed
crumblingstatue opened this issue Feb 29, 2016 · 13 comments
Closed

ICE on type mismatch: Index out of bounds #31964

crumblingstatue opened this issue Feb 29, 2016 · 13 comments
Assignees
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@crumblingstatue
Copy link
Contributor

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>

@sanxiyn sanxiyn added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Mar 1, 2016
@TimNN
Copy link
Contributor

TimNN commented Apr 15, 2016

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).

@alexcrichton alexcrichton added I-nominated regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 20, 2016
@alexcrichton
Copy link
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...

@TimNN
Copy link
Contributor

TimNN commented Apr 20, 2016

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.

@nikomatsakis
Copy link
Contributor

related to #25801

@nikomatsakis
Copy link
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.

@nikomatsakis nikomatsakis self-assigned this Apr 21, 2016
@rust-highfive rust-highfive added P-high High priority and removed I-nominated labels Apr 21, 2016
@arielb1
Copy link
Contributor

arielb1 commented Apr 21, 2016

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

@Don42
Copy link

Don42 commented May 2, 2016

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.

@nikomatsakis
Copy link
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).

@eddyb
Copy link
Member

eddyb commented May 24, 2016

@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?

@nikomatsakis
Copy link
Contributor

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

@nikomatsakis
Copy link
Contributor

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

@eddyb
Copy link
Member

eddyb commented May 24, 2016

@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.

@arielb1
Copy link
Contributor

arielb1 commented May 24, 2016

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.

arielb1 pushed a commit to arielb1/rust that referenced this issue May 24, 2016
Refactor `FnCtxt::autoderef` to use an external iterator and to not
register any obligation from the main autoderef loop, but rather to
register them after (and if) the loop successfully completes.

Fixes rust-lang#24819
Fixes rust-lang#25801
Fixes rust-lang#27631
Fixes rust-lang#31258
Fixes rust-lang#31964
Fixes rust-lang#32320
Fixes rust-lang#33515
Fixes rust-lang#33755
Manishearth added a commit to Manishearth/rust that referenced this issue May 28, 2016
refactor autoderef to avoid prematurely registering obligations

Refactor `FnCtxt::autoderef` to use an external iterator and to not
register any obligation from the main autoderef loop, but rather to
register them after (and if) the loop successfully completes.

Fixes rust-lang#24819
Fixes rust-lang#25801
Fixes rust-lang#27631
Fixes rust-lang#31258
Fixes rust-lang#31964
Fixes rust-lang#32320
Fixes rust-lang#33515
Fixes rust-lang#33755

r? @eddyb
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) ❄️ P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

9 participants