File tree 1 file changed +16
-17
lines changed 1 file changed +16
-17
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## Description
4
4
5
- The borrow checker prevents rust users from developing otherwise unsafe code by
5
+ The borrow checker prevents Rust users from developing otherwise unsafe code by
6
6
ensuring that either: only one mutable reference exists, or potentially many but
7
7
all immutable references exist. If the code written does not hold true to these
8
8
conditions, this anti-pattern arises when the developer resolves the compiler
@@ -11,22 +11,21 @@ error by cloning the variable.
11
11
12
12
## Example
13
13
14
- ``` rust fn main() {
15
- // define any variable
16
- let mut x = 5 ;
17
-
18
- // Borrow `x` -- but clone it first
19
- let y = & mut (x . clone ());
20
-
21
- // perform some action on the borrow to prevent rust from optimizing this
22
- // out of existence
23
- * y += 1 ;
24
-
25
- // without the x.clone() two lines prior, this line would fail on compile as
26
- // x has been borrowed
27
- // thanks to x.clone(), x was never borrowed, and this line will run.
28
- println! (" {}" , x );
29
- }
14
+ ``` rust
15
+ // define any variable
16
+ let mut x = 5 ;
17
+
18
+ // Borrow `x` -- but clone it first
19
+ let y = & mut (x . clone ());
20
+
21
+ // perform some action on the borrow to prevent rust from optimizing this
22
+ // out of existence
23
+ * y += 1 ;
24
+
25
+ // without the x.clone() two lines prior, this line would fail on compile as
26
+ // x has been borrowed
27
+ // thanks to x.clone(), x was never borrowed, and this line will run.
28
+ println! (" {}" , x );
30
29
```
31
30
32
31
You can’t perform that action at this time.
0 commit comments