Closed
Description
Hello!
I am getting a compiler error when trying to define the following trait:
trait Foo {
type PublicKey<'a> : From<&'a [u8]>;
}
fn main() {
println!("hello, world!")
}
I would have expected my code to compile successfully, or to exit with some error explaining why static compilation failed.
Instead, I am getting a:
error: internal compiler error: src/librustc/ty/subst.rs:426: Region parameter out of range when substituting in region 'a (root type=Some(&'a [u8])) (index=1)
More specifically, I'm having troubles trying to define some type PublicKey
that must implement AsRef<[u8]>
and From<&[u8]>
. If I try with lifetimes I get this compiler error; if I replace the from trait with From<[u8; N]>
for some const N: usize (enabling generic_associated_types
and const_generics
) I get:
error: const generics in any position are currently unsupported
--> foo.rs:4:24
|
4 | type PublicKey<const N: usize> : From<[u8; N]>;
| ^
Am I doing something terribly stupid here or const generics for associated types are not yet ready and lifetimes on associated types lead to a compiler error?
Here's the full traceback
--> foo.rs:3:3
|
3 | type PublicKey<'a> : From<&'a[u8]>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(generic_associated_types)] to the crate attributes to enable
error: internal compiler error: src/librustc/ty/subst.rs:426: Region parameter out of range when substituting in region 'a (root type=Some(&'a [u8])) (index=1)
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:558:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0658`.
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.34.0-nightly (aadbc459b 2019-02-23) running on x86_64-unknown-linux-gnu
Metadata
Metadata
Assignees
Labels
Area: Generic associated types (GATs)Area: Associated items (types, constants & functions)Category: This is a bug.`#![feature(generic_associated_types)]` a.k.a. GATsIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Medium priorityRelevant to the compiler team, which will review and decide on the PR/issue.