]> git.lizzy.rs Git - rust.git/blob - src/docs/borrowed_box.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / borrowed_box.txt
1 ### What it does
2 Checks for use of `&Box<T>` anywhere in the code.
3 Check the [Box documentation](https://doc.rust-lang.org/std/boxed/index.html) for more information.
4
5 ### Why is this bad?
6 A `&Box<T>` parameter requires the function caller to box `T` first before passing it to a function.
7 Using `&T` defines a concrete type for the parameter and generalizes the function, this would also
8 auto-deref to `&T` at the function call site if passed a `&Box<T>`.
9
10 ### Example
11 ```
12 fn foo(bar: &Box<T>) { ... }
13 ```
14
15 Better:
16
17 ```
18 fn foo(bar: &T) { ... }
19 ```