3 ms·
You could just use cargo-geiger and #![forbid(unsafe_code)] in order to only have safe code. We use this in our CI/CD in order to ensure that no unsafe code is
by satvikpendem 4y ago
You could just use cargo-geiger and #![forbid(unsafe_code)] in order to only have safe code. We use this in our CI/CD in order to ensure that no unsafe code is used.
- oconnor663 4y agoI replied to a related comment here: https://news.ycombinator.com/item?id=35034184 https://news.ycombinator.com/item?id=35034184
- lordnacho 4y agoWhat happens if you find unsafe deeply nested in some dependency that you need? Like a web framework or maybe a graphics engine that's not so easy to find a replacement for?
- satvikpendem 4y agoWell, the simple answer is you don't use it. The more complex answer is that you do use it but have safe guards in place, which `unsafe` does to some extent even more than C or C++ code. You could also ask the creators of said dependencies why there is `unsafe` in their code and perhaps submit PRs to mitigate or remove that, as in the case of actix-web a few years ago. But as Rust crates become more prevalent, I do expect that we'll see fewer and fewer crates with `unsafe`, or have enough safe alternatives to `unsafe` crates.
- firstlink 4y ago> you do use it but have safe guards in place Isn't this the same thing that everyone else is doing, except they're not pretending to be special by falsely claiming that they're using no unsafe? My impression of `forbid(unsafe)` users in practice is that they think they've cleverly discovered a way to encapsulate unsafe that everyone else is missing, when in fact they've missed the point of unsafe to begin with and then belatedly rediscovered it.
- satvikpendem 4y agoI'm not sure what you're referring to with your 2 sentences exactly. What is "the same thing that everyone else is doing?" And what does this mean: "they've cleverly discovered a way to encapsulate unsafe that everyone else is missing, when in fact they've missed the point of unsafe to begin with and then belatedly rediscovered it?"
- theobeers 4y agoI have a library in which I set #![forbid(unsafe_code)]. It relies on a small number of carefully chosen dependencies, almost all of which contain unsafe code. I mean first-rate libraries like bincode, bstr, and once_cell. It feels a bit disingenuous for me to emphasize the safety of the top layer that I've written. I guess what I can actually express is that I'm setting risk boundaries and, in a way, taking myself out of the equation.
- satvikpendem 4y agoThat's why cargo-geiger exists.