diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-03-08 23:10:43 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-03-08 23:10:43 +0000 |
commit | f5891dd5deab905c7856add720ab0000c4c9c5f7 (patch) | |
tree | 4b825dc642cb6eb9a060e54bf8d69288fbee4904 /src/generate/struc.rs | |
parent | 367f3c050a9ac7ec518ef7301681e3695f2e6a12 (diff) | |
parent | 23c1e5ff66c23e3872877ab8cf257fe22e8f68f1 (diff) | |
download | ouroboros_macro-simpleperf-release.tar.gz |
Snap for 9713123 from 23c1e5ff66c23e3872877ab8cf257fe22e8f68f1 to simpleperf-releasesimpleperf-release
Change-Id: Iccc359ad208edc8db164f0b8bcfe43fcbc60b5ef
Diffstat (limited to 'src/generate/struc.rs')
-rw-r--r-- | src/generate/struc.rs | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/src/generate/struc.rs b/src/generate/struc.rs deleted file mode 100644 index 9b2ff51..0000000 --- a/src/generate/struc.rs +++ /dev/null @@ -1,50 +0,0 @@ -use crate::{ - info_structures::StructInfo, - utils::{self, replace_this_with_lifetime}, -}; -use proc_macro2::TokenStream; -use quote::quote; -use syn::Error; - -/// Creates the struct that will actually store the data. This involves properly organizing the -/// fields, collecting metadata about them, reversing the order everything is stored in, and -/// converting any uses of 'this to 'static. -pub fn create_actual_struct_def(info: &StructInfo) -> Result<TokenStream, Error> { - let vis = utils::submodule_contents_visiblity(&info.vis); - let ident = &info.ident; - let generics = &info.generics; - - let field_defs: Vec<_> = info - .fields - .iter() - // Reverse the order of all fields. We ensure that items in the struct are only dependent - // on references to items above them. Rust drops items in a struct in forward declaration order. - // This would cause parents being dropped before children, necessitating the reversal. - .rev() - .map(|field| { - let name = &field.name; - let ty = field.stored_type(); - quote! { - #[doc(hidden)] - #name: #ty - } - }) - .collect(); - - // Create the new struct definition. - let mut where_clause = quote! {}; - if let Some(clause) = &generics.where_clause { - where_clause = quote! { #clause }; - } - let def = quote! { - #vis struct #ident #generics #where_clause { - #(#field_defs),* - } - }; - - // Finally, replace the fake 'this lifetime with the one we found. - let fake_lifetime = info.fake_lifetime(); - let def = replace_this_with_lifetime(quote! { #def }, fake_lifetime.clone()); - - Ok(def) -} |