- 
                Notifications
    
You must be signed in to change notification settings  - Fork 13.9k
 
Closed
Labels
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.Performance or correctness regression from stable to beta.
Description
This code:
fn main() {
    fn foo(x: Box<Fn(&i32)>) {}
    let bar = Box::new(|x: &i32| {}) as Box<Fn(_)>;
    foo(bar);
}Produces this internal compiler error:
$ cargo build
Compiling fn_panic2 v0.1.0 (file:///home/jonathan/tmp/fn_panic2)
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 2 but the index is 4', /checkout/src/libcollections/vec.rs:1426
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: Could not compile `fn_panic2`.
To learn more, run the command again with --verbose.
Interestingly, changing Box<Fn(_)> to Box<Fn(&_)> or Box<Fn(&i32)> causes the code compile fine (modulo unused variable warnings).
Meta
rustc --version --verbose:
rustc 1.17.0-nightly (cab4bff3d 2017-03-21)
binary: rustc
commit-hash: cab4bff3de1a61472f3c2e7752ef54b87344d1c9
commit-date: 2017-03-21
host: x86_64-unknown-linux-gnu
release: 1.17.0-nightly
LLVM version: 3.9
Backtrace:
thread 'rustc' panicked at 'index out of bounds: the len is 2 but the index is 4', /checkout/src/libcollections/vec.rs:1426
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: rustc::infer::region_inference::RegionVarBindings::var_origin
   1: rustc::infer::error_reporting::<impl rustc::infer::InferCtxt<'a, 'gcx, 'tcx>>::note_issue_32330
   2: rustc::infer::error_reporting::<impl rustc::infer::InferCtxt<'a, 'gcx, 'tcx>>::report_and_explain_type_error
   3: rustc::infer::InferCtxt::report_mismatched_types
   4: rustc_typeck::check::demand::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::demand_coerce
   5: rustc_typeck::check::FnCtxt::check_argument_types
   6: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::confirm_builtin_call
   7: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::check_call
   8: rustc_typeck::check::FnCtxt::check_expr_kind
   9: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref
  10: rustc_typeck::check::FnCtxt::check_stmt
  11: rustc_typeck::check::FnCtxt::check_block_with_expected
  12: rustc_typeck::check::FnCtxt::check_expr_kind
  13: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref
  14: rustc_typeck::check::check_fn
  15: rustc_typeck::check::typeck_tables
  16: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables<'tcx>>::try_get
  17: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables<'tcx>>::get
  18: rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::item_tables
  19: rustc_typeck::check::check_item_bodies
  20: rustc_typeck::check_crate
  21: rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}
  22: rustc_driver::driver::phase_3_run_analysis_passes
  23: rustc_driver::driver::compile_input
  24: rustc_driver::run_compiler
  25: std::panicking::try::do_call
  26: __rust_maybe_catch_panic
             at /checkout/src/libpanic_unwind/lib.rs:98
  27: <F as alloc::boxed::FnBox<A>>::call_box
  28: std::sys::imp::thread::Thread::new::thread_start
             at /checkout/src/liballoc/boxed.rs:650
             at /checkout/src/libstd/sys_common/thread.rs:21
             at /checkout/src/libstd/sys/unix/thread.rs:84
  29: start_thread
  30: __clone
Metadata
Metadata
Assignees
Labels
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.Performance or correctness regression from stable to beta.