Skip to content

ICE with associated type on trait #24810

Closed
@mdup

Description

@mdup

Given the following code,

use std::ops::Add;

trait T: Add<Output=Self> {
}

impl T<Output=T> {
}

fn main() {
}

the compiler crashes:

$ RUST_BACKTRACE=1 rustc main.rs
main.rs:6:15: 6:16 error: the value of the associated type `Output` (from the trait `core::ops::Add`) must be specified [E0191]
main.rs:6 impl T<Output=T> {
                        ^
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: !ty::type_needs_infer(ty)', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/librustc_typeck/lib.rs:148

stack backtrace:
   1:        0x103d6cb3f - sys::backtrace::write::he7c1ee6a91037116KVr
   2:        0x103d75242 - panicking::on_panic::h95811d48f94bff2aNVv
   3:        0x103d31985 - rt::unwind::begin_unwind_inner::h83dd7700bec4d3dcwDv
   4:        0x100b0b8af - rt::unwind::begin_unwind::h5521202385013033086
   5:        0x100c3058e - collect::convert_item::he430b0ba35372b84KGx
   6:        0x100c7ba06 - check_crate::closure.38384
   7:        0x100c7997a - check_crate::h38598962c6951e9d2EC
   8:        0x1004d4f72 - driver::phase_3_run_analysis_passes::h4345ea303ca2819ctGa
   9:        0x1004b6b18 - driver::compile_input::h83758d277994a32eQba
  10:        0x10057bb43 - run_compiler::h2639405527e4221cF4b
  11:        0x1005792aa - boxed::F.FnBox<A>::call_box::h1823104088724806648
  12:        0x1005787f7 - rt::unwind::try::try_fn::h7700810389900064321
  13:        0x103df7618 - rust_try_inner
  14:        0x103df7605 - rust_try
  15:        0x100578ace - boxed::F.FnBox<A>::call_box::h1089084376626579945
  16:        0x103d73c3d - sys::thread::Thread::new::thread_start::he43a1bd6638c19advYu
  17:     0x7fff930b9898 - _pthread_body
  18:     0x7fff930b9729 - _pthread_start

$ rustc --version
rustc 1.1.0-nightly (21f278a68 2015-04-23) (built 2015-04-24)

As a sidenote, I've played with it and was not able to find the correct syntax. The goal is to have a trait requires all implementers be able to add to themselves.

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions