Skip to content

Commit 40d879a

Browse files
committed
Add test.
1 parent a9d0a6f commit 40d879a

7 files changed

+453
-11
lines changed

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ impl<'tcx> Body<'tcx> {
471471

472472
/// Returns an iterator over all function arguments.
473473
#[inline]
474-
pub fn args_iter(&self) -> impl Iterator<Item = Local> + ExactSizeIterator {
474+
pub fn args_iter(&self) -> impl Iterator<Item = Local> + ExactSizeIterator + use<> {
475475
(1..self.arg_count + 1).map(Local::new)
476476
}
477477

compiler/rustc_middle/src/mir/query.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::ty::{self, CoroutineArgsExt, OpaqueHiddenType, Ty};
1717
rustc_index::newtype_index! {
1818
#[derive(HashStable)]
1919
#[encodable]
20-
#[debug_format = "_{}"]
20+
#[debug_format = "_s{}"]
2121
pub struct CoroutineSavedLocal {}
2222
}
2323

tests/mir-opt/building/async_await.b-{closure#0}.coroutine_resume.0.mir

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// MIR for `b::{closure#0}` 0 coroutine_resume
22
/* coroutine_layout = CoroutineLayout {
33
field_tys: {
4-
_0: CoroutineSavedTy {
4+
_s0: CoroutineSavedTy {
55
ty: Coroutine(
66
DefId(0:5 ~ async_await[ccf8]::a::{closure#0}),
77
[
@@ -18,7 +18,7 @@
1818
},
1919
ignore_for_traits: false,
2020
},
21-
_1: CoroutineSavedTy {
21+
_s1: CoroutineSavedTy {
2222
ty: Coroutine(
2323
DefId(0:5 ~ async_await[ccf8]::a::{closure#0}),
2424
[
@@ -40,12 +40,12 @@
4040
Unresumed(0): [],
4141
Returned (1): [],
4242
Panicked (2): [],
43-
Suspend0 (3): [_0],
44-
Suspend1 (4): [_1],
43+
Suspend0 (3): [_s0],
44+
Suspend1 (4): [_s1],
4545
},
4646
storage_conflicts: BitMatrix(2x2) {
47-
(_0, _0),
48-
(_1, _1),
47+
(_s0, _s0),
48+
(_s1, _s1),
4949
},
5050
} */
5151

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
// MIR for `main::{closure#0}` after StateTransform
2+
/* coroutine_layout = CoroutineLayout {
3+
field_tys: {
4+
_s0: CoroutineSavedTy {
5+
ty: std::string::String,
6+
source_info: SourceInfo {
7+
span: $DIR/coroutine.rs:17:32: 17:35 (#0),
8+
scope: scope[0],
9+
},
10+
ignore_for_traits: false,
11+
},
12+
},
13+
variant_fields: {
14+
Unresumed(0): [],
15+
Returned (1): [],
16+
Panicked (2): [],
17+
Suspend0 (3): [_s0],
18+
Suspend1 (4): [_s0],
19+
},
20+
storage_conflicts: BitMatrix(1x1) {
21+
(_s0, _s0),
22+
},
23+
} */
24+
25+
fn main::{closure#0}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:17:31: 17:44}>, _2: String) -> CoroutineState<(&str, String, &Location<'_>), ()> {
26+
debug arg => (((*(_1.0: &mut {coroutine@$DIR/coroutine.rs:17:31: 17:44})) as variant#4).0: std::string::String);
27+
let mut _0: std::ops::CoroutineState<(&str, std::string::String, &std::panic::Location<'_>), ()>;
28+
let _3: std::string::String;
29+
let mut _4: (&str, std::string::String, &std::panic::Location<'_>);
30+
let mut _5: std::string::String;
31+
let mut _6: &std::string::String;
32+
let mut _7: &std::panic::Location<'_>;
33+
let _8: std::string::String;
34+
let mut _9: (&str, std::string::String, &std::panic::Location<'_>);
35+
let mut _10: &str;
36+
let _11: &str;
37+
let mut _12: std::string::String;
38+
let mut _13: &std::string::String;
39+
let mut _14: &std::panic::Location<'_>;
40+
let _15: &std::panic::Location<'_>;
41+
let mut _16: ();
42+
let _17: std::string::String;
43+
let mut _18: u32;
44+
let mut _19: &mut {coroutine@$DIR/coroutine.rs:17:31: 17:44};
45+
let mut _20: &mut {coroutine@$DIR/coroutine.rs:17:31: 17:44};
46+
let mut _21: &mut {coroutine@$DIR/coroutine.rs:17:31: 17:44};
47+
let mut _22: &mut {coroutine@$DIR/coroutine.rs:17:31: 17:44};
48+
let mut _23: &mut {coroutine@$DIR/coroutine.rs:17:31: 17:44};
49+
let mut _24: &mut {coroutine@$DIR/coroutine.rs:17:31: 17:44};
50+
let mut _25: &mut {coroutine@$DIR/coroutine.rs:17:31: 17:44};
51+
let mut _26: &mut {coroutine@$DIR/coroutine.rs:17:31: 17:44};
52+
53+
bb0: {
54+
_19 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:17:31: 17:44});
55+
_18 = discriminant((*_19));
56+
switchInt(move _18) -> [0: bb1, 1: bb19, 3: bb17, 4: bb18, otherwise: bb20];
57+
}
58+
59+
bb1: {
60+
_20 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:17:31: 17:44});
61+
(((*_20) as variant#4).0: std::string::String) = move _2;
62+
StorageLive(_3);
63+
StorageLive(_4);
64+
StorageLive(_5);
65+
StorageLive(_6);
66+
_21 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:17:31: 17:44});
67+
_6 = &(((*_21) as variant#4).0: std::string::String);
68+
_5 = <String as Clone>::clone(move _6) -> [return: bb2, unwind unreachable];
69+
}
70+
71+
bb2: {
72+
StorageDead(_6);
73+
StorageLive(_7);
74+
_7 = Location::<'_>::caller() -> [return: bb3, unwind unreachable];
75+
}
76+
77+
bb3: {
78+
_4 = (const "first", move _5, move _7);
79+
StorageDead(_7);
80+
goto -> bb4;
81+
}
82+
83+
bb4: {
84+
StorageDead(_5);
85+
_0 = CoroutineState::<(&str, String, &Location<'_>), ()>::Yielded(move _4);
86+
StorageDead(_3);
87+
StorageDead(_4);
88+
_22 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:17:31: 17:44});
89+
discriminant((*_22)) = 3;
90+
return;
91+
}
92+
93+
bb5: {
94+
goto -> bb6;
95+
}
96+
97+
bb6: {
98+
StorageDead(_4);
99+
drop(_3) -> [return: bb7, unwind unreachable];
100+
}
101+
102+
bb7: {
103+
StorageDead(_3);
104+
StorageLive(_8);
105+
StorageLive(_9);
106+
StorageLive(_10);
107+
StorageLive(_11);
108+
_11 = const "second";
109+
_10 = &(*_11);
110+
StorageLive(_12);
111+
StorageLive(_13);
112+
_23 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:17:31: 17:44});
113+
_13 = &(((*_23) as variant#4).0: std::string::String);
114+
_12 = <String as Clone>::clone(move _13) -> [return: bb8, unwind unreachable];
115+
}
116+
117+
bb8: {
118+
StorageDead(_13);
119+
StorageLive(_14);
120+
StorageLive(_15);
121+
_15 = Location::<'_>::caller() -> [return: bb9, unwind unreachable];
122+
}
123+
124+
bb9: {
125+
_14 = &(*_15);
126+
_9 = (move _10, move _12, move _14);
127+
StorageDead(_14);
128+
goto -> bb10;
129+
}
130+
131+
bb10: {
132+
StorageDead(_12);
133+
StorageDead(_10);
134+
_0 = CoroutineState::<(&str, String, &Location<'_>), ()>::Yielded(move _9);
135+
StorageDead(_8);
136+
StorageDead(_9);
137+
StorageDead(_11);
138+
StorageDead(_15);
139+
_24 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:17:31: 17:44});
140+
discriminant((*_24)) = 4;
141+
return;
142+
}
143+
144+
bb11: {
145+
goto -> bb12;
146+
}
147+
148+
bb12: {
149+
StorageDead(_9);
150+
drop(_8) -> [return: bb13, unwind unreachable];
151+
}
152+
153+
bb13: {
154+
StorageDead(_15);
155+
StorageDead(_11);
156+
StorageDead(_8);
157+
_16 = const ();
158+
_25 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:17:31: 17:44});
159+
drop((((*_25) as variant#4).0: std::string::String)) -> [return: bb14, unwind unreachable];
160+
}
161+
162+
bb14: {
163+
goto -> bb16;
164+
}
165+
166+
bb15: {
167+
_0 = CoroutineState::<(&str, String, &Location<'_>), ()>::Complete(move _16);
168+
_26 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:17:31: 17:44});
169+
discriminant((*_26)) = 1;
170+
return;
171+
}
172+
173+
bb16: {
174+
goto -> bb15;
175+
}
176+
177+
bb17: {
178+
StorageLive(_3);
179+
StorageLive(_4);
180+
_3 = move _2;
181+
goto -> bb5;
182+
}
183+
184+
bb18: {
185+
StorageLive(_8);
186+
StorageLive(_9);
187+
StorageLive(_11);
188+
StorageLive(_15);
189+
_8 = move _2;
190+
goto -> bb11;
191+
}
192+
193+
bb19: {
194+
assert(const false, "coroutine resumed after completion") -> [success: bb19, unwind unreachable];
195+
}
196+
197+
bb20: {
198+
unreachable;
199+
}
200+
}
201+
202+
ALLOC0 (size: 6, align: 1) {
203+
73 65 63 6f 6e 64 │ second
204+
}
205+
206+
ALLOC1 (size: 5, align: 1) {
207+
66 69 72 73 74 │ first
208+
}

0 commit comments

Comments
 (0)