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

GAT cannot infer implicit lifetime bounds. #62265

Closed
oxalica opened this issue Jul 1, 2019 · 3 comments
Closed

GAT cannot infer implicit lifetime bounds. #62265

oxalica opened this issue Jul 1, 2019 · 3 comments
Labels
A-associated-items Area: Associated items (types, constants & functions) A-GATs Area: Generic associated types (GATs) A-lifetimes Area: Lifetimes / regions A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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

@oxalica
Copy link
Contributor

oxalica commented Jul 1, 2019

I'm trying to simulate closures returning mutable captured variable with GAT-version FnMut.

It cannot infer implicit bound 'a: 'r here and emit an error. But there is self: &'r mut Self alive while Self contains &'a mut i32.

#![feature(generic_associated_types)]

trait MyFnMut<Arg> {
    type Output<'a>;
    fn call_mut(&mut self, arg: Arg) -> Self::Output;
}

struct Closure1<'a>(&'a mut i32);

impl<'a> MyFnMut<()> for Closure1<'a> {
    type Output<'r> = &'r mut i32;
    fn call_mut(&mut self, _: ()) -> Self::Output {
        self.0 // error
    }
}

The same type signature without GAT works well:

// This works
impl<'a> Closure1<'a> {
    fn call_mut(&mut self, _: ()) -> &mut i32 {
        self.0
    }
}

Playground

BTW: Returning unimplemented!() in call_mut (the first one) will cause an ICE. Don't know if it is expected.

@jonas-schievink jonas-schievink added A-associated-items Area: Associated items (types, constants & functions) A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. labels Jul 1, 2019
@hellow554
Copy link
Contributor

BTW: Returning unimplemented!() in call_mut (the first one) will cause an ICE. Don't know if it is expected.

an ICE is never expected. If you haven't, please search for similar issues and then if none is applicable, open an issue and report the ICE (with a small example).

@csmoe csmoe added the A-NLL Area: Non-lexical lifetimes (NLL) label Jul 1, 2019
@csmoe
Copy link
Member

csmoe commented Jul 1, 2019

ICE Duplicate of #56445 (comment)
cc @pnkfelix

@csmoe csmoe added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jul 1, 2019
@Centril Centril added requires-nightly This issue requires a nightly compiler in some way. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 5, 2019
@JohnTitor
Copy link
Member

JohnTitor commented Oct 4, 2019

Cannot see the ICE with the above playground link on latest nightly.

@fmease fmease added the A-GATs Area: Generic associated types (GATs) label Nov 2, 2024
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) A-GATs Area: Generic associated types (GATs) A-lifetimes Area: Lifetimes / regions A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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

No branches or pull requests

8 participants