summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/redundant_closure.txt
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:03:36 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:03:36 +0000
commit17d40c6057c88f4c432b0d7bac88e1b84cb7e67f (patch)
tree3f66c4a5918660bb8a758ab6cda5ff8ee4f6cdcd /src/tools/clippy/src/docs/redundant_closure.txt
parentAdding upstream version 1.64.0+dfsg1. (diff)
downloadrustc-upstream/1.65.0+dfsg1.tar.xz
rustc-upstream/1.65.0+dfsg1.zip
Adding upstream version 1.65.0+dfsg1.upstream/1.65.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/src/docs/redundant_closure.txt')
-rw-r--r--src/tools/clippy/src/docs/redundant_closure.txt25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/tools/clippy/src/docs/redundant_closure.txt b/src/tools/clippy/src/docs/redundant_closure.txt
new file mode 100644
index 000000000..0faa9513f
--- /dev/null
+++ b/src/tools/clippy/src/docs/redundant_closure.txt
@@ -0,0 +1,25 @@
+### What it does
+Checks for closures which just call another function where
+the function can be called directly. `unsafe` functions or calls where types
+get adjusted are ignored.
+
+### Why is this bad?
+Needlessly creating a closure adds code for no benefit
+and gives the optimizer more work.
+
+### Known problems
+If creating the closure inside the closure has a side-
+effect then moving the closure creation out will change when that side-
+effect runs.
+See [#1439](https://github.com/rust-lang/rust-clippy/issues/1439) for more details.
+
+### Example
+```
+xs.map(|x| foo(x))
+```
+
+Use instead:
+```
+// where `foo(_)` is a plain function that takes the exact argument type of `x`.
+xs.map(foo)
+``` \ No newline at end of file