@@ -0,0 +1,45 @@ |
|
|
|
1 |
+// run-pass |
|
2 |
+// |
|
3 |
+// This is derived from a change to compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs, in |
|
4 |
+// preparation for adopting let-else within the compiler (thanks @est31): |
|
5 |
+// |
|
6 |
+// ``` |
|
7 |
+// - let place = if let mir::VarDebugInfoContents::Place(p) = var.value { p } else { continue }; |
|
8 |
+// + let mir::VarDebugInfoContents::Place(place) = var.value else { continue }; |
|
9 |
+// ``` |
|
10 |
+// |
|
11 |
+// The move was due to mir::Place being Copy, but mir::VarDebugInfoContents not being Copy. |
|
12 |
+ |
|
13 |
+#![feature(let_else)] |
|
14 |
+ |
|
15 |
+#[derive(Copy, Clone)] |
|
16 |
+struct Copyable; |
|
17 |
+ |
|
18 |
+enum NonCopy { |
|
19 |
+Thing(Copyable), |
|
20 |
+#[allow(unused)] |
|
21 |
+Other, |
|
22 |
+} |
|
23 |
+ |
|
24 |
+struct Wrapper { |
|
25 |
+field: NonCopy, |
|
26 |
+} |
|
27 |
+ |
|
28 |
+fn let_else() { |
|
29 |
+let vec = vec![Wrapper { field: NonCopy::Thing(Copyable) }]; |
|
30 |
+for item in &vec { |
|
31 |
+let NonCopy::Thing(_copyable) = item.field else { continue }; |
|
32 |
+} |
|
33 |
+} |
|
34 |
+ |
|
35 |
+fn if_let() { |
|
36 |
+let vec = vec![Wrapper { field: NonCopy::Thing(Copyable) }]; |
|
37 |
+for item in &vec { |
|
38 |
+let _copyable = if let NonCopy::Thing(copyable) = item.field { copyable } else { continue }; |
|
39 |
+} |
|
40 |
+} |
|
41 |
+ |
|
42 |
+fn main() { |
|
43 |
+let_else(); |
|
44 |
+if_let(); |
|
45 |
+} |