you_can::turn_off_the_borrow_checker

(docs.rs)

48 points | by striking 3 days ago ago

20 comments

  • tempesttempo86 5 hours ago ago

    Arbitrary mention: Crust[0]

    [0] https://github.com/tsoding/crust

  • extraduder_ire 6 hours ago ago

    Cool idea. I was expecting more than just turn_off_the_borrow_checker in you_can though.

    Maybe with time, as more counterexamples are needed for things "you can't just..." in rust.

  • EFLKumo 7 hours ago ago

    though said for education purpose, keep finding these boundary-pushings playful. I can recall early days arrested by "several ways to access private members in C++" lol

    • himata4113 6 hours ago ago

      I personally hate access controls in general since it always made be release a big sigh as a I was typing .getClass().getMethod()/getField() knowing that it hurts performance.

      • estebank 6 hours ago ago

        That kind of code doesn't have to hurt performance, as long as monomorphization, inlining or JITting are available to the toolchain. If every single method access is a virtual-table call, then yes, there's an "unnecessary" cost. But you shouldn't be writing high-level looking code in such a language if you care about that level of performance.

        • himata4113 6 hours ago ago

          it's more about the fact that the servers are java and invoking a reflection method does have a non-zero cost that isn't substantial but still makes you sigh as you either eat the performance cost or spend 10 minutes creating a patch and recompiling the server.

  • himata4113 7 hours ago ago

    I usually just box it and then Box::into_raw when I need multiple mutable references in a singlethreaded application where there's no deallocation or cleanup has to occur post shutdown.

  • Pesthuf 5 hours ago ago

    I wonder if this has any measurable impact on compile times.

  • space_ghost 7 hours ago ago

    This reminds me of Perl's ACME modules and I'm here for that.

  • codedokode 7 hours ago ago

    Macros can secretly add "unsafe" blocks into the code?

    • kibwen 6 hours ago ago

      If you're paranoid, you can use the `forbid(unsafe_code)` attribute, which will produce a compiler error when any code in its scope attempts to use `unsafe`, which includes macro expansions.

    • EFLKumo 6 hours ago ago

      Yes. It assumes author of the macro guarantees the safety. Common cases are not adding unsafe{} and leaving this to user, relying on audit tools or [highlighters](https://lukaswirth.dev/posts/semantic-unsafe/), etc. However, it's indeed allowed to silently add unsafe blocks in macros. I'm not working on rust frequently btw, mistakes may exist.

    • mplanchard 6 hours ago ago

      Macros are just text in, text out, so yep

      • estebank 6 hours ago ago

        Rust macros are Token Trees and provide namespace hygiene, so not quite "text in, text out".

        • 0x1ceb00da 4 hours ago ago

          Token list, not token trees. There are official libraries for parsing token stream as rust code but you can parse it as anything (eg json, html) if you want to.

        • mplanchard 3 hours ago ago

          You know, I was going to say tokens rather than text, but the AI discourse has me so burnt out on the term that I edited it. Regardless, one can emit unsafe blocks from a macro, provided they are valid tokens.

  • rurban 6 hours ago ago

    Even more unsafe rust, great!

  • orphea 7 hours ago ago

    Disgusting. I love it.