Git Product home page Git Product logo

Comments (6)

Diggsey avatar Diggsey commented on May 27, 2024

And here is the result of reducing that expanded code:

trait Bar<X> {
    type Y;
}
struct Example<A>(A);
impl<X, T> Bar<X> for Example<T> {
    type Y = Option<T>;
}
struct Foo<A, B> {
    x: <Example<A> as Bar<B>>::Y,
}
struct __FooProjection<'pin, A, B> {
    x: &'pin mut <Example<A> as Bar<B>>::Y,
}

from pin-project.

Aaron1011 avatar Aaron1011 commented on May 27, 2024

It looks like the compiler is giving the correct error here. From the infer_outlives rfc:

In turn, if this associated type were used in a struct, where-clauses would be required. As we'll see in the reference-level explanation, this is a consequence of the fact that we do inference without regard for associated type normalization, but it makes for a relatively simple rule -- explicit where clauses are needed in the preseence of impls like the one above:

struct Foo<'a, T>
  where T: 'a // still required, not inferred from `field`
{
  field: <Vec<T> as MakeRef<'a>>::Type
}    

I think the solution is for pin-project to always generate T: 'pin for each type parameter T.

from pin-project.

Diggsey avatar Diggsey commented on May 27, 2024

@Aaron1011 it might be safer to add this bound instead:
where Foo<A, B>: 'pin

This also seems to fix the problem.

trait Bar<X> {
    type Y;
}
struct Example<A>(A);
impl<X, T> Bar<X> for Example<T> {
    type Y = Option<T>;
}
struct Foo<A, B> {
    x: <Example<A> as Bar<B>>::Y,
}
struct __FooProjection<'pin, A, B> where Foo<A, B>: 'pin {
    x: &'pin mut <Example<A> as Bar<B>>::Y,
}

Just in case there are parameters which don't need to have that constraint, we can leave that to the compiler to figure out.

from pin-project.

Aaron1011 avatar Aaron1011 commented on May 27, 2024

@Diggsey: That's a good idea - I'll do that instead.

from pin-project.

taiki-e avatar taiki-e commented on May 27, 2024

Published 0.4.9 which fixes this issue.

from pin-project.

Diggsey avatar Diggsey commented on May 27, 2024

Nice! 👍

from pin-project.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.