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

Compiler crash when using impl Trait to bound associated type parameter #47715

Closed
SDEagle opened this Issue Jan 24, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@SDEagle
Copy link

SDEagle commented Jan 24, 2018

When specifying a trait bound on an associated type with impl Trait the compiler crashes.

I tried this code:

#![feature(universal_impl_trait)]

trait Foo {}

trait Iterable {
    type Item;
    type Iter: Iterator<Item=Self::Item>;
    fn iterator(&self) -> Self::Iter;
}

struct Container<T: Iterable<Item = impl Foo>> {
    field: T
}

I expected to see this happen: compiler telling me what was wrong with my code 🤔

Instead, this happened: compiler crashed 🔥 💥 😞
thread 'rustc' panicked at 'assertion failed: self.in_band_ty_params.is_empty()', librustc/hir/lowering.rs:555:9

Now I now that I can fix this code by doing

struct Container<T: Iterable> where T::Item: Foo {}

instead of the impl Trait bound. But the actual code has a higher ranked trait bound because lifetimes and when I try the where there I get error[E0212]: cannot extract an associated type from a higher-ranked trait bound in this context:

#![feature(universal_impl_trait)]

trait Foo {}

trait Iterable<'a> {
    type Item;
    type Iter: Iterator<Item=Self::Item>;
    fn iterator(&'a self) -> Self::Iter;
}

struct Container<T: for<'a> Iterable<'a>> where T::Item: Foo {
    field: T
}

That was the reason why I started messing with impl Trait.

Meta

rustc --version --verbose:

rustc 1.25.0-nightly (4e3901d35 2018-01-23)
binary: rustc
commit-hash: 4e3901d35f6a8652f67111e7272263c9e62ab3e1
commit-date: 2018-01-23
host: x86_64-unknown-linux-gnu
release: 1.25.0-nightly
LLVM version: 4.0

Backtrace:

thread 'rustc' panicked at 'assertion failed: self.in_band_ty_params.is_empty()', librustc/hir/lowering.rs:555:9
stack backtrace:
   0:     0x7fa9df06f8fb - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h0b39267197ee7050
                               at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1:     0x7fa9df082b74 - std::sys_common::backtrace::print::h9b88c55b4043aa66
                               at libstd/sys_common/backtrace.rs:68
                               at libstd/sys_common/backtrace.rs:57
   2:     0x7fa9df05c320 - std::panicking::default_hook::{{closure}}::h3b642a3cd950ffe5
                               at libstd/panicking.rs:380
   3:     0x7fa9df05bdea - std::panicking::default_hook::hb4fb619379f6ce2e
                               at libstd/panicking.rs:390
   4:     0x7fa9df05c82b - std::panicking::rust_panic_with_hook::haad457c1aa56c2c3
                               at libstd/panicking.rs:576
   5:     0x7fa9daccb9a3 - std::panicking::begin_panic::ha2641df7a2d3bc17
   6:     0x7fa9dae5abc4 - rustc::hir::lowering::LoweringContext::lower_item::h0255bdef333f15fa
   7:     0x7fa9dae4e4b7 - <rustc::hir::lowering::LoweringContext::lower_crate::ItemLowerer<'lcx, 'interner> as syntax::visit::Visitor<'lcx>>::visit_item::ha6a95edc6be2fe96
   8:     0x7fa9dae4d55a - rustc::hir::lowering::lower_crate::hbfc87b4712ff7016
   9:     0x7fa9df41c510 - rustc::util::common::time::ha1b4b423dc21aa17
  10:     0x7fa9df4cc545 - rustc_driver::driver::phase_2_configure_and_expand::hab28e63c96a5e929
  11:     0x7fa9df4c51bd - rustc_driver::driver::compile_input::h4090a78c5a503d38
  12:     0x7fa9df4d8f17 - rustc_driver::run_compiler::ha1f48d7c496e9187
  13:     0x7fa9df439411 - std::sys_common::backtrace::__rust_begin_short_backtrace::h685c703bd6f40d6b
  14:     0x7fa9df0a8bce - __rust_maybe_catch_panic
                               at libpanic_unwind/lib.rs:102
  15:     0x7fa9df3ea6a2 - <F as alloc::boxed::FnBox<A>>::call_box::hb97a13aa605d55e8
  16:     0x7fa9df086c1b - std::sys::unix::thread::Thread::new::thread_start::h2dc780f3002ac407
                               at /checkout/src/liballoc/boxed.rs:798
                               at libstd/sys_common/thread.rs:24
                               at libstd/sys/unix/thread.rs:90
  17:     0x7fa9d907908b - start_thread
  18:     0x7fa9ded51e1e - __GI___clone
  19:                0x0 - <unknown>

bors added a commit that referenced this issue Apr 13, 2018

Auto merge of #49830 - sinkuu:fix_ice_47715, r=cramertj
Fix ICE by disallowing `impl Trait` in unsupported position

Fixes #47715.

@bors bors closed this in #49830 Apr 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment