Unlikely in the foreseeable future. If either C++ compiler or tooling around it (linters/static analysis) catches up with Rust compiler in terms of race condition/lifetime guarantees, then there is no chance of Rust replacing C++. Now how possible this is, I am not sure.
Not really possible. And, even if it got close, the difference between having these things caught immediately during compile vs. having to run a 10 minute analysis pass to hope to catch close to the same amount of issues is huge. It will always be a band-aid with C++.
The problem is not so much that the STL implementation would have to be unsafe, it's that using the STL would be unsafe.
Consider the following, extremely simplistic, example:
auto x = std::find(begin, end, y);
In order to be safe, this example requires that [begin, end) be a valid range, which means:
begin and end are iterators into the same container, or pointers into the same memory allocation.
end is reachable from begin.
Good luck proving those properties, (1) notably essentially require dependent types (which neither C++ nor Rust feature).
Another example:
std::map<int, std::string> map{
{ 0, "Hello, eyes-are-fading-blue! Are you a fremen?" }
}};
auto x = map[0].c_str();
// Safe
map[1] = "Fiesta!";
std::cout << x << "\n";
// Unsafe
map[0] = "Another one bites the dust!"s;
std::cout << x << "\n";
The very guarantee of pointer-stability when inserting in a map has to be revisited.
And it holds doubly true for unordered_map, where it's conditional on the absence of re-hashing.
The effects of borrow-checking are so pervasive to for programs to conform to borrow-checking, you have to design the entire application stack with borrow-checking in mind from the ground-up.
This means throwing away the STL as we know, and adopting a new standard library, for example modeled after Rust's.
11
u/eyes-are-fading-blue Dec 07 '21
Unlikely in the foreseeable future. If either C++ compiler or tooling around it (linters/static analysis) catches up with Rust compiler in terms of race condition/lifetime guarantees, then there is no chance of Rust replacing C++. Now how possible this is, I am not sure.