3 ms·
you_can::turn_off_the_borrow_checker
- orphea 5mo agoDisgusting. I love it.
- himata4113 5mo agoI 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.
- space_ghost 5mo agoThis reminds me of Perl's ACME modules and I'm here for that.
- tmtvl 5mo agoI would go for a Rust version of Acme::Bleach.
- deleted 5mo ago[deleted]
- codedokode 5mo agoMacros can secretly add "unsafe" blocks into the code?
- mplanchard 5mo agoMacros are just text in, text out, so yep
- estebank 5mo agoRust macros are Token Trees and provide namespace hygiene, so not quite "text in, text out".
- 0x1ceb00da 5mo agoToken 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.
- estebank 5mo agoI think you meant TokenStream. They are trees, behind the scenes, because matching delimiters happens early on between lexing and parsing. By the time the rustc_proc_macro::TokenStream is exposed, the rustc_ast::tokenstream::TokenTree is hidden to the proc macro API. https://doc.rust-lang.org/stable/nightly-rustc/rustc_ast/tokenstream/index.html https://doc.rust-lang.org/stable/nightly-rustc/rustc_ast/tok... https://doc.rust-lang.org/stable/nightly-rustc/rustc_proc_macro/struct.TokenStream.html https://doc.rust-lang.org/stable/nightly-rustc/rustc_proc_ma...
- mplanchard 5mo agoYou 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.
- EFLKumo 5mo agoYes. 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/ 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.
- kibwen 5mo agoIf 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 5mo agothough 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 5mo agoI 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 5mo agoThat 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 5mo agoit'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.
- extraduder_ire 5mo agoCool 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.
- rurban 5mo agoEven more unsafe rust, great!
- tempesttempo86 5mo agoArbitrary mention: Crust[0] [0] https://github.com/tsoding/crust https://github.com/tsoding/crust
- nextaccountic 5mo agoWow, it really do look like C https://github.com/bext-lang/b/blob/main/src/bgen.rs https://github.com/bext-lang/b/blob/main/src/bgen.rs
- Pesthuf 5mo agoI wonder if this has any measurable impact on compile times.
- wasmperson 5mo agoRust's memory safety is as much a social convention as it is a language feature. The language has something better described as "mutation safety," and it's the job of library developers to use that to design UB-free APIs. I think many people understand this subconsciously, and that this is what drives some of the more performative security culture in Rust spaces (superfluous safety comments, shunning of certain crate authors, `forbid(unsafe)`, push-back against syntax sugar, etc.).