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

Compiler panic constructing Box<Fn(_)> #40743

Closed
fintelia opened this issue Mar 22, 2017 · 2 comments
Closed

Compiler panic constructing Box<Fn(_)> #40743

fintelia opened this issue Mar 22, 2017 · 2 comments
Labels
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

@fintelia
Copy link
Contributor

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
@dtolnay
Copy link
Member

dtolnay commented Mar 25, 2017

This is a regression in 1.17.0-beta. Earlier versions give:

error[E0308]: mismatched types
  --> src/main.rs:17:9
   |
17 |     foo(bar);
   |         ^^^ expected concrete lifetime, found bound lifetime parameter 
   |
   = note: expected type `std::boxed::Box<for<'r> std::ops::Fn(&'r i32) + 'static>`
              found type `std::boxed::Box<std::ops::Fn(_)>`

@arielb1 arielb1 added 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 Mar 25, 2017
@arielb1
Copy link
Contributor

arielb1 commented Mar 26, 2017

Duplicate of #40000.

@arielb1 arielb1 closed this as completed Mar 26, 2017
arielb1 added a commit to arielb1/rust that referenced this issue Mar 26, 2017
The data can't be looked up from the region variable directly, because
the region variable might have been destroyed at the end of a snapshot.

Fixes rust-lang#40000.
Fixes rust-lang#40743.
bors added a commit that referenced this issue Mar 29, 2017
store a copy of the Issue32230 info within TypeError

The data can't be looked up from the region variable directly, because
the region variable might have been destroyed at the end of a snapshot.

Fixes #40000.
Fixes #40743.

beta-nominating because regression.
r? @nikomatsakis
alexcrichton pushed a commit to alexcrichton/rust that referenced this issue Apr 1, 2017
The data can't be looked up from the region variable directly, because
the region variable might have been destroyed at the end of a snapshot.

Fixes rust-lang#40000.
Fixes rust-lang#40743.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

3 participants