Lint

C/C++ compilers can issue many useful warnings but the amount of static analysis they can do is usually quite limited.

The Rust compiler performs a far more rigorous lifecycle check on data and then follows up with a lint check that inspects your code for potentially bad or erroneous

In particular it looks for:

  • Dead / unused code
  • Unreachable code
  • Deprecated methods
  • Undocumented functions
  • Camel case / snake case violations
  • Unbounded recursion code (i.e. no conditionals to stop recursion)
  • Use of heap memory when stack could be used
  • Unused extern crates, imports, variables, attributes, mut, parentheses
  • Using “while true {}” instead of “loop {}”

Lint rules can be enforced more strictly or ignored by using attributes:

1. #[allow(rule)]
2. #[warn(rule)]
3. #[deny(rule)]
4. #[forbid(rule)]

A full list of lint rules can be found by typing “rustc -W help”:

1. name  default  meaning
2. ----  -------  -------
3. box-pointers   allow    use of owned (Box type) heap memory
4. fat-ptr-transmutes  allow    detects transmutes of fat pointers
5. missing-copy-implementations  allow    detects potentially-forgotten implementations of `Copy`
6. missing-debug-implementations  allow    detects missing implementations of fmt::Debug
7. missing-docs  allow    detects missing documentation for public members
8. trivial-casts  allow    detects trivial casts which could be removed
9. trivial-numeric-casts  allow    detects trivial casts of numeric types which could be removed
10. unsafe-code  allow    usage of `unsafe` code
11. ...

There are a lot checks than are listed here.