Skip to content

Commit 792d2ce

Browse files
committed
Add codegen test to be sure we get rid of uneeded clones after monomorphization
1 parent ddd744b commit 792d2ce

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

rustfmt.toml

+1
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@ ignore = [
5757

5858
# Rustfmt doesn't support use closures yet
5959
"tests/mir-opt/ergonomic-clones/closure.rs",
60+
"tests/codegen/ergonomic-clones/closure.rs",
6061
]
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//@ compile-flags: -C no-prepopulate-passes -Copt-level=0 -Zmir-opt-level=0
2+
3+
#![crate_type = "lib"]
4+
5+
#![feature(ergonomic_clones)]
6+
#![allow(incomplete_features)]
7+
8+
use std::clone::UseCloned;
9+
10+
pub fn ergonomic_clone_closure_move() -> String {
11+
let s = String::from("hi");
12+
13+
// CHECK-NOT: ; call core::clone::impls::<impl core::clone::Clone for String>::clone
14+
let cl = use || s;
15+
cl()
16+
}
17+
18+
#[derive(Clone)]
19+
struct Foo;
20+
21+
impl UseCloned for Foo {}
22+
23+
pub fn ergonomic_clone_closure_use_cloned() -> Foo {
24+
let f = Foo;
25+
26+
// CHECK: ; call <closure::Foo as core::clone::Clone>::clone
27+
let f1 = use || f;
28+
29+
// CHECK: ; call <closure::Foo as core::clone::Clone>::clone
30+
let f2 = use || f;
31+
32+
f
33+
}
34+
35+
pub fn ergonomic_clone_closure_copy() -> i32 {
36+
let i = 1;
37+
38+
// CHECK-NOT: ; call core::clone::impls::<impl core::clone::Clone for i32>::clone
39+
let i1 = use || i;
40+
41+
// CHECK-NOT: ; call core::clone::impls::<impl core::clone::Clone for i32>::clone
42+
let i2 = use || i;
43+
44+
i
45+
}
46+
47+
pub fn ergonomic_clone_closure_use_cloned_generics<T: UseCloned>(f: T) -> T {
48+
// CHECK-NOT: ; call core::clone::impls::<impl core::clone::Clone for i32>::clone
49+
let f1 = use || f;
50+
51+
// CHECK-NOT: ; call core::clone::impls::<impl core::clone::Clone for i32>::clone
52+
let f2 = use || f;
53+
54+
f
55+
}

0 commit comments

Comments
 (0)