Skip to content

Associated type as struct field causes type-checking error #20535

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

Closed
murarth opened this issue Jan 4, 2015 · 1 comment · Fixed by #20706
Closed

Associated type as struct field causes type-checking error #20535

murarth opened this issue Jan 4, 2015 · 1 comment · Fixed by #20706
Labels
A-associated-items Area: Associated items (types, constants & functions) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Milestone

Comments

@murarth
Copy link
Contributor

murarth commented Jan 4, 2015

The following causes an error (indicated in the comment):

#![feature(associated_types)]

pub trait Foo {
    type Bar;
}

impl Foo for int {
    type Bar = int;
}

struct Thing<F: Foo> {
    a: F,
    b: F::Bar,
}

fn main() {
    let _ = Thing{a: 1i, b: 2i};
    //                      ^~
    // error: mismatched types: expected `<int as Foo>::Bar`,
    // found `int` (expected associated type, found int)
}

And this closely related case causes an ICE:

#![feature(associated_types)]

pub trait Foo {
    type Bar;
}

impl Foo for int {
    type Bar = int;
}

struct Thing<F: Foo> {
    a: F,
    b: Option<F::Bar>,
}

fn main() {
    let _ = Thing{a: 1i, b: None};
}

Backtrace:

error: internal compiler error: trying to take the sizing type of <int as Foo>::Bar, an unsized type
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 'Box<Any>', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libsyntax/diagnostic.rs:182

stack backtrace:
   1:     0x7f22c6fb32d0 - sys::backtrace::write::h8532e701ef86014f4it
   2:     0x7f22c6fd8b00 - failure::on_fail::h7532e1f79d134d5dzvz
   3:     0x7f22c6f3e1c0 - rt::unwind::begin_unwind_inner::h97b151606151d62deaz
   4:     0x7f22c1defc60 - rt::unwind::begin_unwind::h15809447133099964284
   5:     0x7f22c1df0510 - diagnostic::Handler::bug::h8818b567cf47e6a0DLF
   6:     0x7f22c512acf0 - session::Session::bug::h251da16737c526c0lrq
   7:     0x7f22c5dfd020 - trans::type_of::sizing_type_of::he06887b02c649aebXRo
   8:     0x7f22c5f1cb10 - trans::adt::represent_type_uncached::h6b884b95692379c1oxH
   9:     0x7f22c5df7b30 - trans::adt::represent_type::ha0c2ea2716678100YtH
  10:     0x7f22c5de2fb0 - trans::type_of::type_of::h7caa699265884e0bFYo
  11:     0x7f22c5de2fb0 - trans::type_of::type_of::h7caa699265884e0bFYo
  12:     0x7f22c5f22b20 - vec::Vec<T>.FromIterator<T>::from_iter::h11585473372288691594
  13:     0x7f22c5de2fb0 - trans::type_of::type_of::h7caa699265884e0bFYo
  14:     0x7f22c5de2fb0 - trans::type_of::type_of::h7caa699265884e0bFYo
  15:     0x7f22c5decf50 - trans::base::alloc_ty::h29690970a9e20515oft
  16:     0x7f22c5ee6800 - trans::_match::mk_binding_alloca::h2686137581982254550
  17:     0x7f22c5ddcb70 - trans::base::init_local::h9a5509ab5cb7df8eB1s
  18:     0x7f22c5dddd10 - trans::controlflow::trans_block::hfd89f3a5d0ddcbbdQ1d
  19:     0x7f22c5ea8f60 - trans::base::trans_closure::hbecde8c2bc5f7b2fsSt
  20:     0x7f22c5dc9120 - trans::base::trans_fn::hba312ea6d66cf757Z2t
  21:     0x7f22c5dc4300 - trans::base::trans_item::ha0e598b4af14d13fQpu
  22:     0x7f22c5eb1a60 - trans::base::trans_crate::hf12b6e99a3af9ab9blv
  23:     0x7f22c7513250 - driver::phase_4_translate_to_llvm::h40ce54ee4a878885vFa
  24:     0x7f22c74f2ae0 - driver::compile_input::h68b8602933aad8d7wba
  25:     0x7f22c75bdeb0 - thunk::F.Invoke<A, R>::invoke::h18029802347644288836
  26:     0x7f22c75bcc60 - rt::unwind::try::try_fn::h6518866316425934196
  27:     0x7f22c703f400 - rust_try_inner
  28:     0x7f22c703f3f0 - rust_try
  29:     0x7f22c75bcfb0 - thunk::F.Invoke<A, R>::invoke::h15513809553472565307
  30:     0x7f22c6fc4e40 - sys::thread::thread_start::h5ea7ba97235331d5a9v
  31:     0x7f22c16130c0 - start_thread
  32:     0x7f22c6be4ec9 - __clone
  33:                0x0 - <unknown>
@kmcallister kmcallister added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-associated-items Area: Associated items (types, constants & functions) labels Jan 4, 2015
@nikomatsakis
Copy link
Contributor

The second example (ICE) is fixed by #20706

@nikomatsakis nikomatsakis changed the title Associated type as struct field causes error or ICE Associated type as struct field causes type-checking error Jan 7, 2015
@nikomatsakis nikomatsakis added this to the 1.0 alpha milestone Jan 7, 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) 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.

3 participants