Originally posted by cardich
View Post
There are many write up on the topic its not speculations. There are many memory handling errors you can code in C that rust simple will not allow without jumping though a lot of hoops. The reason why rust will not allow is the language has extra information that you must include or it not valid rust that can be processed to validate memory operations. Yes that extra information can be include in C/C++ but you normal C/C++ compliers don't process it or mandate it.
More cases with rust will fail at compiler of source file to object than what C and C++ will. You see more cases be detected when you use LTO with gcc or llvm than without but this is still not as many cases as rust can detect due to language mandating more information about memory usage.
error[E0106]: missing lifetime specifier << yes errors like this in the example on that site are about lack of information that happened when they did a 1 to 1 C to rust conversion. This is something you find doing a 1 to 1 C to rust conversion in lot of cases will result in the rust compiler yell at you that you have missed declaring important things about how memory will be used. Without how the memory will be used information the compiler really cannot make correct judgement calls when you are doing source file to object file and when doing complete Link time optimization you are doing lot of processing to calculate this missing information to attempt to reduce C/C++ memory issues.
Lot of the information that rust language mandates can be calculated(take this a computer guessed) by complete program analysis. Please note this is a lot more processing to work out that hey I missed allocating X correctly so this is going to segfault or other memory fault.
Rust language is you must declare more about how memory will be used resulting in the rust compiler being able to be pick up defects with less processing.
Please note attempt since calculation of the missing information is not right all the time there are defects with C/C++ programs that get past that will not happen with rust as simply.
Do take into account I am not saying that rust is perfect. C and C++ language standards could be extended to mandate programmers include the extra information in future that the issues rust detects are detectable by a C/C++ compiler at the same stages but this would also be a backwards compatibility breaking change.
Comment