about summary refs log tree commit diff
path: root/src/test/codegen/iter-fold-closure-no-iterator.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-08-15 04:24:29 +0000
committerbors <bors@rust-lang.org>2019-08-15 04:24:29 +0000
commit1cdcea920e56a5d0587307a4c9cf8fff5c77c4bc (patch)
treeccb6b9be0ea3d973f4e0808ef6f7c11bebf52a9b /src/test/codegen/iter-fold-closure-no-iterator.rs
parent9e9a136fcec5eb78f09a14dfd072a51ae2550269 (diff)
parentbca6f28f7f7a6db3416c0d4e631a7a4cc1072cf7 (diff)
downloadrust-1cdcea920e56a5d0587307a4c9cf8fff5c77c4bc.tar.gz
rust-1cdcea920e56a5d0587307a4c9cf8fff5c77c4bc.zip
Auto merge of #62429 - cuviper:iter-closures, r=cramertj
Reduce the genericity of closures in the iterator traits

By default, closures inherit the generic parameters of their scope,
including `Self`. However, in most cases, the closures used to implement
iterators don't need to be generic on the iterator type, only its `Item`
type. We can reduce this genericity by redirecting such closures through
local functions.

This does make the closures more cumbersome to write, but it will
hopefully reduce duplication in their monomorphizations, as well as
their related type lengths.
Diffstat (limited to 'src/test/codegen/iter-fold-closure-no-iterator.rs')
-rw-r--r--src/test/codegen/iter-fold-closure-no-iterator.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/test/codegen/iter-fold-closure-no-iterator.rs b/src/test/codegen/iter-fold-closure-no-iterator.rs
new file mode 100644
index 00000000000..fbeafd5f395
--- /dev/null
+++ b/src/test/codegen/iter-fold-closure-no-iterator.rs
@@ -0,0 +1,10 @@
+//! Check that fold closures aren't generic in the iterator type.
+// compile-flags: -C opt-level=0
+
+fn main() {
+    (0i32..10).by_ref().count();
+}
+
+// `count` calls `fold`, which calls `try_fold` -- that `fold` closure should
+// not be generic in the iterator type, only in the item type.
+// CHECK-NOT: {{^define.*Iterator::fold::.*closure.*Range}}