Skip to content

compiler error: lifetimes in associated types leading to a compiler error. #58694

Closed
@mmaker

Description

@mmaker

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

Activity

changed the title [-]compiler error: lifetimes in traits leading to a compiler error.[/-] [+]compiler error: lifetimes in associated types leading to a compiler error.[/+] on Feb 24, 2019
jonas-schievink

jonas-schievink commented on Feb 24, 2019

@jonas-schievink
Contributor

type PublicKey<'a> defines a generic associated type, which aren't yet fully implemented.

added
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
A-associated-itemsArea: Associated items (types, constants & functions)
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
C-bugCategory: This is a bug.
on Feb 24, 2019
hellow554

hellow554 commented on Feb 25, 2019

@hellow554
Contributor

type PublicKey<'a> defines a generic associated type, which aren't yet fully implemented.

That's correct, but even without enabled feature it crashes, which should not happen, or am I wrong? :/

pietroalbini

pietroalbini commented on Feb 25, 2019

@pietroalbini
Member

cc @rust-lang/compiler @rust-lang/release

It's technically a stable-to-beta regression, but it goes from hard error to ICE so I don't think it's worth blocking the release on this.

(Also woops, mistakenly closed the issue)

Centril

Centril commented on Feb 25, 2019

@Centril
Contributor

As long as we're not breaking working code it's not really a breakage and so I agree we should not block a release on it.

arielb1

arielb1 commented on Feb 25, 2019

@arielb1
Contributor

Also +1 for not blocking the release on this.

This error does not only occur in code that is illegal, it (apparently) only occurs in code that has already triggered a visible, clear, feature-gate error. Therefore, it's not even a particularly-high risk for confusing users (unlike e.g. an ICE that occurs instead of a valid error message, or an ICE that occurs after an obscure error message).

pnkfelix

pnkfelix commented on Feb 28, 2019

@pnkfelix
Member

triage: P-medium. Assigning to self for initial investigation.

(P-medium based on the reasons given by @arielb1 : the risks for end users here do seem quite low.)

20 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-GATsArea: Generic associated types (GATs)A-associated-itemsArea: Associated items (types, constants & functions)C-bugCategory: This is a bug.F-generic_associated_types`#![feature(generic_associated_types)]` a.k.a. GATsI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @pnkfelix@mmaker@Centril@hellow554@jonas-schievink

      Issue actions

        compiler error: lifetimes in associated types leading to a compiler error. · Issue #58694 · rust-lang/rust