Errors and fixes
How to read a Peeper error, and which ones peeper fix applies for you.
Every error on this page is what peeper check printed for a small program.
Reading an error
[T0039]: `value` is used before it is set --> src/main.peep:6:12 | 1 | fn pick(flag: bool) -> i32 {2 | let value: i32; | ----- declared here without a value...5 | }6 | return value; | ^^^^^ `value` is not set on every path to here | = help: set `value` on every path before this use, or give it a value where it is declaredCompilation failed with 1 error(s)- The first line gives the code and what is wrong.
-->gives the file, line and column.- The labels under the code point at each place that matters. Here they
show where
valuewas declared and where it is read. = note:explains the rule, and= help:suggests a change.
The code's letter
The letter says which part of the compiler found the problem:
| Letter | Found while |
|---|---|
L | reading the characters of the file |
P | parsing the code into a tree |
M | resolving modules and imports |
T | checking types, paths, moves and borrows |
W | looking for likely mistakes: a warning, not an error |
Fixes
Some errors carry a fix, marked = fix:, with the changed line under it and
the new text highlighted. peeper fix applies these fixes to your files, and
an editor offers them as quick fixes.
[P0002]: expected `;`, found `println` --> src/main.peep:2:22 | 1 | fn main() {2 | let total = 1 + 2 | ^ | = fix: add missing `;` | 2 | let total = 1 + 2;Compilation failed with 1 error(s)[T0001]: mismatched types: expected `i32`, found `&i32` --> src/main.peep:4:18 | 3 | let r = &n;4 | let m: i32 = r; | ^ | = fix: add `.*` to use the value it points to | 4 | let m: i32 = r.*;Compilation failed with 1 error(s)fixed src/main.peep:4:19: add `.*` to use the value it points toA = help: line is only a suggestion, and peeper fix leaves it to you. A
guess at a mistyped name is one:
[T0002]: unknown name `totla` --> src/main.peep:3:23 | 2 | let total = 3;3 | println("total:", totla); | ^^^^^ | = help: did you mean `total`? | 3 | println("total:", total);Compilation failed with 1 error(s)More errors
A function that can end without returning its value:
[T0017]: not all control paths return a value --> src/main.peep:2:8 | 1 | fn sign(n: i32) -> i32 {2 | if n > 0 { | ^^^^^ if this is false, nothing is returned...4 | }5 | } | - function ends without returning `i32` | = note: execution can reach the end of the function without a `return` = help: add a `return` at the end of the function, or make each path shown return a valueCompilation failed with 1 error(s)The other pages show errors where their rules come up:
assigning without mut,
narrowing a number,
an index out of bounds,
using a moved value,
overlapping borrows and
a private name.