GithubHelp home page GithubHelp logo

Comments (6)

claytonwramsey avatar claytonwramsey commented on June 5, 2024

My original idea for handling this was covered in a remark in Collectable - in essence, buyer beware - with Collectable as an unsafe trait. I think that the approach of forcing a Drop implementation on all Collectable types is far more elegant, though. Will do.

from dumpster.

claytonwramsey avatar claytonwramsey commented on June 5, 2024

@wishawa By the way, do you know any elegant way to extract a TokenStream for the "default" implementation of Drop, or do I have to go do that myself?

from dumpster.

claytonwramsey avatar claytonwramsey commented on June 5, 2024

A possible wrinkle: in your example solution, MyStructInner would have to be either !Collectable or have a manual implementation of Collectable. An alternate solution would be to make Gc operations panic if dereferenced during Drop.

from dumpster.

wishawa avatar wishawa commented on June 5, 2024

@wishawa By the way, do you know any elegant way to extract a TokenStream for the "default" implementation of Drop, or do I have to go do that myself?

The "default" implementation of drop is just

impl Drop for Type {
fn drop(&mut self) {}
}

right?

But if you meant the drop glue, I have no idea. I don't know if it even exists as Rust code (as opposed to being some intermediate representation thing).

from dumpster.

wishawa avatar wishawa commented on June 5, 2024

A possible wrinkle: in your example solution, MyStructInner would have to be either !Collectable or have a manual implementation of Collectable.

True. I didn't think of that. One fix would be to provide a mostly transparent ManuallyCollectable type analogous to std::mem::ManuallyDrop.

An alternate solution would be to make Gc operations panic if dereferenced during Drop.
This might be the cleanest way to go about it.

An issue is that with careful use of Pin, it is possible to safely make self-referential types that hold references derefed before the drop. I don't think there is a general fix for this. The good thing is this is almost impossible to unintentionally run in to.

from dumpster.

claytonwramsey avatar claytonwramsey commented on June 5, 2024

I've now made it so that Gc::deref will panic if dereferenced against a value which is currently being dropped.

from dumpster.

Related Issues (10)

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.