You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/e1.smart-compiler.md
+72-75Lines changed: 72 additions & 75 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,109 +3,106 @@ title: Smart Compiler
3
3
slug: smart-compiler
4
4
---
5
5
6
-
> [!caution]
7
-
> This needs a refresh!
6
+
## Compile-time Errors
8
7
9
-
## Why Compiler?
8
+
Rust focuses on strict code hygiene, and the compiler generates a highly specific set of warnings and errors to make it easier to identify and solve them.
10
9
11
-
The Rust compiler does the most significant job to prevent errors in Rust programs. It **analyzes the code at compile-time** and issues warnings, if the code does not follow memory management rules or lifetime annotations correctly.
10
+
### Typos
12
11
13
-
For example,
14
12
```rust
15
-
#[allow(unused_variables)] //💡 A lint attribute used to suppress the warning; unused variable: `b`
// ⭐ instead using #[allow(unused_variables)], consider using "let _b = a;" in line 4.
40
-
// Also you can use "let _ =" to completely ignore return values
62
+
implPerson {
63
+
fnintro(&self) {
64
+
println!("Hello! I am {} {}.", self.fname, self.lname)
65
+
}
66
+
}
41
67
```
42
68
43
-
> [!recap]
44
-
> In the previous sections, we have discussed memory management concepts like [ownership](/docs/ownership), [borrowing](/docs/borrowing), [lifetimes](/docs/lifetimes) and etc.
Above error messages are very descriptive and we can easily see where is the error. But while we can not identify the issue via the error message, **`rustc --explain`** commands help us **to identify the error type and how to solve** it, by showing **simple code samples** which express the same problem and the solution we have to use.
98
+
## Error Codes
80
99
81
-
For example, `rustc --explain E0571` shows the following output in the console.
100
+
- Rust's error codes consist of the letter **E** followed by four digits.
101
+
- Each code corresponds to a specific kind of error, and `rustc --explain <CODE>` provides more details to help to identify the error.
102
+
- The same explanations are also available in the [Rust Error Codes Index](https://doc.rust-lang.org/error_codes/error-index.html).
82
103
83
-
```rust
84
-
A `break` statementwithanargumentappearedinanon-`loop` loop.
104
+
For example, `rustc --explain E0571` shows the following output in the console, and the same content is also available at https://doc.rust-lang.org/error_codes/E0571.html.
85
105
86
-
Exampleoferroneouscode:
87
-
```
88
-
letresult=whiletrue {
89
-
ifsatisfied(i) {
90
-
break2*i; // error: `break` with value from a `while` loop
91
-
}
92
-
i+=1;
93
-
};
94
-
```
95
-
96
-
The `break` statementcantakeanargument (whichwillbethevalueoftheloop
97
-
expressionifthe `break` statementisexecuted) in `loop` loops, butnot
💡 Also you can read the same explanations via [Rust Compiler Error Index](https://doc.rust-lang.org/error_codes/error-index.html). For example to check the explanation of `E0571` error, you can use https://doc.rust-lang.org/error-index.html#E0571.
0 commit comments