Coder Social home page Coder Social logo

Comments (9)

alexcrichton avatar alexcrichton commented on May 29, 2024 2

Ah no worries! I was able to adapt this and get something working, albeit not as egonomically as desired.

In any case thanks for the quick responses here, it's definitely appreciated!

from rust.

lcnr avatar lcnr commented on May 29, 2024 1

The hidden type of impl Host ends up as &'a U and we currently don't have an implied U: 'a bound here. This breaks the invariants of our type system, using a pattern which can result in actual unsoundnesses. I don't think your snippet is unsound as is, but also don't know how we would fix #114936 without breaking your example

from rust.

lcnr avatar lcnr commented on May 29, 2024

your code snippet does not seem to compile in 1.77 or 1.76? 🤔 https://rust.godbolt.org/z/vzhn87bfz

from rust.

alexcrichton avatar alexcrichton commented on May 29, 2024

That may be a godbolt issue perhaps? https://rust.godbolt.org/z/e6nxK5oaq shows it passing with 77/76 and locally 1.77.0 compiles the example for me.

from rust.

compiler-errors avatar compiler-errors commented on May 29, 2024

@alexcrichton: The code you shared in the issue has an extra + 'a, causing it to fail both before and after 1.78.

from rust.

alexcrichton avatar alexcrichton commented on May 29, 2024

Er apologies, that's my mistake. I was trying various versions locally and got the wires crossed. I've updated the above which also explains why the two godbolt links are differing in results.

I was surprised that this actually worked on 1.77.0, so is this actually a soundness issue fixed by #118882?

from rust.

alexcrichton avatar alexcrichton commented on May 29, 2024

Ah ok, if this is expected no worries, I just wanted to confirm!

Would you happen to know off the top of your head if there's a way we could somehow get this working? The ideal thing we want is:

fn foo<T>(f: impl Fn(&mut T) -> impl Host) { ... }

and we're trying to hack around it of sorts with a custom GetHost trait, but I'm having a tough time figuring out how to model this use case.

from rust.

alexcrichton avatar alexcrichton commented on May 29, 2024

Ah well in any case this appears to be expected so there's no issue here I believe. We'll work on getting something alternative working instead.

from rust.

lcnr avatar lcnr commented on May 29, 2024

Would you happen to know off the top of your head if there's a way we could somehow get this working? The ideal thing we want is:

It's really hard as you need a for<'a> U: 'a bound which currently forces U to be 'static while ideally it would only allow instantiating 'a with lifetimes which outlive 'a. We will support this in a few years as these kinds of bounds are necessary to fix e.g. #25860

but up until then I also don't have a nice fix for this :/

from rust.

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.