rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.99k stars 12.79k forks source link

ICE related to lifetimes #13808

Closed jmmk closed 9 years ago

jmmk commented 10 years ago

Updated code example

struct Foo {
    listener: <'a> ||: 'a
}

impl Foo {
    fn new(listener: <'a> ||: 'a) -> Foo {
        Foo {
            listener: listener
        }
    }
}

fn main() {
    let a = Foo::new();
}

Original description

I added pub listener: <'a> ||: 'a, as a field on a struct and I am passing listener: <'a> ||: 'a into the constructor and setting listener: listener. My code is horribly broken at the moment, so the error might be hard to duplicate in a normal circumstance

src/slot.rs:16:23: 16:31 error: internal compiler error: cannot relate bound region: ReLateBound(368, BrNamed(syntax::ast::DefId{krate: 0u32, node: 370u32}, a)) <= ReLateBound(613, BrNamed(syntax::ast::DefId{krate: 0u32, node: 615u32}, a))
src/slot.rs:16             listener: listener,
                                     ^~~~~~~~
note: the compiler hit an unexpected failure path. this is a bug.
note: we would appreciate a bug report: http://static.rust-lang.org/doc/master/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' failed at '~Any', /Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/libsyntax/diagnostic.rs:99
stack backtrace:
   1:        0x108bcc774 - rt::backtrace::imp::write::hb8edc46a4e54f5bdyEa::v0.11.pre
   2:        0x108b2e65e - rt::unwind::begin_unwind_inner::h4857e4963ab560a9Eea::v0.11.pre
   3:        0x1082ae925 - rt::unwind::begin_unwind::h10981348780101087386::v0.11.pre
   4:        0x1082ae8a9 - diagnostic::SpanHandler::span_bug::h7a0381da98a05456ITb::v0.11.pre
   5:        0x105f673f1 - driver::session::Session::span_bug::hf3890a8c1798bcecGqh::v0.11.pre
   6:        0x1062161c5 - middle::typeck::infer::region_inference::RegionVarBindings<'a>::make_subre
gion::h2161fa77405c0b5eVii::v0.11.pre
   7:        0x1061f8664 - middle::typeck::infer::sub::Sub<'f>.Combine::regions::h87816d6c29e2d1e2NIk
::v0.11.pre
   8:        0x1061f8969 - middle::typeck::infer::sub::Sub<'f>.Combine::contraregions::ha70e9e373bca1
82aeIk::v0.11.pre
   9:        0x10622dba8 - middle::typeck::infer::combine::Combine::closure_tys::h1515845370716737786
6::v0.11.pre
  10:        0x1061e11ee - middle::typeck::infer::sub::Sub<'f>.Combine::tys::h9e417bda90b44b91PQk::v0
.11.pre
  11:        0x1061ed578 - middle::typeck::infer::lattice::ty..t.LatticeValue::sub::h6788a62e8e532e66
1kg::v0.11.pre
  12:        0x1061ef19a - middle::typeck::infer::lattice::CombineFields<'f>.CombineFieldsLatticeMeth
ods::bnds::h11321451026438906780::v0.11.pre
  13:        0x1061ee8de - middle::typeck::infer::lattice::CombineFields<'f>.CombineFieldsLatticeMeth
ods::set_var_to_merged_bounds::h18364305293880178940::v0.11.pre
  14:        0x1061e021a - middle::typeck::infer::sub::Sub<'f>.Combine::tys::h9e417bda90b44b91PQk::v0
.11.pre
  15:        0x10623292b - middle::typeck::infer::coercion::Coerce<'f>::subtype::ha90a34c19d50317a3Ol
::v0.11.pre
  16:        0x10623127e - middle::typeck::infer::coercion::Coerce<'f>::coerce_borrowed_fn::h21eec21d
591af7e2J9l::v0.11.pre
  17:        0x106231081 - middle::typeck::infer::coercion::Coerce<'f>::tys::closure.68186
  18:        0x10622f4b1 - middle::typeck::infer::coercion::Coerce<'f>::unpack_actual_value::h423d3c0
be57f69fbCPl::v0.11.pre
  19:        0x10622edd2 - middle::typeck::infer::coercion::Coerce<'f>::tys::hfbee61e40c4d2177VHl::v0
.11.pre
  20:        0x10625630d - middle::typeck::infer::mk_coercety::closure.68856
  21:        0x106255e5c - middle::typeck::infer::InferCtxt<'a>::commit::closure.68846
  22:        0x1062550f9 - util::common::indent::h148640294178993037::v0.11.pre
  23:        0x106255cee - middle::typeck::infer::mk_coercety::closure.68842
  24:        0x1062550f9 - util::common::indent::h148640294178993037::v0.11.pre
  25:        0x1061bbc1c - middle::typeck::infer::mk_coercety::h8c3f5e59b24b1d6a3Go::v0.11.pre
  26:        0x10617f701 - middle::typeck::check::FnCtxt<'a>::mk_assignty::h73ec086633282126ZV8::v0.1
1.pre
  27:        0x10617f588 - middle::typeck::check::demand::coerce::h728f9dff6d7fdfc7SY4::v0.11.pre
  28:        0x1061c606a - middle::typeck::check::check_expr_coercable_to_type::closure.66448
  29:        0x1061bcd6e - middle::typeck::check::check_expr_with_unifier::h54f2db4c9a491156Dy9::v0.1
1.pre
  30:        0x1061d222b - middle::typeck::check::check_expr_with_unifier::check_struct_or_variant_fi
elds::h3be96966110b5d79OAa::v0.11.pre
  31:        0x1061c5940 - middle::typeck::check::check_expr_with_unifier::h54f2db4c9a491156Dy9::v0.1
1.pre
  32:        0x10619f26c - middle::typeck::check::check_block_with_expected::h03ef625794cf7320lUb::v0
.11.pre
  33:        0x10619ae49 - middle::typeck::check::check_fn::h9c2aca4017bc1637Sn7::v0.11.pre
  34:        0x10619a67a - middle::typeck::check::check_bare_fn::hbbbe27defcff6637Jd7::v0.11.pre
  35:        0x1061a38d2 - middle::typeck::check::check_method_body::h7e31fe0e72676ae4IU7::v0.11.pre
  36:        0x106192d8e - middle::typeck::check::check_item::h810810778b4049b86J7::v0.11.pre
  37:        0x1061944bd - visit::walk_item::h10033669871325854080::v0.11.pre
  38:        0x10619a420 - middle::typeck::check::check_item_types::h9d072e264d49e9741c7::v0.11.pre
  39:        0x1062cd9df - util::common::time::h14811596011449642652::v0.11.pre
  40:        0x1062cc90d - middle::typeck::check_crate::hc7ccc9d6246f2066lIu::v0.11.pre
  41:        0x1066e655d - driver::driver::phase_3_run_analysis_passes::hb484e7997e276ab1TCf::v0.11.p
re
  42:        0x1066ec5d2 - driver::driver::compile_input::h5786f561b203dba8G2f::v0.11.pre
  43:        0x1067123b2 - run_compiler::he93bc641c5699ab0xzn::v0.11.pre
  44:        0x10672622d - main_args::closure.91452
  45:        0x1067245c2 - monitor::closure.91327
  46:        0x10672010b - task::TaskBuilder::try::closure.91093
  47:        0x105eca47c - task::spawn_opts::closure.7106
  48:        0x108bc7878 - rt::task::Task::run::closure.40139
  49:        0x108bd15ec - rust_try
  50:        0x108bc76f7 - rt::task::Task::run::h149edfd1efd12195e57::v0.11.pre
  51:        0x105eca2ff - task::spawn_opts::closure.7078
  52:        0x108bcb146 - rt::thread::thread_start::he6c7e09250b70489rK8::v0.11.pre
  53:     0x7fff8e7fc899 - _pthread_body
  54:     0x7fff8e7fc72a - _pthread_struct_init

make: *** [compile] Error 101
alexcrichton commented 10 years ago

Do you have a small amount of code which reproduces the error?

jmmk commented 10 years ago
struct Foo {
    listener: <'a> ||: 'a
}

impl Foo {
    fn new(listener: <'a> ||: 'a) -> Foo {
        Foo {
            listener: listener
        }
    }
}

fn main() {
    let a = Foo::new();
}
alexcrichton commented 10 years ago

Thanks!

For future reference you probably don't want to store <'a> ||: 'a but rather ||: 'a

struct Foo<'a> {
    listener: ||: 'a
}

impl<'a> Foo<'a> {
    fn new(listener: ||: 'a) -> Foo<'a> {
        Foo { listener: listener }
    }
}

fn main() {
    let a = Foo::new(|| {});
}
alexcrichton commented 10 years ago

cc @pnkfelix and @nikomatsakis