Can you give me example of a normal C++ code where compiler and/or language will not guarantee safety? Let's put aside UBs, because they are everything but normal code.
Can you give me example of a normal C++ code where compiler and/or language will not guarantee safety? Let's put aside UBs, because they are everything but normal code.
An easy way to trigger undefined behavior in C++ is by using a pointer after the thing it's pointing to has been freed. Doing this in a process that takes any user input can easily create a vulnerability that allows an attacker to inject code into the process. There are many ways to accidentally do this while thinking you're safe. A pointer to an item inside a data structure like a vector or hash table is dangerous if you use it after some items may have been inserted into the data structure, because inserts can cause the data structure to reallocate and expand its backing memory. This mistake can easily go unnoticed for a long time because only a small fraction of inserts will cause that. This mistake isn't possible to make in safe Rust.
Almost all C++ code interacts with bare pointers at some point. And that’s just one of the places where you get into issues with safety.
You can also run into problems with iterators being invalidated: your iterator into a std::vector is no longer valid after a call to push_back().
Anything that stores a reference and can exist after the lifetime of the object, really. Lambdas are a problem here. But so are instances with reference members.
C++ is littered with these things.
This is a device driver. If it has to talk to memory-mapped hardware, that's a raw pointer, inherently, inevitably.
Other things are language issues, and can be solved by changing languages, but raw pointers are inherent in the task.
This is an IPC "device driver". It does not talk to any hardware, it's used to pass messages between processes.
It's not, it's an IPC subsystem. It doesn't talk to any hardware.
Why would you avoid saying that? Rust does give guarantees: about memory safety and concurrency primarily, but also regarding the lack of undefined behavior.
> It paints Rust as this magical thing that will solve anything.
It does not, the above are not magical they are just challenging problems (although at some point they may have been deemed impossible problems and hence magical, I don't know)
> My preferred explanation is that Rust provides better tools to build wrappers that can't be misused.
"wrappers that can't be misused" sounds a LOT like it "gives guarantees".
* you will not be able to compile undefined behavior
* you will not be able to create a data race
* a shared reference is read-only
* you cannot write past the end of an array
There are others, but those are pretty big ones that both guarantees and part of the language itself, independent of stdlib.