Skip to content

Commit

Permalink
markdownlint
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsan committed Jan 6, 2021
1 parent 39c9555 commit eaa9e0a
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions anti_patterns/borrow_clone.md
Expand Up @@ -4,11 +4,10 @@

The borrow checker prevents Rust users from developing otherwise unsafe code by
ensuring that either: only one mutable reference exists, or potentially many but
all immutable references exist. If the code written does not hold true to these
all immutable references exist. If the code written does not hold true to these
conditions, this anti-pattern arises when the developer resolves the compiler
error by cloning the variable.


## Example

```rust
Expand All @@ -28,7 +27,6 @@ let y = &mut (x.clone());
println!("{}", x);
```


## Motivation

It is tempting, particularly for beginners, to use this pattern to resolve
Expand All @@ -48,8 +46,7 @@ that's a good indication this anti-pattern may be in use.
If an unnecessary clone is suspected, The Rust Book's chapter on Ownership
should be understood fully before assessing whether the clone is required or not.


## See also

[The Rust Book: Ownership, which describes how the borrow checker behaves](https://doc.rust-lang.org/book/ownership.html)
[Rc<T> documentation, which handles .clone() intelligently](http://doc.rust-lang.org/std/rc/)
[`Rc<T>` documentation, which handles .clone() intelligently](http://doc.rust-lang.org/std/rc/)

0 comments on commit eaa9e0a

Please sign in to comment.