Skip to content

Commit 7a9709b

Browse files
Fix bootstrap rustc build
1 parent 4ee857c commit 7a9709b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/librustc_data_structures/box_region.rs

+39
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct PinnedGenerator<I, A, R> {
2525
}
2626

2727
impl<I, A, R> PinnedGenerator<I, A, R> {
28+
#[cfg(bootstrap)]
2829
pub fn new<T: Generator<Yield = YieldType<I, A>, Return = R> + 'static>(
2930
generator: T,
3031
) -> (I, Self) {
@@ -39,6 +40,22 @@ impl<I, A, R> PinnedGenerator<I, A, R> {
3940
(init, result)
4041
}
4142

43+
#[cfg(not(bootstrap))]
44+
pub fn new<T: Generator<Yield = YieldType<I, A>, Return = R> + 'static>(
45+
generator: T,
46+
) -> (I, Self) {
47+
let mut result = PinnedGenerator { generator: Box::pin(generator) };
48+
49+
// Run it to the first yield to set it up
50+
let init = match Pin::new(&mut result.generator).resume(()) {
51+
GeneratorState::Yielded(YieldType::Initial(y)) => y,
52+
_ => panic!(),
53+
};
54+
55+
(init, result)
56+
}
57+
58+
#[cfg(bootstrap)]
4259
pub unsafe fn access(&mut self, closure: *mut dyn FnMut()) {
4360
BOX_REGION_ARG.with(|i| {
4461
i.set(Action::Access(AccessAction(closure)));
@@ -50,13 +67,35 @@ impl<I, A, R> PinnedGenerator<I, A, R> {
5067
}
5168
}
5269

70+
#[cfg(not(bootstrap))]
71+
pub unsafe fn access(&mut self, closure: *mut dyn FnMut()) {
72+
BOX_REGION_ARG.with(|i| {
73+
i.set(Action::Access(AccessAction(closure)));
74+
});
75+
76+
// Call the generator, which in turn will call the closure in BOX_REGION_ARG
77+
if let GeneratorState::Complete(_) = Pin::new(&mut self.generator).resume(()) {
78+
panic!()
79+
}
80+
}
81+
82+
#[cfg(bootstrap)]
5383
pub fn complete(&mut self) -> R {
5484
// Tell the generator we want it to complete, consuming it and yielding a result
5585
BOX_REGION_ARG.with(|i| i.set(Action::Complete));
5686

5787
let result = Pin::new(&mut self.generator).resume();
5888
if let GeneratorState::Complete(r) = result { r } else { panic!() }
5989
}
90+
91+
#[cfg(not(bootstrap))]
92+
pub fn complete(&mut self) -> R {
93+
// Tell the generator we want it to complete, consuming it and yielding a result
94+
BOX_REGION_ARG.with(|i| i.set(Action::Complete));
95+
96+
let result = Pin::new(&mut self.generator).resume(());
97+
if let GeneratorState::Complete(r) = result { r } else { panic!() }
98+
}
6099
}
61100

62101
#[derive(PartialEq)]

0 commit comments

Comments
 (0)