Skip to content

Nightly panics when using associated constant in array size #27367

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

Closed
jadpole opened this issue Jul 28, 2015 · 2 comments
Closed

Nightly panics when using associated constant in array size #27367

jadpole opened this issue Jul 28, 2015 · 2 comments

Comments

@jadpole
Copy link

jadpole commented Jul 28, 2015

In the playpen (Mode: Debug, Channel: Nightly)

I was playing with associated constants when this code made the compiler panic:

#![feature(associated_consts)]

use ::std::marker::PhantomData;

trait Num {
    const VAL: usize;
    fn val() -> usize;
}

struct N1;
impl Num for N1 {
    const VAL: usize = 1;
    fn val() -> usize { N1::VAL }
}

struct Arr<S: Num> {
    ty: PhantomData<S>,
    data: [i32; S::VAL]
}


fn main() {
}

With error message:

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 'path not fully resolved: PathResolution { base_def: DefTyParam(TypeSpace, 0, DefId { krate: 0, node: 35 }, "S"(72)), last_private: LastMod(AllPublic), depth: 1 }', ../src/librustc/middle/def.rs:81


playpen: application terminated with error code 101

Playpen link: http://is.gd/dE8jbq

The line which confuses the compiler is this one:

    data: [i32; S::VAL]

Without it, the program compiles just fine.

@ghost
Copy link

ghost commented Jul 29, 2015

I think this is a duplicate of #26922.

@jadpole
Copy link
Author

jadpole commented Jul 29, 2015

It is indeed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant