Skip to content

ICE when coercing certain closures (with discarded arguments) to fn #40204

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
archshift opened this issue Mar 2, 2017 · 8 comments
Closed

ICE when coercing certain closures (with discarded arguments) to fn #40204

archshift opened this issue Mar 2, 2017 · 8 comments
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@archshift
Copy link
Contributor

archshift commented Mar 2, 2017

To replicate:

#![feature(closure_to_fn_coercion)]
fn main() {
    let bar: fn(&mut u32) = |_| {};
}

ICE details:

rustc 1.17.0-nightly (be760566c 2017-02-28)
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

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', /checkout/src/libcollections/vec.rs:1401
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_decl_initializer
   6: rustc_typeck::check::FnCtxt::check_decl_local
   7: rustc_typeck::check::FnCtxt::check_stmt
   8: rustc_typeck::check::FnCtxt::check_block_with_expected
   9: rustc_typeck::check::FnCtxt::check_expr_kind
  10: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref
  11: rustc_typeck::check::check_fn
  12: rustc_typeck::check::typeck_tables
  13: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables<'tcx>>::try_get
  14: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables<'tcx>>::get
  15: rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::item_tables
  16: rustc_typeck::check::check_item_bodies
  17: rustc_typeck::check_crate
  18: rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}
  19: rustc_driver::driver::phase_3_run_analysis_passes
  20: rustc_driver::driver::compile_input
  21: rustc_driver::run_compiler
  22: std::panicking::try::do_call
  23: __rust_maybe_catch_panic
             at /checkout/src/libpanic_unwind/lib.rs:98
  24: <F as alloc::boxed::FnBox<A>>::call_box
  25: std::sys::imp::thread::Thread::new::thread_start
             at /checkout/src/liballoc/boxed.rs:648
             at /checkout/src/libstd/sys_common/thread.rs:21
             at /checkout/src/libstd/sys/unix/thread.rs:84
  26: start_thread
  27: clone

ref #40025

@TimNN TimNN added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Mar 3, 2017
@dtolnay
Copy link
Member

dtolnay commented Mar 25, 2017

This looks a lot like #40000 and #40743.

@est31
Copy link
Member

est31 commented May 3, 2017

With current nightly this doesn't ICE any more, but gives an error:

rustc 1.19.0-nightly (6a5fc9eec 2017-05-02)
error[E0308]: mismatched types
 --> <anon>:3:29
  |
3 |     let bar: fn(&mut u32) = |_| {};
  |                             ^^^^^^ expected concrete lifetime, found bound lifetime parameter
  |
  = note: expected type `fn(&mut u32)`
             found type `[closure@<anon>:3:29: 3:35]`

error: aborting due to previous error

Is this a problem?

@cramertj
Copy link
Member

cramertj commented May 5, 2017

@est31 That's related to #39706, #32600, and #41078. Inference doesn't work quite right for lifetime-generic closures (e.g. any closure that takes a reference with a non-explicit lifetime as an argument).

@nikomatsakis
Copy link
Contributor

@cramertj @est31 that's actually a different bug. I would say it is #41755 -- in particular, if we were getting the expected type correctly, this inference error would go away.

@est31
Copy link
Member

est31 commented May 5, 2017

okay, but if you spell out the type annotations, the example compiles fine. Does that mean this bug is fixed?

@est31
Copy link
Member

est31 commented May 5, 2017

Okay, I've obtained a copy of the compiler that ICE'd and apparently it doesn't ICE when you spell out the type annotation. So I'd say the ICE is fixed, and only #41755 remains?

@est31
Copy link
Member

est31 commented May 9, 2017

With #41838 merged, this issue seems to be resolved. @nikomatsakis does this issue need a regression test or can it be closed?

@eddyb eddyb added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label May 9, 2017
@arielb1
Copy link
Contributor

arielb1 commented May 9, 2017

duplicate of #40000.

@arielb1 arielb1 closed this as completed May 9, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

8 participants