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 when using a struct containing an option containing a closure #18977

Closed
IvanUkhov opened this issue Nov 15, 2014 · 3 comments
Closed
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@IvanUkhov
Copy link
Contributor

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

@IvanUkhov IvanUkhov changed the title Compiler panic when initializing a struct containing an option containing a closure Compiler panic when using a struct containing an option containing a closure Nov 15, 2014
@tomjakubowski
Copy link
Contributor

It does compile if you annotate the &str with a lifetime:

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

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

fn main() {
    let foo = Foo {
        bar: Some(|_| {}),
    };
}

@IvanUkhov
Copy link
Contributor Author

@tomjakubowski, thank you for the feedback. Yes, it is fixable, but the point is the compiler’s crash.

Regards,
Ivan

@steveklabnik steveklabnik added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jan 29, 2015
@tamird
Copy link
Contributor

tamird commented Apr 22, 2015

The original example no longer ICEs. @steveklabnik close?

lnicola pushed a commit to lnicola/rust that referenced this issue Jan 27, 2025
fix: Fix missing upmapping in trait impls completion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

4 participants