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 using associated type in trait bound #20220

Closed
pythonesque opened this issue Dec 25, 2014 · 13 comments
Closed

ICE using associated type in trait bound #20220

pythonesque opened this issue Dec 25, 2014 · 13 comments
Assignees
Labels
A-associated-items Area: Associated items (types, constants & functions) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@pythonesque
Copy link
Contributor

It actually happens even if you take out the type T but I figured that would be too confusing of a testcase.

#![feature(associated_types)]

pub trait Foo {
    type T;
    type S: Bar<Self::T>;
}

pub trait Bar<T> {}
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
thread 'rustc' panicked at 'no entry found for key', /Users/rustbuild/src/rust-buildbot/slave/nightly-mac/build/src/libcore/option.rs:329

stack backtrace:
   1:        0x1078c7c38 - sys::backtrace::write::h329291c3ffa2342c0Jt
   2:        0x1078e8a03 - failure::on_fail::h17e4ace9633d727be0z
   3:        0x107854c3a - rt::unwind::begin_unwind_inner::h190be063817ae06eFHz
   4:        0x10785915d - rt::unwind::begin_unwind_fmt::hc68ebd2b3de4118e2Ez
   5:        0x1078e8302 - rust_begin_unwind
   6:        0x107935d0c - panicking::panic_fmt::h6d9a452b0d084e9dLkl
   7:        0x1046960b9 - collections::hash::map::HashMap<K,$u{20}V$C$$u{20}H$GT$.Index$LT$Q$C$$u{20}V$GT$::index::h4548773097338651390
   8:        0x104756a96 - astconv::ast_ty_to_ty::unboxed_closure.36753
   9:        0x104755323 - astconv::ast_ty_to_ty::h3464216238889989760
  10:        0x10475497c - iter::IteratorExt::collect::h1178474147849539242
  11:        0x104862cf1 - astconv::ast_path_to_trait_ref::h12290017992957141453
  12:        0x1048625e6 - astconv::instantiate_poly_trait_ref::h3434886886043991751
  13:        0x104862350 - vec::Vec<T>.FromIterator<T>::from_iter::h6759705047736047902
  14:        0x1048c987d - collect::compute_bounds::h9074989142750734463
  15:        0x104860e9b - collect::ty_generics_for_trait::ha23d00f7844cb7b4quv
  16:        0x1047321ee - collect::trait_def_of_item::h2e00c54b47ce1f2cgdv
  17:        0x10472ed30 - collect::CollectTraitDefVisitor<$u{27}a$C$$u{20}$u{27}tcx$GT$.visit..Visitor$LT$$u{27}v$GT$::visit_item::h913166666a1bcfc7dSt
  18:        0x10492237f - check_crate::unboxed_closure.43401
  19:        0x10492048a - check_crate::hcab218417b8f1f7f51y
  20:        0x103ff9113 - driver::phase_3_run_analysis_passes::hb0ac12e829cd00e7Jta
  21:        0x103fdaffe - driver::compile_input::hdcb29128a43ec322wba
  22:        0x10417aff8 - thunk::Thunk<(*,$u{20}R$GT$::new::unboxed_closure.30336
  23:        0x104179038 - thunk::F.Invoke<A,$u{20}R$GT$::invoke::h12480167585331118411
  24:        0x1041777d9 - rt::unwind::try::try_fn::h9666833473335668351
  25:        0x107950669 - rust_try_inner
  26:        0x107950656 - rust_try
  27:        0x104177ed7 - thunk::F.Invoke<A,$u{20}R$GT$::invoke::h4838524648863172491
  28:        0x1078d7c24 - sys::thread::thread_start::h7394d69fbc5b85e9vFw
  29:     0x7fff8115e899 - _pthread_body
  30:     0x7fff8115e72a - _pthread_struct_init
@pythonesque pythonesque changed the title ICE using associative type in trait bound ICE using associated type in trait bound Dec 27, 2014
@pythonesque
Copy link
Contributor Author

Note: this still ICEs, but now gives a different backtrace:


thread 'rustc' panicked at 'assertion failed: did.krate != ast::LOCAL_CRATE', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/librustc/middle/ty.rs:5429

stack backtrace:
   1:        0x112a5ea85 - sys::backtrace::write::h99bbbbef588b9184Klt
   2:        0x112a83f1f - failure::on_fail::h8b1c6fd57e4213d95nz
   3:        0x1129e895a - rt::unwind::begin_unwind_inner::hfd8d974c1cdeb74f35y
   4:        0x10fb41dfc - rt::unwind::begin_unwind::h9670423602147760625
   5:        0x10fec0a48 - middle::ty::lookup_trait_def::h0d278c058dac7da0bJ8
   6:        0x10f71a8bf - astconv::trait_defines_associated_type_named::h6e1f2adb924a7a3ed8r
   7:        0x10f729f14 - astconv::associated_path_def_to_ty::he58c9dd43523b1ady3r
   8:        0x10f7f5b58 - astconv::ast_ty_to_ty::unboxed_closure.36572
   9:        0x10f7f4217 - astconv::ast_ty_to_ty::h9692175568744562300
  10:        0x10f7f3889 - vec::Vec<T>.FromIterator<T>::from_iter::h2513327853763018693
  11:        0x10f81ca4b - astconv::instantiate_poly_trait_ref::h13560246163170871033
  12:        0x10f81c340 - vec::Vec<T>.FromIterator<T>::from_iter::h14680717809933419516
  13:        0x10f86855e - collect::conv_param_bounds::h18412785619248994413
  14:        0x10f897bbb - collect::ty_generics_for_trait::predicates_for_associated_types::unboxed_closure.38347
  15:        0x10f8975f1 - vec::Vec<T>.FromIterator<T>::from_iter::h5667342797167702362
  16:        0x10f86764e - collect::ty_generics_for_trait::h86232192f12b9d3cL6t
  17:        0x10f7d313a - collect::trait_def_of_item::h38b7e2843be79580FSt
  18:        0x10f7d0441 - collect::CollectTraitDefVisitor<'a, 'tcx>.visit..Visitor<'v>::visit_item::he1dd377f8daa9f9cm6s
  19:        0x10f8d00ff - check_crate::unboxed_closure.40064
  20:        0x10f8ce0eb - check_crate::h8fb6181edbba0f5bjsx
  21:        0x10f12d592 - driver::phase_3_run_analysis_passes::h80f5730bb84ad4dbTva
  22:        0x10f119f1c - driver::compile_input::h3940b6305f304e80wba
  23:        0x10f1e1853 - thunk::F.Invoke<A, R>::invoke::h10598202800189765697
  24:        0x10f1de9b0 - rt::unwind::try::try_fn::h2354011666368721707
  25:        0x112aec409 - rust_try_inner
  26:        0x112aec3f6 - rust_try
  27:        0x10f1df0f6 - thunk::F.Invoke<A, R>::invoke::h10531483554991743553
  28:        0x112a6fed4 - sys::thread::thread_start::h156b750c645e6d54M8v
  29:     0x7fff8115e899 - _pthread_body
  30:     0x7fff8115e72a - _pthread_struct_init

@japaric
Copy link
Member

japaric commented Jan 4, 2015

cc @nikomatsakis

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

Gankra commented Jan 10, 2015

Just ran into this in collect-rs, trying to migrate some of our iterator traits/adaptors to associate types. :(

@alexcrichton
Copy link
Member

Another example:

#![crate_type = "lib"]
trait IntoIterator {
    type Item;
    type IntoIter: Iterator<Item=Self::Item>;

    fn into_iter(self) -> Self::IntoIter;
}
$ rustc foo.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
thread 'rustc' panicked at 'assertion failed: did.krate != ast::LOCAL_CRATE', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/middle/ty.rs:5341

@nikomatsakis
Copy link
Contributor

I suspect you can workaround this with Iterator<Item=<Self as IntoIterator>::Item>

@alexcrichton
Copy link
Member

It got rid of the ICE at least!

$ rustc foo.rs
foo.rs:4:34: 4:62 error: illegal recursive type; insert an enum or struct in the cycle, if this is desired [E0246]
foo.rs:4     type IntoIter: Iterator<Item=<Self as IntoIterator>::Item>;
                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

@nikomatsakis
Copy link
Contributor

@alexcrichton d'oh. I'll look into resolving this, I think it's blocking @pnkfelix too. It's a bit non-trivial I fear.

@pnkfelix
Copy link
Member

pnkfelix commented Feb 3, 2015

@nikomatsakis yes, i think they are the same problem. gist: https://gist.github.com/pnkfelix/6ef4e5087f31473a7305

@kvark
Copy link
Contributor

kvark commented Feb 3, 2015

We are also getting this ICE in gfx-rs/gfx#517. Unfortunately, it blocks us from doing the most needed changes in regards to device abstraction.

@Gankra
Copy link
Contributor

Gankra commented Feb 20, 2015

I'm still seeing this with a slightly different input:

pub trait Foo: Iterator<Item=Self::Key> {
    type Key;
}

fn main() {}
[abeingessner@localhost test]$ cargo build
   Compiling test v0.0.1 (file:///home/abeingessner/dev/test)
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'assertion failed: did.krate != ast::LOCAL_CRATE', /home/abeingessner/dev/rust/src/librustc/middle/ty.rs:5461

stack backtrace:
   1:     0x7f10e24ddf70 - sys::backtrace::write::h8fe124aa62d4666cKlC
   2:     0x7f10e2506820 - panicking::on_panic::hbe49ffcf4865682ftXL
   3:     0x7f10e2447480 - rt::unwind::begin_unwind_inner::h76247a696cedaf77RBL
   4:     0x7f10e02c98f0 - rt::unwind::begin_unwind::h18381420555743533883
   5:     0x7f10e060ab00 - middle::ty::lookup_trait_def::h681d8657b73814a8Nla
   6:     0x7f10e062ff60 - middle::ty::predicates_for_trait_ref::h573132b5faa99585Vna
   7:     0x7f10e0629ce0 - middle::traits::util::Elaborator<'cx, 'tcx>.Iterator::next::h0e03729c4060de94QkV
   8:     0x7f10e062f960 - middle::traits::util::Supertraits<'cx, 'tcx>.Iterator::next::hfc2d17e5bc9957barnV
   9:     0x7f10e1c93450 - astconv::ast_ty_to_ty::closure.34582
  10:     0x7f10e1c30490 - astconv::ast_ty_to_ty::h7bd9623e042b5e3eNcw
  11:     0x7f10e1c8b930 - vec::Vec<T>.FromIterator<T>::from_iter::h182839420622209455
  12:     0x7f10e1c88800 - astconv::convert_angle_bracketed_parameters::h9bc668b404bddf99biv
  13:     0x7f10e1c8d020 - astconv::ast_path_to_trait_ref::h877deb0e17991561Vvv
  14:     0x7f10e1c3c230 - astconv::instantiate_trait_ref::h12efe6a871d055d0Csv
  15:     0x7f10e1c8ca50 - astconv::instantiate_poly_trait_ref::hdf3227e7a74ba7561qv
  16:     0x7f10e1cbb700 - collect::compute_bounds::ha18f23051e2a6717cTy
  17:     0x7f10e1c9cd80 - collect::trait_def_of_item::hb7f0f767c7cffe73Q2x
  18:     0x7f10e1c9c310 - collect::CollectTraitDefVisitor<'a, 'tcx>.visit..Visitor<'v>::visit_item::hbcfae1845ee115ebS8w
  19:     0x7f10e1ce6a00 - check_crate::closure.35776
  20:     0x7f10e1ce4a10 - check_crate::hc6d19f098edbe89aVjC
  21:     0x7f10e2b60bb0 - driver::phase_3_run_analysis_passes::hb4dd797330c68d2cgHa
  22:     0x7f10e2b46ef0 - driver::compile_input::he482374663bf0bd3Gba
  23:     0x7f10e2c15eb0 - run_compiler::h734ffa62c7eabdf8Zbc
  24:     0x7f10e2c147b0 - thunk::F.Invoke<A, R>::invoke::h15492659192422867035
  25:     0x7f10e2c136a0 - rt::unwind::try::try_fn::h15963018374249765158
  26:     0x7f10e257c570 - rust_try_inner
  27:     0x7f10e257c560 - rust_try
  28:     0x7f10e2c139a0 - thunk::F.Invoke<A, R>::invoke::h18067408346278163587
  29:     0x7f10e24f28c0 - sys::thread::thread_start::h45e232408687fc4093G
  30:     0x7f10dc53c460 - start_thread
  31:     0x7f10e20cd769 - clone
  32:                0x0 - <unknown>

Could not compile `test`.

@Gankra Gankra reopened this Feb 20, 2015
@nikomatsakis
Copy link
Contributor

PR #22512 fixes the ice in @gankro's example but we do get an error that doesn't appear quite right.

@nikomatsakis
Copy link
Contributor

I think I see how to fix it. I'll rebase #22512 and either open a new PR with the fix or maybe open a new PR.

@Gankra
Copy link
Contributor

Gankra commented Feb 20, 2015

Thanks! 💃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

8 participants