Skip to content

Compiler panic when accessing an associated type's consts in generic function #42956

Closed
@Osspial

Description

@Osspial

Attempting to run this code causes the compiler to panic with the given message, which obviously should not happen.

#![feature(associated_consts)]

impl A for i32 {
    type Foo = u32;
}
impl B for u32 {
    const BAR: i32 = 0;
}

trait A {
    type Foo: B;
}

trait B {
    const BAR: i32;
}

fn generic<T: A>() {
    // This panics if the universal function call syntax is used as well
    println!("{}", T::Foo::BAR);
}
error: internal compiler error: src\librustc_const_eval\eval.rs:529: resolve_trait_associated_const: unexpected vtable type

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: rustc 1.20.0-nightly (f590a44ce 2017-06-27) running on x86_64-pc-windows-msvc

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'Box<Any>', src\librustc_errors\lib.rs:478
stack backtrace:
   0: <std::time::SystemTimeError as core::fmt::Display>::fmt
   1: std::panicking::Location::line
   2: std::panicking::Location::line
   3: std::panicking::rust_panic_with_hook
   4: <unknown>
   5: rustc_errors::Handler::bug
   6: rustc::session::bug_fmt
   7: rustc::session::bug_fmt
   8: rustc::session::bug_fmt
   9: rustc_const_eval::eval::ConstContext::eval
  10: rustc_const_eval::eval::lookup_const_by_id
  11: rustc_const_eval::eval::provide
  12: rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::try_get
  13: rustc::ty::maps::TyCtxtAt::const_eval
  14: rustc_const_eval::eval::ConstContext::eval
  15: rustc_const_eval::eval::ConstContext::eval
  16: <rustc_passes::consts::CheckCrateVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  17: <rustc_passes::consts::CheckCrateVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  18: <rustc_passes::consts::CheckCrateVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  19: <rustc_passes::consts::CheckCrateVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  20: <rustc_passes::consts::CheckCrateVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr

Note that attempting to do that with concrete types works - i.e. removing the function generic() and adding this compiles fine:

fn main() {
    println!("{}", <i32 as A>::Foo::BAR);
}

Playground link for the above code: https://is.gd/7AqiMP

Meta

rustc 1.20.0-nightly (f590a44ce 2017-06-27)
binary: rustc
commit-hash: f590a44ce61888c78b9044817d8b798db5cd2ffd
commit-date: 2017-06-27
host: x86_64-pc-windows-msvc
release: 1.20.0-nightly
LLVM version: 4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)C-bugCategory: This is a bug.E-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