diff options
Diffstat (limited to 'src/tools/clippy/src/docs/box_default.txt')
-rw-r--r-- | src/tools/clippy/src/docs/box_default.txt | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/tools/clippy/src/docs/box_default.txt b/src/tools/clippy/src/docs/box_default.txt new file mode 100644 index 000000000..1c670c773 --- /dev/null +++ b/src/tools/clippy/src/docs/box_default.txt @@ -0,0 +1,17 @@ +### What it does +checks for `Box::new(T::default())`, which is better written as +`Box::<T>::default()`. + +### Why is this bad? +First, it's more complex, involving two calls instead of one. +Second, `Box::default()` can be faster +[in certain cases](https://nnethercote.github.io/perf-book/standard-library-types.html#box). + +### Example +``` +let x: Box<String> = Box::new(Default::default()); +``` +Use instead: +``` +let x: Box<String> = Box::default(); +```
\ No newline at end of file |