Performance lints

If you are reading this book, these two lints will probably be the ones you will find more important than the ones Clippy does not warn by default. The first is pretty simple: if you want to share an integer between threads, using a Mutex is a really bad idea if you do not need to use it as a synchronization variable.

Usually, things such as counters will be much faster by using atomic types. Only pointer-sized atomics and booleans are stable at the time of writing, but the rest are also coming and can now be used in nightly Rust. You can spot this issue with the mutex_integer lint.

Also, you might be tempted to use std::mem::forget() to enable sending data to C APIs, or to be able to do some strange memory tricks. This can be fine (even though it can lead to memory leaks), but can sometimes prevent running destructors. If you want to make sure that your Drop types never get forgotten, use the mem_forget lint.

If you are worried about infinite iterators that could hang your applications, you should use the maybe_infinite_iter lint, which will find those. It will not detect stopping conditions, so it could show too many false positives.

We might also find ourselves adding debug information when developing by using print!() macros and debug formatting. Once the application goes into production, a good way to avoid these logs staying in the code base is to use the print_stdout and use_debug lints.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.235.219