X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc_data_structures%2Fbox_region.rs;h=94abb89503c033049436eeec23b7c244060c3e2b;hb=787c458eeb20e447989124e2900e02e8e03b1c51;hp=278dcdf2bee42a49b830690e37bc00fa493388b2;hpb=61ff887919ba03d869e2b91aba1a9e64f6bf9a73;p=rust.git diff --git a/src/librustc_data_structures/box_region.rs b/src/librustc_data_structures/box_region.rs index 278dcdf2bee..94abb89503c 100644 --- a/src/librustc_data_structures/box_region.rs +++ b/src/librustc_data_structures/box_region.rs @@ -1,7 +1,7 @@ use std::cell::Cell; use std::marker::PhantomData; -use std::pin::Pin; use std::ops::{Generator, GeneratorState}; +use std::pin::Pin; #[derive(Copy, Clone)] pub struct AccessAction(*mut dyn FnMut()); @@ -21,23 +21,19 @@ pub enum Action { thread_local!(pub static BOX_REGION_ARG: Cell = Cell::new(Action::Complete)); pub struct PinnedGenerator { - generator: Pin, Return = R>>> + generator: Pin, Return = R>>>, } impl PinnedGenerator { - pub fn new< - T: Generator, Return = R> + 'static - >(generator: T) -> (I, Self) { - let mut result = PinnedGenerator { - generator: Box::pin(generator) - }; + pub fn new, Return = R> + 'static>( + generator: T, + ) -> (I, Self) { + let mut result = PinnedGenerator { generator: Box::pin(generator) }; // Run it to the first yield to set it up let init = match Pin::new(&mut result.generator).resume() { - GeneratorState::Yielded( - YieldType::Initial(y) - ) => y, - _ => panic!() + GeneratorState::Yielded(YieldType::Initial(y)) => y, + _ => panic!(), }; (init, result) @@ -56,16 +52,10 @@ pub unsafe fn access(&mut self, closure: *mut dyn FnMut()) { pub fn complete(&mut self) -> R { // Tell the generator we want it to complete, consuming it and yielding a result - BOX_REGION_ARG.with(|i| { - i.set(Action::Complete) - }); + BOX_REGION_ARG.with(|i| i.set(Action::Complete)); let result = Pin::new(&mut self.generator).resume(); - if let GeneratorState::Complete(r) = result { - r - } else { - panic!() - } + if let GeneratorState::Complete(r) = result { r } else { panic!() } } }