Skip to content

Internal compiler error upon deriving Debug for a generic type T with a default type argument that depends on T's lifetime parameter #29030

Closed
@tenyoung795

Description

@tenyoung795

When you attempt to derive Debug for some T<'a, U: 'a = V<'a>>, the compiler throws Type parameter out of range when substituting in region 'a.

See this playpen. Note that this works fine on beta and nightly; perhaps this would make a good regression test case.

Code

#[derive(Debug)]
struct Message<'a, P: 'a = &'a [u8]> {
    header: &'a [u8],
    payload: P,
}

Error

bug.rs:1:10: 1:15 error: internal compiler error: Type parameter out of range when substituting in region 'a (root type=Some(&'a [u8])) (space=TypeSpace, index=0)
bug.rs:1 #[derive(Debug)]
                  ^~~~~
bug.rs:1:10: 1:15 note: in expansion of #[derive_Debug]
bug.rs:1:10: 1:15 note: expansion site

Meta

rustc --version --verbose

rustc 1.3.0 (9a92aaf19 2015-09-15)
binary: rustc
commit-hash: 9a92aaf19a64603b02b4130fe52958cc12488900
commit-date: 2015-09-15
host: x86_64-unknown-linux-gnu
release: 1.3.0

Backtrace

   1:     0x7f159a1288ee - sys::backtrace::write::haf6e4e635ac76143Ivs
   2:     0x7f159a130fd5 - panicking::on_panic::ha085a58a08f78856lzx
   3:     0x7f159a0f1bce - rt::unwind::begin_unwind_inner::hc90ee27246f12475C0w
   4:     0x7f15974f276c - rt::unwind::begin_unwind::h11988818671084554314
   5:     0x7f15974f270b - diagnostic::SpanHandler::span_bug::h5e275fd43fb4dbf5X6A
   6:     0x7f159824c67b - middle::subst::SubstFolder<'a, 'tcx>.TypeFolder<'tcx>::fold_region::h6e68580d67532a3aLlQ
   7:     0x7f159817b380 - middle::subst::SubstFolder<'a, 'tcx>.TypeFolder<'tcx>::fold_ty::h7f3a3205b864f389GnQ
   8:     0x7f15981f544c - middle::infer::InferCtxt<'a, 'tcx>::type_vars_for_defs::h26a1898fc01cd534AoC
   9:     0x7f1599877f4f - check::instantiate_path::h5cf0d5a86dc81128iIs
  10:     0x7f159987a6a3 - check::_match::check_pat_struct::h8307d8311228d69cbyb
  11:     0x7f159986c6a6 - check::_match::check_pat::h0d1b284bfff635dd43a
  12:     0x7f159987b59a - check::_match::check_match::h397d7cfcf63ba1eeIsb
  13:     0x7f1599921dce - check::check_expr_with_unifier::h2356985747389952917
  14:     0x7f15998f740f - check::check_block_with_expected::he8940408a5503b54Hhs
  15:     0x7f15998d7f3a - check::check_fn::h5e5df21b0fd773ea2In
  16:     0x7f15998ee4a6 - check::check_bare_fn::h86a03fb1f3983995Hyn
  17:     0x7f15998fd14c - check::check_method_body::h13d6362f0882c3dcSao
  18:     0x7f15998ec5c3 - check::check_item_body::hf589d5189d5cb836HYn
  19:     0x7f15998ee0d4 - check::check_item_types::h489a8e890fa40e75ewn
  20:     0x7f15999adafb - check_crate::h64d9b180d61a15fblaD
  21:     0x7f159a698479 - driver::phase_3_run_analysis_passes::closure.16545
  22:     0x7f159a696d91 - middle::ty::ctxt<'tcx>::create_and_enter::h17619121053301903364
  23:     0x7f159a691c71 - driver::phase_3_run_analysis_passes::h12169435128770927116
  24:     0x7f159a675d70 - driver::compile_input::h50576600c327a48aTba
  25:     0x7f159a75c083 - run_compiler::h08c4308e3023ae95A7b
  26:     0x7f159a759afe - boxed::F.FnBox<A>::call_box::h5719507417069443679
  27:     0x7f159a759429 - rt::unwind::try::try_fn::h17024725433081724618
  28:     0x7f159a130acd - __rust_try
  29:     0x7f159a11bb77 - rt::unwind::try::inner_try::h59523aa853a0e10avWw
  30:     0x7f159a759648 - boxed::F.FnBox<A>::call_box::h16487981074879516847
  31:     0x7f159a12fc11 - sys::thread::Thread::new::thread_start::h890d1188505773c835v
  32:     0x7f159477a181 - start_thread
  33:     0x7f1599d7e47c - __clone
  34:                0x0 - <unknown>

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions