]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/rc_buffer.txt
Auto merge of #104673 - matthiaskrgr:rollup-85f65ov, r=matthiaskrgr
[rust.git] / src / tools / clippy / src / docs / rc_buffer.txt
1 ### What it does
2 Checks for `Rc<T>` and `Arc<T>` when `T` is a mutable buffer type such as `String` or `Vec`.
3
4 ### Why is this bad?
5 Expressions such as `Rc<String>` usually have no advantage over `Rc<str>`, since
6 it is larger and involves an extra level of indirection, and doesn't implement `Borrow<str>`.
7
8 While mutating a buffer type would still be possible with `Rc::get_mut()`, it only
9 works if there are no additional references yet, which usually defeats the purpose of
10 enclosing it in a shared ownership type. Instead, additionally wrapping the inner
11 type with an interior mutable container (such as `RefCell` or `Mutex`) would normally
12 be used.
13
14 ### Known problems
15 This pattern can be desirable to avoid the overhead of a `RefCell` or `Mutex` for
16 cases where mutation only happens before there are any additional references.
17
18 ### Example
19 ```
20 fn foo(interned: Rc<String>) { ... }
21 ```
22
23 Better:
24
25 ```
26 fn foo(interned: Rc<str>) { ... }
27 ```