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

lifetime-parametric GATs cause ICEs (with feature(generic_associated_types)) #62521

Closed
Tracked by #44265
pnkfelix opened this issue Jul 9, 2019 · 3 comments · Fixed by #67160
Closed
Tracked by #44265

lifetime-parametric GATs cause ICEs (with feature(generic_associated_types)) #62521

pnkfelix opened this issue Jul 9, 2019 · 3 comments · Fixed by #67160
Labels
A-associated-items Area: Associated items such as associated types and consts. A-lifetimes Area: lifetime related C-bug Category: This is a bug. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pnkfelix
Copy link
Member

pnkfelix commented Jul 9, 2019

Many people playing with #[feature(generic_associated_types)] have noticed that they break very easily when you attempt to use a lifetime formal parameter.

Examples follow

ICE: Region parameter out of range

#62326 (play):

#![feature(generic_associated_types)]
trait Iterator {
    type Item<'a>: 'a;
}

#58694 (play)

#![feature(generic_associated_types)]
trait Foo {
  type PublicKey<'a> : From<&'a [u8]>;     
}

#49362 (play)

#![feature(generic_associated_types)]

trait Trait {
    type Associated<'a>;
}

impl Trait for () {
    type Associated<'a> = &'a ();
}

ICE: cannot convert ReEarlyBound(0, 'b) to a region vid

#60654 (play)

#![feature(generic_associated_types)]
struct Foo;

impl Iterator for Foo {
    type Item<'b> = &'b Foo;

    fn next(&mut self) -> Option<Self::Item> {
        None
    }
}

This obviously blocks stabilization of GATs (#44265).

@pnkfelix
Copy link
Member Author

pnkfelix commented Jul 9, 2019

(also copying labels from the issues in the description)

@pnkfelix pnkfelix added A-associated-items Area: Associated items such as associated types and consts. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-lifetimes Area: lifetime related P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 9, 2019
@estebank
Copy link
Contributor

estebank commented Aug 5, 2019

CC #56445, seemingly same underlying issue, has longer thread.

@Centril Centril added F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs requires-nightly This issue requires a nightly compiler in some way. labels Aug 5, 2019
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Oct 15, 2019
@hellow554
Copy link
Contributor

hellow554 commented Nov 25, 2019

Not only an ICE will occur if you put Self::Item in the return type, but also as a parameter (take from #66734):

#![feature(generic_associated_types)]

trait Foo {
    type Bar<'a>;
    fn baz<'a>(_: Self::Bar) ;
}

impl Foo for () {
    type Bar<'a> = &'a ();
    fn baz<'a>(_: Self::Bar) {}
}

fn main () {}

Centril added a commit to Centril/rust that referenced this issue Dec 21, 2019
…atsakis

Make GATs less ICE-prone.

After this PR simple lifetime-generic associated types can now be used in a compiling program. There are two big limitations:

* rust-lang#30472 has not been addressed in any way (see src/test/ui/generic-associated-types/iterable.rs)
* Using type- and const-generic associated types errors because bound types and constants aren't handled by trait solving.
    * The errors are technically non-fatal, but they happen in a [part of the compiler](https://github.com/rust-lang/rust/blob/4abb0ad2731e9ac6fd5d64d4cf15b7c82e4b5a81/src/librustc_typeck/lib.rs#L298) that fairly aggressively stops compiling on errors.

closes rust-lang#47206
closes rust-lang#49362
closes rust-lang#62521
closes rust-lang#63300
closes rust-lang#64755
closes rust-lang#67089
@bors bors closed this as completed in b50c3b7 Dec 22, 2019
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 such as associated types and consts. A-lifetimes Area: lifetime related C-bug Category: This is a bug. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants