Skip to content

Commit c938ba5

Browse files
liamzdeneksimonsan
authored andcommitted
Small changes per feedback on the PR
1 parent 93ba9a5 commit c938ba5

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

anti_patterns/borrow_clone.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Description
44

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
66
ensuring that either: only one mutable reference exists, or potentially many but
77
all immutable references exist. If the code written does not hold true to these
88
conditions, this anti-pattern arises when the developer resolves the compiler
@@ -11,22 +11,21 @@ error by cloning the variable.
1111

1212
## Example
1313

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);
3029
```
3130

3231

0 commit comments

Comments
 (0)