]> git.lizzy.rs Git - rust.git/blob - tests/mir-opt/copy-prop/copy_propagation_arg.rs
Auto merge of #107443 - cjgillot:generator-less-query, r=compiler-errors
[rust.git] / tests / mir-opt / copy-prop / copy_propagation_arg.rs
1 // Check that CopyProp does not propagate an assignment to a function argument
2 // (doing so can break usages of the original argument value)
3 // unit-test: CopyProp
4 fn dummy(x: u8) -> u8 {
5     x
6 }
7
8 // EMIT_MIR copy_propagation_arg.foo.CopyProp.diff
9 fn foo(mut x: u8) {
10     // calling `dummy` to make a use of `x` that copyprop cannot eliminate
11     x = dummy(x); // this will assign a local to `x`
12 }
13
14 // EMIT_MIR copy_propagation_arg.bar.CopyProp.diff
15 fn bar(mut x: u8) {
16     dummy(x);
17     x = 5;
18 }
19
20 // EMIT_MIR copy_propagation_arg.baz.CopyProp.diff
21 fn baz(mut x: i32) -> i32 {
22     // self-assignment to a function argument should be eliminated
23     x = x;
24     x
25 }
26
27 // EMIT_MIR copy_propagation_arg.arg_src.CopyProp.diff
28 fn arg_src(mut x: i32) -> i32 {
29     let y = x;
30     x = 123; // Don't propagate this assignment to `y`
31     y
32 }
33
34 fn main() {
35     // Make sure the function actually gets instantiated.
36     foo(0);
37     bar(0);
38     baz(0);
39     arg_src(0);
40 }