…and the journey to getting better code automatically
Pascal Hertleif
2018-02-04
error[E0507]: cannot move out of borrowed content
--> src/lib.rs:126:29
|
126 | if let Some(code) = diagnostic.code {
| ---- ^^^^^^^^^^ cannot move out of borrowed content
| |
| hint: to prevent move, use `ref code` or `ref mut code`
Rust is all about compile-time checks
But also: Rust’s errors are pretty and helpful
Result
s or Iterator
sIt looks like you’re enjoying errors. Would you like some more?
if_same_then_else
iter.filter(|x| x == 0).next()
Did you know about iter.find(|x| x == 0)
?
if !m.contains_key(&k) { m.insert(k, v) }
Have you heard the good news about the Entry API?
m.entry(k).or_insert(v);
error: this range is empty so this for loop will never run
--> $DIR/for_loop.rs:148:14
|
148 | for i in 10..0 {
| ^^^^^
|
= note: `-D reverse-range-loop` implied by `-D warnings`
help: consider using the following if you are attempting to iterate over this range in reverse
|
148 | for i in (0..10).rev() {
| ^^^^^^^^^^^^^
I’m sold. These suggestions are great. But…
No magic! Just:
rustfix as CLI tool is interactive
You need to manually call the CLI tool
You do that after working on the code
We can do better
Laptop didn’t work?
Totally saw that coming.
– Past Me
Search for “Rust Clippy” or go to https://github.com/rust-lang-nursery/rust-clippy
There are a lot of issues labelled good first issue
You get to call yourself a compiler hacker!
Visit rust-lang.org
Follow me on Twitter: @killercup
Slides available at git.io/fosdem-rustfix