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

Build broken by type alias enforcing outlives relations #139

Closed
MingweiSamuel opened this issue Apr 11, 2022 · 8 comments
Closed

Build broken by type alias enforcing outlives relations #139

MingweiSamuel opened this issue Apr 11, 2022 · 8 comments

Comments

@MingweiSamuel
Copy link
Member

rust-lang/rust#95519

@MingweiSamuel
Copy link
Member Author

rust-lang/rust#95922

@MingweiSamuel
Copy link
Member Author

MingweiSamuel commented Apr 11, 2022

#![feature(generic_associated_types)]
#![feature(type_alias_impl_trait)]

trait Gats {
    type Build<'a, 'b>: Fn() -> String;
    fn build<'a, 'b>(a: &'a str, b: &'b str) -> Self::Build<'a, 'b>;
}

type AlphaBuild<'a, 'b> = impl Fn() -> String;

struct Alpha;
impl Gats for Alpha {
    type Build<'a, 'b> = AlphaBuild<'a, 'b>;
    fn build<'a, 'b>(a: &'a str, b: &'b str) -> Self::Build<'a, 'b> {
        || format!("{}{}", a, b)
    }
}

Playground Link

@MingweiSamuel
Copy link
Member Author

doesn't quite reproduce

#![feature(generic_associated_types)]
#![feature(type_alias_impl_trait)]

use std::fmt::Display;

trait GatsBase {
    type Build<'a, 'b>: Fn() -> String;
}
trait Gats: GatsBase {
    fn build<'a, 'b>(&'a self, b: &'b str) -> Self::Build<'a, 'b>;
}

type AlphaBuild<'a, 'b, T> = impl 'a + 'b + Fn() -> String;

struct Alpha<T: Display>(T);

impl<T: Display> GatsBase for Alpha<T> {
    type Build<'a, 'b> = AlphaBuild<'a, 'b, T>;
}
impl<T: Display> Gats for Alpha<T> {
    fn build<'a, 'b>(&'a self, b: &'b str) -> Self::Build<'a, 'b> {
        || format!("{}{}", self.0, b)
    }
}

@aliemjay
Copy link

I know nothing about hydroflow but noticed that adding move to the closure makes it pass.

Was it accpeted previously? That would be surprising!

@MingweiSamuel
Copy link
Member Author

MingweiSamuel commented Apr 12, 2022

updated playground

Thanks! Yeah, that does fix this example, so I guess this wasn't a reproduction of the issue we're having in hf itself. Still working on it.

more complicated playground also works

@aliemjay
Copy link

reproduced on playground

Fixed by adding where T: 'a to the GAT and to the type alias. playgound

@MingweiSamuel
Copy link
Member Author

Oh I didn't know the where Self: 'a clause let you bound other type parameters as 'a, I think that will work!

@MingweiSamuel
Copy link
Member Author

MingweiSamuel commented Apr 12, 2022

Although I guess writing where Self: 'a (instead of where T: 'a) also works? Since T is a parameter of Self, I guess.

MingweiSamuel added a commit to MingweiSamuel/hydroflow that referenced this issue Apr 12, 2022
nickjiang2378 pushed a commit to nickjiang2378/hydroflow that referenced this issue Jan 24, 2024
nickjiang2378 pushed a commit to nickjiang2378/hydroflow that referenced this issue Jan 25, 2024
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

2 participants