Skip to content

Commit 755c091

Browse files
committed
Add codegen tests for the genericity of fold closures
1 parent 6a04c76 commit 755c091

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//! Check that fold closures aren't duplicated for each iterator type.
2+
// compile-flags: -C opt-level=0
3+
4+
fn main() {
5+
(0i32..10).by_ref().count();
6+
(0i32..=10).by_ref().count();
7+
}
8+
9+
// `count` calls `fold`, which calls `try_fold` -- find the `fold` closure:
10+
// CHECK: {{^define.*Iterator::fold::.*closure}}
11+
//
12+
// Only one closure is needed for both `count` calls, even from different
13+
// monomorphized iterator types, as it's only generic over the item type.
14+
// CHECK-NOT: {{^define.*Iterator::fold::.*closure}}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//! Check that fold closures aren't generic in the iterator type.
2+
// compile-flags: -C opt-level=0
3+
4+
fn main() {
5+
(0i32..10).by_ref().count();
6+
}
7+
8+
// `count` calls `fold`, which calls `try_fold` -- that `fold` closure should
9+
// not be generic in the iterator type, only in the item type.
10+
// CHECK-NOT: {{^define.*Iterator::fold::.*closure.*Range}}

0 commit comments

Comments
 (0)