Skip to content

Compiler panic when using a struct containing an option containing a closure #18977

Closed
@IvanUkhov

Description

@IvanUkhov

Hello,

The following code makes the compiler panic:

type baz<'r> = |a: &str|: 'r;

struct Foo<'a> {
    pub bar: Option<baz<'a>>,
}

fn main() {
    let foo = Foo {
        bar: Some(|_| {}), // No panic if set to `None`.
    };
}

The error is as follows:

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)', /Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/librustc/middle/typeck/mod.rs:287

The stack backtrace is as follows:

   1:        0x1121d2f3f - rt::backtrace::imp::write::hd7f84a0d118b4e9eVot
   2:        0x1121d60c7 - failure::on_fail::h9a35b44cd8edccd4KFt
   3:        0x11245e415 - unwind::begin_unwind_inner::h5bb2382486c9eb6aj1c
   4:        0x10ee973cc - unwind::begin_unwind::h5469326410716518062
   5:        0x10f351ad2 - middle::typeck::write_ty_to_tcx::h02e44d904504fae6a9o
   6:        0x10f34efc3 - middle::typeck::check::writeback::WritebackCx<'cx, 'tcx>::visit_node_id::hfc5209ecc7d2f579bMO
   7:        0x10f34c67d - middle::typeck::check::writeback::WritebackCx<'cx, 'tcx>.Visitor<'v>::visit_expr::h2d8bef8a28c38537bBO
   8:        0x10f34cc64 - middle::typeck::check::writeback::WritebackCx<'cx, 'tcx>.Visitor<'v>::visit_expr::h2d8bef8a28c38537bBO
   9:        0x10f35102e - visit::walk_block::h2012324997306219364
  10:        0x10f34de79 - middle::typeck::check::writeback::resolve_type_vars_in_fn::h6a69f57e62af9b54hwO
  11:        0x10f3a1e2a - middle::typeck::check::check_bare_fn::hf9c5939be93720b6C5V
  12:        0x10f39df6d - middle::typeck::check::check_item::hb3a2168259443e2cLpW
  13:        0x10f3a1c40 - middle::typeck::check::check_item_types::h7c1c2eed449cb7c9M4V
  14:        0x10eeb30b6 - util::common::time::h17033228965645124047
  15:        0x10f6ae15e - middle::typeck::check_crate::h89ee1085aa565dd1Grp
  16:        0x10f715fd3 - driver::driver::phase_3_run_analysis_passes::h9477d78afd732f73VaC
  17:        0x10f70ffe8 - driver::driver::compile_input::h09034ca679b6c81cGRB
  18:        0x10f79156d - driver::run_compiler::hf724a0b8aff786c1XHF
  19:        0x10f78faae - driver::run::closure.146256
  20:        0x10eecbacb - task::TaskBuilder<S>::try_future::closure.104746
  21:        0x10eecb9c3 - task::TaskBuilder<S>::spawn_internal::closure.104717
  22:        0x10ee847bd - task::NativeSpawner.Spawner::spawn::closure.2555
  23:        0x1124bca0c - rust_try_inner
  24:        0x1124bc9f6 - rust_try
  25:        0x11245bbe7 - unwind::try::he1cc0564b93828d71Pc
  26:        0x11245ba7c - task::Task::run::h57e9dcb572d5ca5e61b
  27:        0x10ee845e3 - task::NativeSpawner.Spawner::spawn::closure.2479
  28:        0x11245d2a7 - thread::thread_start::h53a0c73ff66ca2293mc
  29:     0x7fff8e8742fc - _pthread_body
  30:     0x7fff8e874279 - _pthread_body

The bug seems to be related to #14038 and #18919.

Regards,
Ivan

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions