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 when using unboxed closures with lifetime HRTBs #19135

Closed
abonander opened this issue Nov 20, 2014 · 4 comments · Fixed by #19780
Closed

ICE when using unboxed closures with lifetime HRTBs #19135

abonander opened this issue Nov 20, 2014 · 4 comments · Fixed by #19780
Labels
A-closures Area: Closures (`|…| { … }`) A-lifetimes Area: Lifetimes / regions 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

@abonander
Copy link
Contributor

Most basic test case:

#![feature(unboxed_closures)]

#[deriving(Show)]
struct LifetimeStruct<'a>;

fn main() {
    takes_hrtb_closure(|&mut: lts| println!("{}", lts));
}

fn takes_hrtb_closure<F: for<'a>FnMut(LifetimeStruct<'a>)>(f: F) {
    f(LifetimeStruct);
}

Compiler Output:

$ RUST_BACKTRACE=1 rustc hrtb_test.rs 
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' panicked at 'assertion failed: !ty::type_needs_infer(ty)', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/librustc/middle/typeck/mod.rs:290

stack backtrace:
   1:     0x7fde72dc4a80 - rt::backtrace::imp::write::had71017ae03f24a0vVs
   2:     0x7fde72dc7b10 - failure::on_fail::he71b2ccb43241291iht
   3:     0x7fde7358c0e0 - unwind::begin_unwind_inner::he7edbf4992e36292Pad
   4:     0x7fde71b53790 - unwind::begin_unwind::h16417137682926516883
   5:     0x7fde71ecab50 - middle::typeck::write_ty_to_tcx::h1c217af62028a95brtK
   6:     0x7fde71ec62e0 - middle::typeck::check::writeback::WritebackCx<'cx, 'tcx>::visit_node_id::h0cabe78aea9d5af18n9
   7:     0x7fde71ec4410 - middle::typeck::check::writeback::WritebackCx<'cx, 'tcx>.Visitor<'v>::visit_expr::he3eee31f7078a8284c9
   8:     0x7fde71ec4410 - middle::typeck::check::writeback::WritebackCx<'cx, 'tcx>.Visitor<'v>::visit_expr::he3eee31f7078a8284c9
   9:     0x7fde71ec9e40 - visit::walk_block::h11911811437128181636
  10:     0x7fde71ec6050 - middle::typeck::check::writeback::resolve_type_vars_in_fn::h1f622545b4b2c27c978
  11:     0x7fde71f25df0 - middle::typeck::check::check_bare_fn::hd3d74fd6bc764cbdhfh
  12:     0x7fde71f21e60 - middle::typeck::check::check_item::h40f208d380d8ba92izh
  13:     0x7fde71f25bb0 - middle::typeck::check::check_item_types::hab579f21022c1d0freh
  14:     0x7fde722ff7e0 - util::common::time::h2047692826153001907
  15:     0x7fde722fe960 - middle::typeck::check_crate::h2edb3a53d123f8c0eMK
  16:     0x7fde73a81500 - driver::driver::phase_3_run_analysis_passes::ha5acf8a70ce48fbfMTR
  17:     0x7fde73a76320 - driver::driver::compile_input::h2b7fa47cad7323abwAR
  18:     0x7fde73af69f0 - driver::run_compiler::hd1dcd9c26f83ca38HyT
  19:     0x7fde73af68e0 - driver::run::closure.53542
  20:     0x7fde73913400 - task::TaskBuilder<S>::try_future::closure.38917
  21:     0x7fde739131f0 - task::TaskBuilder<S>::spawn_internal::closure.38888
  22:     0x7fde73e12b50 - task::NativeSpawner.Spawner::spawn::closure.2470
  23:     0x7fde735e4b40 - rust_try_inner
  24:     0x7fde735e4b30 - rust_try
  25:     0x7fde73589a40 - unwind::try::h074ea65506c07a5arZc
  26:     0x7fde735898d0 - task::Task::run::h7e964b829504fb5ah5b
  27:     0x7fde73e12890 - task::NativeSpawner.Spawner::spawn::closure.2396
  28:     0x7fde7358b0f0 - thread::thread_start::hd81953be3de79f59nqc
  29:     0x7fde6deab0c0 - start_thread
  30:     0x7fde73250f89 - __clone
  31:                0x0 - <unknown>

This is a boiled-down version of the problem I'm having. It's not giving them here, but in the original program where I discovered this, I did get compiler lifetime errors:

/home/austin/Rust/multipart/src/bin/multipart_server.rs:19:94: 19:101 error: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19         multipart.foreach_entry(|&mut: name, content| println!("Name: {} Content: {}", name, content));
                                                                                                                                                        ^~~~~~~
note: in expansion of format_args!
<std macros>:2:23: 2:77 note: expansion site
<std macros>:1:1: 3:2 note: in expansion of println!
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19:55: 19:103 note: expansion site
note: first, the lifetime cannot outlive lifetime ReInfer(ReSkolemized(10, BrNamed(DefId { krate: 30, node: 1704 }, "'a"(2090))))...
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19:94: 19:101 note: ...so that the reference type `&multipart::MultipartField<'a>` does not outlive the data it points at
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19         multipart.foreach_entry(|&mut: name, content| println!("Name: {} Content: {}", name, content));
                                                                                                                                                        ^~~~~~~
note: in expansion of format_args!
<std macros>:2:23: 2:77 note: expansion site
<std macros>:1:1: 3:2 note: in expansion of println!
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19:55: 19:103 note: expansion site
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19:94: 19:101 note: but, the lifetime must be valid for the expression at 19:93...
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19         multipart.foreach_entry(|&mut: name, content| println!("Name: {} Content: {}", name, content));
                                                                                                                                                        ^~~~~~~
note: in expansion of format_args!
<std macros>:2:23: 2:77 note: expansion site
<std macros>:1:1: 3:2 note: in expansion of println!
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19:55: 19:103 note: expansion site
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19:94: 19:101 note: ...so that reference is valid at the time of borrow
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19         multipart.foreach_entry(|&mut: name, content| println!("Name: {} Content: {}", name, content));
                                                                                                                                                        ^~~~~~~
note: in expansion of format_args!
<std macros>:2:23: 2:77 note: expansion site
<std macros>:1:1: 3:2 note: in expansion of println!
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19:55: 19:103 note: expansion site
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19:19: 19:103 error: cannot infer an appropriate lifetime due to conflicting requirements
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19         multipart.foreach_entry(|&mut: name, content| println!("Name: {} Content: {}", name, content));
                                                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: first, the lifetime cannot outlive lifetime ReInfer(ReSkolemized(10, BrNamed(DefId { krate: 30, node: 1704 }, "'a"(2090))))...
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19:19: 19:103 note: ...so that trait type parameters matches those specified on the impl (expected `for<'a> core::ops::FnMut<(collections::string::String, multipart::MultipartField<'a>), ()>`, found `core::ops::FnMut<(collections::string::String, multipart::MultipartField<'a>), ()>`)
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19         multipart.foreach_entry(|&mut: name, content| println!("Name: {} Content: {}", name, content));
                                                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19:94: 19:101 note: but, the lifetime must be valid for the expression at 19:93...
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19         multipart.foreach_entry(|&mut: name, content| println!("Name: {} Content: {}", name, content));
                                                                                                                                                        ^~~~~~~
note: in expansion of format_args!
<std macros>:2:23: 2:77 note: expansion site
<std macros>:1:1: 3:2 note: in expansion of println!
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19:55: 19:103 note: expansion site
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19:94: 19:101 note: ...so that type parameter instantiated with `multipart::MultipartField<'_>`, will meet its declared lifetime bounds.
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19         multipart.foreach_entry(|&mut: name, content| println!("Name: {} Content: {}", name, content));
                                                                                                                                                        ^~~~~~~
note: in expansion of format_args!
<std macros>:2:23: 2:77 note: expansion site
<std macros>:1:1: 3:2 note: in expansion of println!
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19:55: 19:103 note: expansion site
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19:94: 19:101 error: type of expression contains references that are not valid during the expression: `multipart::MultipartField<'a>`
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19         multipart.foreach_entry(|&mut: name, content| println!("Name: {} Content: {}", name, content));
                                                                                                                                                        ^~~~~~~
note: in expansion of format_args!
<std macros>:2:23: 2:77 note: expansion site
<std macros>:1:1: 3:2 note: in expansion of println!
/home/austin/Rust/multipart/src/bin/multipart_server.rs:19:55: 19:103 note: expansion site
note: type is only valid for lifetime ReInfer(ReSkolemized(10, BrNamed(DefId { krate: 30, node: 1704 }, "'a"(2090))))
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' panicked at 'assertion failed: !ty::type_needs_infer(ty)', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/librustc/middle/typeck/mod.rs:290

(Backtrace omitted because it was the same.)

ICE Location
multipart.foreach_entry() definition

This seems like a personally reasonable use case, and I believe my logic here is sound. It should work just fine with a static function or an old boxed closure, but I'd really like to make it work with unboxed closures.

@huonw huonw added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-lifetimes Area: Lifetimes / regions A-closures Area: Closures (`|…| { … }`) labels Nov 20, 2014
@abonander abonander mentioned this issue Nov 20, 2014
47 tasks
@nikomatsakis
Copy link
Contributor

cc me

@nikomatsakis
Copy link
Contributor

Hmm. Seems to work for me, rebuilding with vanilla master to double check.

@nikomatsakis
Copy link
Contributor

Yes, works for me.

@nikomatsakis nikomatsakis added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Nov 25, 2014
@nikomatsakis
Copy link
Contributor

Marking as needs-test

bors added a commit that referenced this issue Dec 18, 2014
Closes #5988.
Closes #10176.
Closes #10456.
Closes #12744.
Closes #13264.
Closes #13324.
Closes #14182.
Closes #15381.
Closes #15444.
Closes #15480.
Closes #15756.
Closes #16822.
Closes #16966.
Closes #17351.
Closes #17503.
Closes #17545.
Closes #17771.
Closes #17816.
Closes #17897.
Closes #17905.
Closes #18188.
Closes #18232.
Closes #18345.
Closes #18389.
Closes #18400.
Closes #18502.
Closes #18611.
Closes #18783.
Closes #19009.
Closes #19081.
Closes #19098.
Closes #19127.
Closes #19135.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: Closures (`|…| { … }`) A-lifetimes Area: Lifetimes / regions 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

Successfully merging a pull request may close this issue.

3 participants