Skip to content
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 panic when accessing an associated type's consts in generic function #42956

Closed
Osspial opened this issue Jun 28, 2017 · 5 comments
Closed
Labels
A-associated-items Area: Associated items (types, constants & functions) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@Osspial
Copy link

Osspial commented Jun 28, 2017

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
@Osspial
Copy link
Author

Osspial commented Jun 28, 2017

cc #29646

@arielb1
Copy link
Contributor

arielb1 commented Jun 29, 2017

cc @eddyb

@kwanyyoss
Copy link

Possible workaround?


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

trait A {
    type Foo: B;
    
    fn get_val() -> i32 { Self::Foo::get_val() }
}

trait B {
    const BAR: i32;
    
    fn get_val() -> i32 { Self::BAR }
}


fn generic<T: A>() {
    println!("{}", T::get_val());
}

fn main() {
    generic::<i32>();
}

Playground link: https://play.rust-lang.org/?gist=8eae8de12cc67e7a6b6d2cca09e4cd49&version=nightly

@Mark-Simulacrum Mark-Simulacrum added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ C-bug Category: This is a bug. labels Jul 19, 2017
@Osspial
Copy link
Author

Osspial commented Sep 1, 2017

Could this be tagged as A-associated-items?

@arielb1 arielb1 added the A-associated-items Area: Associated items (types, constants & functions) label Sep 3, 2017
@topecongiro
Copy link
Contributor

This is fixed on rustc 1.24.0-nightly (3f916bd30 2017-12-30).

@eddyb eddyb added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Dec 31, 2017
topecongiro added a commit to topecongiro/rust that referenced this issue Jan 11, 2018
kennytm added a commit to kennytm/rust that referenced this issue Jan 11, 2018
kennytm added a commit to kennytm/rust that referenced this issue Jan 11, 2018
kennytm added a commit to kennytm/rust that referenced this issue Jan 12, 2018
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) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

6 participants