diff options
Diffstat (limited to 'src/docs')
| -rw-r--r-- | src/docs/box_default.txt | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/docs/box_default.txt b/src/docs/box_default.txt new file mode 100644 index 00000000000..ffac894d0c5 --- /dev/null +++ b/src/docs/box_default.txt @@ -0,0 +1,23 @@ +### 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). + +### Known problems +The lint may miss some cases (e.g. Box::new(String::from(""))). +On the other hand, it will trigger on cases where the `default` +code comes from a macro that does something different based on +e.g. target operating system. + +### Example +``` +let x: Box<String> = Box::new(Default::default()); +``` +Use instead: +``` +let x: Box<String> = Box::default(); +``` \ No newline at end of file |
