Start with the idea
When rustc rejects a program, begin at the highlighted source span. The message usually names what type was expected and what expression was actually found. In the example, count is annotated u32, while "four" is text; the compiler cannot turn that word into an unsigned integer by guessing. The primary span points to the conflicting value. Nearby labels and notes explain how the expectation was established, and a help message may suggest an operation. Treat suggestions as evidence, not commands: first decide what the program should mean.
If the count should be four, replace the text with the numeric literal 4. If the user really supplies text, parsing is a separate, fallible step that returns a Result and needs error handling. Those are different programs. Fix the earliest causal mismatch and compile again before chasing a long list of later messages; one root error can make downstream expressions appear broken.
Keep learning, for free
The rest of this lesson is waiting for you.
Create a free account to read the complete explanation, see the infographic, explore the code, and try the exercises. All 742 lessons and algorithm steps are included.
No payment details. Your account opens the complete Academy.