Skip to content

Compiler panic on self-referencing trait with associated types #23595

Closed
@jmitchell

Description

@jmitchell

The compiler unexpectedly panicked due to a trait with associated types referencing itself. Likely related to #23073, but this trace goes one frame deeper before unwinding.

I tried this code:

use std::ops::{Index};

trait Hierarchy {
    type Value;
    type ChildKey;
    type Children = Index<Self::ChildKey, Output=Hierarchy>;

    fn data(&self) -> Option<(Self::Value, Self::Children)>;
}

I was expecting this to compile, and hoped Output=Hierarchy part would automatically reuse the associated types. Explicitly setting them using Hierarchy<Value=Self::Value,ChildKey=Self::ChildKey> doesn't seem to change anything.

Clearly there's a compiler bug somewhere, but I wouldn't mind feedback about the validity of my expectations. I'm fairly new to Rust. For now I've worked around the issue by moving the associated types into the trait signature.

Meta

rustc --version --verbose:

rustc 1.0.0-dev (e2fa53e59 2015-03-20) (built 2015-03-20)
binary: rustc
commit-hash: e2fa53e593a854a609ae9efe5a1bbe15265f0a6f
commit-date: 2015-03-20
build-date: 2015-03-20
host: x86_64-apple-darwin
release: 1.0.0-dev

Backtrace:

thread 'rustc' panicked at 'path not fully resolved: PathResolution { base_def: DefSelfTy(6), last_private: LastMod(AllPublic), depth: 1 }', /Users/jake/src/rust/src/librustc/middle/def.rs:79

stack backtrace:
   1:        0x1106312cb - sys::backtrace::write::hbea0685a50659608A7C
   2:        0x11065cfa8 - panicking::on_panic::hc1f3ff62cc45fceafXI
   3:        0x110578eb9 - rt::unwind::begin_unwind_inner::h189021cc7e69d195ZFI
   4:        0x11057935e - rt::unwind::begin_unwind_fmt::h93fcd46877260e86AEI
   5:        0x10d53b6af - middle::def::PathResolution::full_def::h38fd56f2ad8d940182k
   6:        0x10d44b2ba - PrivacyVisitor<'a, 'tcx>::check_path::h05c78fb3c2c4592fM4a
   7:        0x10d44c4d1 - PrivacyVisitor<'a, 'tcx>.Visitor<'v>::visit_path::hdbc4bac3ff8b01f6Tsb
   8:        0x10d44c5fe - visit::walk_path::h3479848768788528522
   9:        0x10d44c35e - PrivacyVisitor<'a, 'tcx>.Visitor<'v>::visit_item::h5358ad00fed0ec7ajdb
  10:        0x10d45386a - check_crate::hb1c6527f25d590b7lVb
  11:        0x10cb5f0a2 - driver::phase_3_run_analysis_passes::hf44129b9377f1b66sGa
  12:        0x10cb45556 - driver::compile_input::h363b4befa2afe902Rba
  13:        0x10cc05c53 - run_compiler::he317b7c6af5d4656v2b
  14:        0x10cc03775 - thunk::F.Invoke<A, R>::invoke::h4452396910537927981
  15:        0x10cc02b37 - rt::unwind::try::try_fn::h13708605604948619026
  16:        0x1106e4308 - rust_try_inner
  17:        0x1106e42f5 - rust_try
  18:        0x10cc02ed5 - thunk::F.Invoke<A, R>::invoke::h1733875596228645594
  19:        0x110647a5d - sys::thread::create::thread_start::hc225c8ea020565ecNDH
  20:     0x7fff9692c267 - _pthread_body
  21:     0x7fff9692c1e4 - _pthread_start

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.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