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: Associated type referencing itself #20772

Closed
tobbebex opened this issue Jan 8, 2015 · 10 comments · Fixed by #24259
Closed

ICE: Associated type referencing itself #20772

tobbebex opened this issue Jan 8, 2015 · 10 comments · Fixed by #24259
Labels
A-associated-items Area: Associated items (types, constants & functions) E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@tobbebex
Copy link

tobbebex commented Jan 8, 2015

trait T : Iterator<Item=Self::Item>
{}

Compiling the above (admittedly ill-typed) file will cause

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-bugr
eport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'assertion failed: did.krate != ast::LOCAL_CRATE', C:
\bot\slave\nightly-dist-rustc-win-64\build\src\librustc\middle\ty.rs:5362

stack backtrace:
   1:         0x69bee9cd - sys::backtrace::write::hd40c6de25ef01e0bfjt
   2:         0x69c01a32 - rt::unwind::register::hcb202fda23aef97aw7y
   3:         0x69b834a7 - rt::unwind::begin_unwind_inner::h43ca250f1ae88b3e64y
   4:           0x6a8bcc - middle::astencode::encode_inlined_item::h4b6b2c857184
2bb1Jja
   5:           0xa6541f - middle::ty::lookup_trait_def::ha89a0d2c5a879780Zv8
   6:           0xa88c19 - middle::ty::predicates_for_trait_ref::he59b587e624291
8d4w8
   7:           0xa5b65b - middle::traits::util::Elaborator<'cx, 'tcx>.Iterator:
:next::hcbe2c9744651548fo9T
   8:           0xa62347 - middle::traits::util::Supertraits<'cx, 'tcx>.Iterator
::next::h2e87d83ce16f061dZbU
   9:         0x6d5f70bc - rscope::ShiftedRscope<'r>.RegionScope::anon_regions::
h258921b49adee87bcYq
  10:         0x6d5992f8 - astconv::ast_ty_to_ty::h09671105f6afe18cwes
  11:         0x6d5ed3d8 - rscope::ShiftedRscope<'r>.RegionScope::anon_regions::
h258921b49adee87bcYq
  12:         0x6d5eb4c3 - rscope::ShiftedRscope<'r>.RegionScope::anon_regions::
h258921b49adee87bcYq
  13:         0x6d5ef7d1 - rscope::ShiftedRscope<'r>.RegionScope::anon_regions::
h258921b49adee87bcYq
  14:         0x6d5ee5a9 - rscope::ShiftedRscope<'r>.RegionScope::anon_regions::
h258921b49adee87bcYq
  15:         0x6d5ee071 - rscope::ShiftedRscope<'r>.RegionScope::anon_regions::
h258921b49adee87bcYq
  16:         0x6d62f749 - collect::CollectCtxt<'a, 'tcx>.AstConv<'tcx>::project
ed_ty::h5a3a931757c8bb85Gbt
  17:         0x6d60b2a1 - collect::CollectCtxt<'a, 'tcx>.AstConv<'tcx>::get_ite
m_type_scheme::hffebd1c9c5b2d6c3P8s
  18:         0x6d606312 - collect::CollectTraitDefVisitor<'a, 'tcx>.visit..Visi
tor<'v>::visit_item::h781513b01a393b7dP5s
  19:         0x6d66274f - check_crate::h862e87e9f04b6e0cNrx
  20:         0x6d6600b0 - check_crate::h862e87e9f04b6e0cNrx
  21:         0x70b18b2f - driver::phase_3_run_analysis_passes::hf7b2b2080ba4334
56va
  22:         0x70b027ba - driver::compile_input::h45b30318e07c4cf6vba
  23:         0x70bcaa1e - run::heefafb1ff7869308B4b
  24:         0x70bc786a - run::heefafb1ff7869308B4b
  25:         0x69c288fc - rust_try
  26:         0x69c288d9 - rust_try
  27:         0x70bc7fa9 - run::heefafb1ff7869308B4b
  28:         0x69bf3457 - sys::tcp::TcpListener::bind::hfcf283b88d14d24bfTv
  29:     0x7ffc65ad16ad - BaseThreadInitThunk

My version is

rustc 1.0.0-nightly (ea6f65c5f 2015-01-06 19:47:08 +0000)
binary: rustc
commit-hash: ea6f65c5f1a3f84e010d2cef02a0160804e9567a
commit-date: 2015-01-06 19:47:08 +0000
host: x86_64-pc-windows-gnu
release: 1.0.0-nightly
@jroesch
Copy link
Member

jroesch commented Jan 8, 2015

cc @nikomatsakis, @nick29581 didn't easily find a dup of this.

@nrc nrc added A-associated-items Area: Associated items (types, constants & functions) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Jan 8, 2015
@carllerche
Copy link
Member

Looks like I am hitting a similar issue.

Repro:

pub trait Foo<T> {
}

pub trait Bar : Send {
    type A;
    type B: Foo<Self::A>;
}

pub fn main() {}

@japaric
Copy link
Member

japaric commented Feb 13, 2015

@carllerche your code compiles with cf636c2
@tobbebex's code still ICEs though

@brendanzab
Copy link
Member

I have a similar issue with:

pub trait Resources {}

pub trait CommandBuffer {
    type Resouces: Resources;
}

pub trait Device {
    type CommandBuffer: CommandBuffer<Resources = Self::Resources>;
}
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:5383

Playpen link

@japaric
Copy link
Member

japaric commented Feb 14, 2015

@bjz With the latest nightly, your example doesn't ICE, but errors instead:

bjz.rs:10:51: 10:66 error: associated type `Resources` not found for type parameter `Self` [E0220]
bjz.rs:10     type CommandBuffer: CommandBuffer<Resources = Self::Resources>;
                                                            ^~~~~~~~~~~~~~~
bjz.rs:10:39: 10:67 error: no associated type `Resources` defined in `CommandBuffer` [E0218]
bjz.rs:10     type CommandBuffer: CommandBuffer<Resources = Self::Resources>;
                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors

@brendanzab
Copy link
Member

So that would be wrong...? Should I make a new issue?

@japaric
Copy link
Member

japaric commented Feb 14, 2015

@bjz Why would that be wrong? Device implementors don't have a Resources associated type, so Self::Resources is correctly rejected (the first error). The second error pops up because of a typo (I just noticed) it says Resouces in CommandBuffer.

@brendanzab
Copy link
Member

Oh, woops - the example was meant to be:

pub trait Resources {}

pub trait CommandBuffer {
    type Resources: Resources;
}

pub trait Device {
    type Resources: Resources;
    type CommandBuffer: CommandBuffer<Resources = Self::Resources>;
}

@japaric
Copy link
Member

japaric commented Feb 14, 2015

@bjz that compiles with the latest nightly (rustc 1.0.0-nightly (b9ba643b7 2015-02-13 21:15:39 +0000))

@brendanzab
Copy link
Member

Yay!

@ghost ghost added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Apr 3, 2015
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) E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants