diff options
| author | bors <bors@rust-lang.org> | 2022-04-16 22:04:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-04-16 22:04:10 +0000 |
| commit | 563ef23529ae800b2b136cabdc71a81d86a75f58 (patch) | |
| tree | 6457ca2757a1938584ef0a1cb21842d9e1bb43bd /compiler/rustc_data_structures | |
| parent | 878c7833f6c1ff10e2fd89074e5bd4ef5ff15936 (diff) | |
| parent | 233fa659f455e84cdf5ba74d8cda6e9fb3f6245b (diff) | |
| download | rust-563ef23529ae800b2b136cabdc71a81d86a75f58.tar.gz rust-563ef23529ae800b2b136cabdc71a81d86a75f58.zip | |
Auto merge of #95899 - petrochenkov:modchild2, r=cjgillot
rustc_metadata: Do not encode unnecessary module children This should remove the syntax context shift and the special case for `ExternCrate` in decoder in https://github.com/rust-lang/rust/pull/95880. This PR also shifts some work from decoding to encoding, which is typically useful for performance (but probably not much in this case). r? `@cjgillot`
Diffstat (limited to 'compiler/rustc_data_structures')
| -rw-r--r-- | compiler/rustc_data_structures/src/lib.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/lib.rs b/compiler/rustc_data_structures/src/lib.rs index 98d4870e645..30a3ddc6003 100644 --- a/compiler/rustc_data_structures/src/lib.rs +++ b/compiler/rustc_data_structures/src/lib.rs @@ -14,6 +14,8 @@ #![feature(control_flow_enum)] #![feature(core_intrinsics)] #![feature(extend_one)] +#![feature(generator_trait)] +#![feature(generators)] #![feature(let_else)] #![feature(hash_raw_entry)] #![feature(maybe_uninit_uninit_array)] @@ -112,6 +114,9 @@ pub mod unhash; pub use ena::undo_log; pub use ena::unify; +use std::ops::{Generator, GeneratorState}; +use std::pin::Pin; + pub struct OnDrop<F: Fn()>(pub F); impl<F: Fn()> OnDrop<F> { @@ -130,6 +135,26 @@ impl<F: Fn()> Drop for OnDrop<F> { } } +struct IterFromGenerator<G>(G); + +impl<G: Generator<Return = ()> + Unpin> Iterator for IterFromGenerator<G> { + type Item = G::Yield; + + fn next(&mut self) -> Option<Self::Item> { + match Pin::new(&mut self.0).resume(()) { + GeneratorState::Yielded(n) => Some(n), + GeneratorState::Complete(_) => None, + } + } +} + +/// An adapter for turning a generator closure into an iterator, similar to `iter::from_fn`. +pub fn iter_from_generator<G: Generator<Return = ()> + Unpin>( + generator: G, +) -> impl Iterator<Item = G::Yield> { + IterFromGenerator(generator) +} + // See comments in src/librustc_middle/lib.rs #[doc(hidden)] pub fn __noop_fix_for_27438() {} |
