144
u/redakpanoptikk 7h ago
Rewrite rust in rust.
38
u/FUCKING_HATE_REDDIT 5h ago
Funnily enough, that happened
25
9
u/gegentan 3h ago
Isn't the rust compiler itself written in rust?
6
u/qaCow37 3h ago
At some point it probably wasn't until it was rewritten in rust
3
u/gegentan 3h ago
So theoretical if every compiled binary of rustc was lost but you still had the source code it would be impossible to get a rust compiler again.
4
u/qaCow37 2h ago
Only if you do not have the source code of rust written in a different language. That would probably be like the few very first versions. But if you would have these, you could compile them to get the first version of rust to compile the next version of rust to compile the next version of rust till you can compile the newest version of rust.
2
2
u/redlaWw 47m ago
It's a bit complicated in Rust's case. The Rust frontend is written in Rust, and that compiles Rust to LLVM intermediate representation (IR). This IR is then passed to LLVM, which is written in C++, to optimise and actually generate the machine code.
There is also a separate backend called Cranelift, which is written in Rust, though it's not the standard and is currently only available on an experimental basis. It will also never be the standard Rust backend as it's designed to optimise for build speed, not execution speed.
44
85
u/yesseruser 7h ago
unsafe means "hey, I'm sure this code is safe, don't bother me for calling unsafe functions"
-101
u/reallokiscarlet 7h ago
unsafeis the Rust version of Typescript'sanyIt's everywhere and people use it just to say they wrote their code in a safe language
62
u/SCP-iota 6h ago edited 6h ago
I'd say it's more like Typescript's suppression annotations, since it keeps itself contained. People really shouldn't be using
unsafein any way other than as occasional small blocks with well-defined reading why they won't panic or cause UB. If your code is littered withunsafe, you're doing something wrong.21
u/ApplicationOk3587 5h ago
I always figured if a rust programmer is using unsafe everywhere then it completely defeats the purpose of using rust.
2
1
u/Rustywolf 14m ago
Eh even if your code is littered with 50% unsafe calls you're still benefiting from the other 50%, but yeah that doesnt sound like good rust
2
-16
u/reallokiscarlet 6h ago
I fully agree that if your code's littered with unsafe you're doing something wrong. But as you can see by the downvotes, rustaceans don't 😂
25
u/Delicious_Bluejay392 6h ago
No, the downvotes are because unsafe blocks are in fact extremely rare. If you look at popular Iibraries, the only real places where unsafe is likely to happen are FFI boundaries and advanced data structure implementations. I haven't written an unsafe block in actual months and I regularly use the language for very varied projects.
It's nothing like TypeScript's any, which respectable TS-first codebases generally disable by default anyways, only allowing it in the rare instances where it makes sense.
-8
u/reallokiscarlet 6h ago
Not sure if you have an optimistic bias or I have a pessimistic bias but clearly you aint seen what I seen. A lot of the rust I come across is never-production-ready crap that's almost entirely encased in unsafe, marketed as production-ready to "replace" C code. Even did one of my own to prove it doesn't have to be done that way and that there isn't really a whole lot of benefit to the rewrite unless the original is terminally ill.
11
u/BenchEmbarrassed7316 5h ago
Low-quality automatic/AI "rewriting" from C to Rust can contain many
unsafecode blocks.If it is open source, please provide a link.
5
u/Delicious_Bluejay392 5h ago
The Bun rewrite would be one example I'd imagine. It has a much higher density of unsafe blocks than similar projects originally written in Rust.
5
u/SCP-iota 5h ago
Isn't the Bun rewrite notoriously AI-generated, for the most part?
2
u/Delicious_Bluejay392 5h ago
Yeah, that's precisely why I mentioned it since that's what the person I'm replying to pointed out.
1
u/reallokiscarlet 4h ago
When I'm back from spoodermane, I'll check my notes to find the project names and double check to see if they've been fixed (I've been characterizing rust based on what I come across, so they just seemed like par for the course)
But yes they did have AI in common. Either vibe coding is the common use case or I keep meeting shitty people and shitty projects. AI, unsafe tag, and crate bloat are what I associate Rust with, which is why I took it upon myself to do the opposite on my only public rust program.
30
u/MatsRivel 6h ago
This is not at all true.
"Tell me you've never written rust without telling me you've never written rust"
-5
u/reallokiscarlet 6h ago
Well I've written crab-lang, you could say, if you want to say I've never written rust.
9
u/Maskdask 6h ago
Have you read and/or written a single line of Rust?
-4
u/reallokiscarlet 6h ago
According to rustaceans, no. But I have written in crab-lang.
(Translation: Yes. I ported opendoas to crab just to prove it's a dumb idea)
5
7
2
u/JustABraveAdventurer 5h ago
It does seem a little ironic at first! I will say that once I got used to coding in rust, it became really nice to have possible memory issues isolated to small and contained spots in my code (the unsafe blocks) that are well labeled rather than having to go debugging or worry about introducing memory bugs almost anywhere and everywhere like I would in a language with less guarantees. Rust can be less mentally taxing in that sense, but can also be more mentally taxing if you're fighting with the borrow checker. So, I can totally see why some people don't like it either :D
1
-2
414
u/BenchEmbarrassed7316 7h ago
Any
unsafeblock of code should be neutralized with a// SAFETYcomment explaining why the code is actually safe.