]> git.lizzy.rs Git - rust.git/blob - tests/mir-opt/copy-prop/borrowed_local.rs
Auto merge of #107443 - cjgillot:generator-less-query, r=compiler-errors
[rust.git] / tests / mir-opt / copy-prop / borrowed_local.rs
1 // unit-test: CopyProp
2
3 #![feature(custom_mir, core_intrinsics)]
4 #![allow(unused_assignments)]
5 extern crate core;
6 use core::intrinsics::mir::*;
7
8 fn opaque(_: impl Sized) -> bool { true }
9
10 fn cmp_ref(a: &u8, b: &u8) -> bool {
11     std::ptr::eq(a as *const u8, b as *const u8)
12 }
13
14 #[custom_mir(dialect = "analysis", phase = "post-cleanup")]
15 fn f() -> bool {
16     mir!(
17         {
18             let a = 5_u8;
19             let r1 = &a;
20             let b = a;
21             // We cannot propagate the place `a`.
22             let r2 = &b;
23             Call(RET, next, cmp_ref(r1, r2))
24         }
25         next = {
26             // But we can propagate the value `a`.
27             Call(RET, ret, opaque(b))
28         }
29         ret = {
30             Return()
31         }
32     )
33 }
34
35 fn main() {
36     assert!(!f());
37 }
38
39 // EMIT_MIR borrowed_local.f.CopyProp.diff