[
  {
    "path": ".gitignore",
    "content": "/target\n/rental-impl/target\n/.cargo\nCargo.lock\n\n*.vim\n*.sw[onp]\n*~\n"
  },
  {
    "path": "Cargo.toml",
    "content": "[package]\nname = \"rental\"\nversion = \"0.5.6\"\nlicense = \"MIT/Apache-2.0\"\nauthors = [\"Jameson Ernst <jameson@jpernst.com>\"]\ndescription = \"A macro to generate safe self-referential structs, plus premade types for common use cases.\"\nreadme = \"README.md\"\nkeywords = [\"lifetime\", \"ownership\", \"borrowing\", \"self\", \"reference\"]\ncategories = [\"rust-patterns\", \"no-std\"]\nrepository = \"https://github.com/jpernst/rental\"\ndocumentation = \"https://docs.rs/rental\"\n\n[workspace]\nmembers = [\"rental-impl\"]\n\n[features]\ndefault = [\"std\"]\nstd = [\"stable_deref_trait/std\"]\n\n[dependencies]\nrental-impl = { version = \"=0.5.5\", path = \"rental-impl\" }\nstable_deref_trait = { version = \"1.0.0\", default-features = false }\n"
  },
  {
    "path": "LICENSE-APACHE",
    "content": "                              Apache License\n                        Version 2.0, January 2004\n                     http://www.apache.org/licenses/\n\nTERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n1. Definitions.\n\n   \"License\" shall mean the terms and conditions for use, reproduction,\n   and distribution as defined by Sections 1 through 9 of this document.\n\n   \"Licensor\" shall mean the copyright owner or entity authorized by\n   the copyright owner that is granting the License.\n\n   \"Legal Entity\" shall mean the union of the acting entity and all\n   other entities that control, are controlled by, or are under common\n   control with that entity. For the purposes of this definition,\n   \"control\" means (i) the power, direct or indirect, to cause the\n   direction or management of such entity, whether by contract or\n   otherwise, or (ii) ownership of fifty percent (50%) or more of the\n   outstanding shares, or (iii) beneficial ownership of such entity.\n\n   \"You\" (or \"Your\") shall mean an individual or Legal Entity\n   exercising permissions granted by this License.\n\n   \"Source\" form shall mean the preferred form for making modifications,\n   including but not limited to software source code, documentation\n   source, and configuration files.\n\n   \"Object\" form shall mean any form resulting from mechanical\n   transformation or translation of a Source form, including but\n   not limited to compiled object code, generated documentation,\n   and conversions to other media types.\n\n   \"Work\" shall mean the work of authorship, whether in Source or\n   Object form, made available under the License, as indicated by a\n   copyright notice that is included in or attached to the work\n   (an example is provided in the Appendix below).\n\n   \"Derivative Works\" shall mean any work, whether in Source or Object\n   form, that is based on (or derived from) the Work and for which the\n   editorial revisions, annotations, elaborations, or other modifications\n   represent, as a whole, an original work of authorship. For the purposes\n   of this License, Derivative Works shall not include works that remain\n   separable from, or merely link (or bind by name) to the interfaces of,\n   the Work and Derivative Works thereof.\n\n   \"Contribution\" shall mean any work of authorship, including\n   the original version of the Work and any modifications or additions\n   to that Work or Derivative Works thereof, that is intentionally\n   submitted to Licensor for inclusion in the Work by the copyright owner\n   or by an individual or Legal Entity authorized to submit on behalf of\n   the copyright owner. For the purposes of this definition, \"submitted\"\n   means any form of electronic, verbal, or written communication sent\n   to the Licensor or its representatives, including but not limited to\n   communication on electronic mailing lists, source code control systems,\n   and issue tracking systems that are managed by, or on behalf of, the\n   Licensor for the purpose of discussing and improving the Work, but\n   excluding communication that is conspicuously marked or otherwise\n   designated in writing by the copyright owner as \"Not a Contribution.\"\n\n   \"Contributor\" shall mean Licensor and any individual or Legal Entity\n   on behalf of whom a Contribution has been received by Licensor and\n   subsequently incorporated within the Work.\n\n2. Grant of Copyright License. Subject to the terms and conditions of\n   this License, each Contributor hereby grants to You a perpetual,\n   worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n   copyright license to reproduce, prepare Derivative Works of,\n   publicly display, publicly perform, sublicense, and distribute the\n   Work and such Derivative Works in Source or Object form.\n\n3. Grant of Patent License. Subject to the terms and conditions of\n   this License, each Contributor hereby grants to You a perpetual,\n   worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n   (except as stated in this section) patent license to make, have made,\n   use, offer to sell, sell, import, and otherwise transfer the Work,\n   where such license applies only to those patent claims licensable\n   by such Contributor that are necessarily infringed by their\n   Contribution(s) alone or by combination of their Contribution(s)\n   with the Work to which such Contribution(s) was submitted. If You\n   institute patent litigation against any entity (including a\n   cross-claim or counterclaim in a lawsuit) alleging that the Work\n   or a Contribution incorporated within the Work constitutes direct\n   or contributory patent infringement, then any patent licenses\n   granted to You under this License for that Work shall terminate\n   as of the date such litigation is filed.\n\n4. Redistribution. You may reproduce and distribute copies of the\n   Work or Derivative Works thereof in any medium, with or without\n   modifications, and in Source or Object form, provided that You\n   meet the following conditions:\n\n   (a) You must give any other recipients of the Work or\n       Derivative Works a copy of this License; and\n\n   (b) You must cause any modified files to carry prominent notices\n       stating that You changed the files; and\n\n   (c) You must retain, in the Source form of any Derivative Works\n       that You distribute, all copyright, patent, trademark, and\n       attribution notices from the Source form of the Work,\n       excluding those notices that do not pertain to any part of\n       the Derivative Works; and\n\n   (d) If the Work includes a \"NOTICE\" text file as part of its\n       distribution, then any Derivative Works that You distribute must\n       include a readable copy of the attribution notices contained\n       within such NOTICE file, excluding those notices that do not\n       pertain to any part of the Derivative Works, in at least one\n       of the following places: within a NOTICE text file distributed\n       as part of the Derivative Works; within the Source form or\n       documentation, if provided along with the Derivative Works; or,\n       within a display generated by the Derivative Works, if and\n       wherever such third-party notices normally appear. The contents\n       of the NOTICE file are for informational purposes only and\n       do not modify the License. You may add Your own attribution\n       notices within Derivative Works that You distribute, alongside\n       or as an addendum to the NOTICE text from the Work, provided\n       that such additional attribution notices cannot be construed\n       as modifying the License.\n\n   You may add Your own copyright statement to Your modifications and\n   may provide additional or different license terms and conditions\n   for use, reproduction, or distribution of Your modifications, or\n   for any such Derivative Works as a whole, provided Your use,\n   reproduction, and distribution of the Work otherwise complies with\n   the conditions stated in this License.\n\n5. Submission of Contributions. Unless You explicitly state otherwise,\n   any Contribution intentionally submitted for inclusion in the Work\n   by You to the Licensor shall be under the terms and conditions of\n   this License, without any additional terms or conditions.\n   Notwithstanding the above, nothing herein shall supersede or modify\n   the terms of any separate license agreement you may have executed\n   with Licensor regarding such Contributions.\n\n6. Trademarks. This License does not grant permission to use the trade\n   names, trademarks, service marks, or product names of the Licensor,\n   except as required for reasonable and customary use in describing the\n   origin of the Work and reproducing the content of the NOTICE file.\n\n7. Disclaimer of Warranty. Unless required by applicable law or\n   agreed to in writing, Licensor provides the Work (and each\n   Contributor provides its Contributions) on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n   implied, including, without limitation, any warranties or conditions\n   of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n   PARTICULAR PURPOSE. You are solely responsible for determining the\n   appropriateness of using or redistributing the Work and assume any\n   risks associated with Your exercise of permissions under this License.\n\n8. Limitation of Liability. In no event and under no legal theory,\n   whether in tort (including negligence), contract, or otherwise,\n   unless required by applicable law (such as deliberate and grossly\n   negligent acts) or agreed to in writing, shall any Contributor be\n   liable to You for damages, including any direct, indirect, special,\n   incidental, or consequential damages of any character arising as a\n   result of this License or out of the use or inability to use the\n   Work (including but not limited to damages for loss of goodwill,\n   work stoppage, computer failure or malfunction, or any and all\n   other commercial damages or losses), even if such Contributor\n   has been advised of the possibility of such damages.\n\n9. Accepting Warranty or Additional Liability. While redistributing\n   the Work or Derivative Works thereof, You may choose to offer,\n   and charge a fee for, acceptance of support, warranty, indemnity,\n   or other liability obligations and/or rights consistent with this\n   License. However, in accepting such obligations, You may act only\n   on Your own behalf and on Your sole responsibility, not on behalf\n   of any other Contributor, and only if You agree to indemnify,\n   defend, and hold each Contributor harmless for any liability\n   incurred by, or claims asserted against, such Contributor by reason\n   of your accepting any such warranty or additional liability.\n\nEND OF TERMS AND CONDITIONS\n\nAPPENDIX: How to apply the Apache License to your work.\n\n   To apply the Apache License to your work, attach the following\n   boilerplate notice, with the fields enclosed by brackets \"[]\"\n   replaced with your own identifying information. (Don't include\n   the brackets!)  The text should be enclosed in the appropriate\n   comment syntax for the file format. We also recommend that a\n   file or class name and description of purpose be included on the\n   same \"printed page\" as the copyright notice for easier\n   identification within third-party archives.\n\nCopyright [yyyy] [name of copyright owner]\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n\thttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n"
  },
  {
    "path": "LICENSE-MIT",
    "content": "Copyright (c) 2016 Jameson Ernst\n\nPermission is hereby granted, free of charge, to any\nperson obtaining a copy of this software and associated\ndocumentation files (the \"Software\"), to deal in the\nSoftware without restriction, including without\nlimitation the rights to use, copy, modify, merge,\npublish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software\nis furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice\nshall be included in all copies or substantial portions\nof the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF\nANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED\nTO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A\nPARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT\nSHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR\nIN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\nDEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# WARNING: This crate is NO LONGER MAINTAINED OR SUPPORTED\nI'm not going to yank the crate because it's still fit for its intended purpose, but as time goes on it will become increasingly out of step with Rust's evolution, so users are encouraged to explore other solutions. I will also not merge any pull requests, as the code is sufficiently complicated that I'm no longer confident in my ability to effectively review them. Rental can be considered \"frozen\" in its current state, and any further development will need to take place under a fork for whoever wishes to do so.\n\n# Rental - A macro to generate safe self-referential structs, plus premade types for common use cases.\n\n[Documentation](http://docs.rs/rental)\n\n# Overview\nIt can sometimes occur in the course of designing an API that it would be convenient, or even necessary, to allow fields within a struct to hold references to other fields within that same struct. Rust's concept of ownership and borrowing is powerful, but can't express such a scenario yet.\n\nCreating such a struct manually would require unsafe code to erase lifetime parameters from the field types. Accessing the fields directly would be completely unsafe as a result. This library addresses that issue by allowing access to the internal fields only under carefully controlled circumstances, through closures that are bounded by generic lifetimes to prevent infiltration or exfiltration of any data with an incorrect lifetime. In short, while the struct internally uses unsafe code to store the fields, the interface exposed to the consumer of the struct is completely safe. The implementation of this interface is subtle and verbose, hence the macro to automate the process.\n\nThe API of this crate consists of the `rental` macro that generates safe self-referential structs, a few example instantiations to demonstrate the API provided by such structs (see `examples`), and a module of premade instantiations to cover common use cases (see `common`).\n\n# Example\nOne instance where this crate is useful is when working with `libloading`. That crate provides a `Library` struct that defines methods to borrow `Symbol`s from it. These symbols are bounded by the lifetime of the library, and are thus considered a borrow. Under normal circumstances, one would be unable to store both the library and the symbols within a single struct, but the macro defined in this crate allows you to define a struct that is capable of storing both simultaneously, like so:\n\n```rust,ignore\nrental! {\n    pub mod rent_libloading {\n        use libloading;\n\n        #[rental(deref_suffix)] // This struct will deref to the Deref::Target of Symbol.\n        pub struct RentSymbol<S: 'static> {\n            lib: Box<libloading::Library>, // Library is boxed for StableDeref.\n            sym: libloading::Symbol<'lib, S>, // The 'lib lifetime borrows lib.\n        }\n    }\n}\n\nfn main() {\n    let lib = libloading::Library::new(\"my_lib.so\").unwrap(); // Open our dylib.\n    if let Ok(rs) = rent_libloading::RentSymbol::try_new(\n        Box::new(lib),\n        |lib| unsafe { lib.get::<extern \"C\" fn()>(b\"my_symbol\") }) // Loading symbols is unsafe.\n    {\n        (*rs)(); // Call our function\n    };\n}\n```\n\nIn this way we can store both the `Library` and the `Symbol` that borrows it in a single struct. We can even tell our struct to deref to the function pointer itself so we can easily call it. This is legal because the function pointer does not contain any of the special lifetimes introduced by the rental struct in its type signature, which means reborrowing will not expose them to the outside world. As an aside, the `unsafe` block for loading the symbol is necessary because the act of loading a symbol from a dylib is unsafe, and is unrelated to rental.\n\n# Limitations\nThere are a few limitations with the current implementation due to bugs or pending features in rust itself. These will be lifted once the underlying language allows it.\n\n* Currently, the rental struct itself can only take lifetime parameters under certain conditions. These conditions are difficult to fully describe, but in general, a lifetime param of the rental struct itself must appear \"outside\" of any special rental lifetimes in the type signatures of the struct fields. To put it another way, replacing the rental lifetimes with `'static` must still produce legal types, otherwise it will not compile. In most situations this is fine, since most of the use cases for this library involve erasing all of the lifetimes anyway, but there's no reason why the head element of a rental struct shouldn't be able to take arbitrary lifetime params. This is currently impossible to fully support due to lack of an `'unsafe` lifetime or equivalent feature.\n* Prefix fields, and the head field if it IS a subrental, must be of the form `Foo<T>` where `Foo` is some `StableDeref` container, or rental will not be able to correctly guess the `Deref::Target` of the type. If you are using a custom type that does not fit this pattern, you can use the `target_ty` attribute on the field to manually specify the target type. If the head field is NOT a subrental, then it may have any form as long as it is `StableDeref`.\n* Rental structs can only have a maximum of 32 rental lifetimes, including transitive rental lifetimes from subrentals. This limitation is the result of needing to implement a new trait for each rental arity. This limit can be easily increased if necessary.\n* The references received in the constructor closures don't currently have their lifetime relationship to eachother expressed in bounds, since HRTB lifetimes do not currently support bounds. This is not a soundness hole, but it does prevent some otherwise valid uses from compiling.\n"
  },
  {
    "path": "rental-impl/Cargo.toml",
    "content": "[package]\nname = \"rental-impl\"\nversion = \"0.5.5\"\nlicense = \"MIT/Apache-2.0\"\nauthors = [\"Jameson Ernst <jameson@jpernst.com>\"]\ndescription = \"An implementation detail of rental. Should not be used directly.\"\nrepository = \"https://github.com/jpernst/rental\"\ndocumentation = \"https://docs.rs/rental\"\nhomepage = \"https://www.jpernst.com\"\n\n[lib]\nproc-macro = true\n\n[dependencies]\nproc-macro2 = \"1\"\nquote = \"1\"\nsyn = { version = \"1\", features = [\"full\", \"fold\", \"visit\", \"extra-traits\"] }\n"
  },
  {
    "path": "rental-impl/src/lib.rs",
    "content": "#![recursion_limit = \"512\"]\n\nextern crate proc_macro;\nextern crate proc_macro2;\n#[macro_use]\nextern crate syn;\n#[macro_use]\nextern crate quote;\n\nuse std::iter::{self, FromIterator};\nuse syn::spanned::Spanned;\nuse syn::visit::Visit;\nuse syn::fold::Fold;\nuse quote::ToTokens;\nuse proc_macro2::Span;\n\n\n/// From `procedural_masquerade` crate\n#[doc(hidden)]\nfn _extract_input(derive_input: &str) -> &str {\n\tlet mut input = derive_input;\n\n\tfor expected in &[\"#[allow(unused)]\", \"enum\", \"ProceduralMasqueradeDummyType\", \"{\", \"Input\", \"=\", \"(0,\", \"stringify!\", \"(\"] {\n\t\tinput = input.trim_start();\n\t\tassert!(input.starts_with(expected), \"expected prefix {:?} not found in {:?}\", expected, derive_input);\n\t\tinput = &input[expected.len()..];\n\t}\n\n\tfor expected in [\")\", \").0,\", \"}\"].iter().rev() {\n\t\tinput = input.trim_end();\n\t\tassert!(input.ends_with(expected), \"expected suffix {:?} not found in {:?}\", expected, derive_input);\n\t\tlet end = input.len() - expected.len();\n\t\tinput = &input[..end];\n\t}\n\n\tinput\n}\n\n\n#[doc(hidden)]\n#[allow(non_snake_case)]\n#[proc_macro_derive(__rental_traits)]\npub fn __rental_traits(input: proc_macro::TokenStream) -> proc_macro::TokenStream {\n\tlet mut tokens = proc_macro2::TokenStream::new();\n\n\tlet max_arity = _extract_input(&input.to_string()).parse::<usize>().expect(\"Input must be an integer literal.\");\n\twrite_rental_traits(&mut tokens, max_arity);\n\n\ttokens.into()\n}\n\n\n#[doc(hidden)]\n#[allow(non_snake_case)]\n#[proc_macro_derive(__rental_structs_and_impls)]\npub fn __rental_structs_and_impls(input: proc_macro::TokenStream) -> proc_macro::TokenStream {\n\tlet mut tokens = proc_macro2::TokenStream::new();\n\n\tfor item in syn::parse_str::<syn::File>(_extract_input(&input.to_string())).expect(\"Failed to parse items in module body.\").items.iter() {\n\t\tmatch *item {\n\t\t\tsyn::Item::Use(..) => {\n\t\t\t\titem.to_tokens(&mut tokens);\n\t\t\t},\n\t\t\tsyn::Item::Type(..) => {\n\t\t\t\titem.to_tokens(&mut tokens);\n\t\t\t},\n\t\t\tsyn::Item::Struct(ref struct_info) => {\n\t\t\t\twrite_rental_struct_and_impls(&mut tokens, &struct_info);\n\t\t\t},\n\t\t\t_ => panic!(\"Item must be a `use` or `struct`.\"),\n\t\t}\n\t}\n\n\ttokens.into()\n}\n\n\nfn write_rental_traits(tokens: &mut proc_macro2::TokenStream, max_arity: usize) {\n\tlet call_site: Span = Span::call_site();\n\n\tlet mut lt_params = vec![syn::LifetimeDef::new(syn::Lifetime::new(\"'a0\", call_site))];\n\n\tfor arity in 2 .. max_arity + 1 {\n\t\tlet trait_ident = &syn::Ident::new(&format!(\"Rental{}\", arity), call_site);\n\t\tlet lt_param = syn::LifetimeDef::new(syn::Lifetime::new(&format!(\"'a{}\", arity - 1), call_site));\n\t\tlt_params[arity - 2].bounds.push(lt_param.lifetime.clone());\n\t\tlt_params.push(lt_param);\n\n\t\tlet lt_params_iter = &lt_params;\n\t\tquote!(\n\t\t\t#[doc(hidden)]\n\t\t\tpub unsafe trait #trait_ident<#(#lt_params_iter),*> {\n\t\t\t\ttype Borrow;\n\t\t\t\ttype BorrowMut;\n\t\t\t}\n\t\t).to_tokens(tokens);\n\t}\n}\n\n\nfn write_rental_struct_and_impls(tokens: &mut proc_macro2::TokenStream, struct_info: &syn::ItemStruct) {\n\tlet def_site: Span = Span::call_site(); // FIXME: hygiene\n\tlet call_site: Span = Span::call_site();\n\n\tif let syn::Visibility::Inherited = struct_info.vis {\n\t\tpanic!(\"Struct `{}` must be non-private.\", struct_info.ident);\n\t}\n\n\tlet attribs = get_struct_attribs(struct_info);\n\tlet (fields, fields_brace) = prepare_fields(struct_info);\n\n\tlet struct_generics = &struct_info.generics;\n\tlet struct_rlt_args = &fields.iter().fold(Vec::new(), |mut rlt_args, field| { rlt_args.extend(field.self_rlt_args.iter()); rlt_args });\n\tif let Some(collide) = struct_rlt_args.iter().find(|rlt_arg| struct_generics.lifetimes().any(|lt_def| lt_def.lifetime == ***rlt_arg)) {\n\t\tpanic!(\"Struct `{}` lifetime parameter `{}` collides with rental lifetime.\", struct_info.ident, collide);\n\t}\n\tlet last_rlt_arg = &struct_rlt_args[struct_rlt_args.len() - 1];\n\tlet static_rlt_args = &iter::repeat(syn::Lifetime::new(\"'static\", def_site)).take(struct_rlt_args.len()).collect::<Vec<_>>();\n\tlet self_rlt_args = &iter::repeat(syn::Lifetime::new(\"'__s\", def_site)).take(struct_rlt_args.len()).collect::<Vec<_>>();\n\n\tlet item_ident = &struct_info.ident;\n\tlet item_vis = &struct_info.vis;\n\tlet item_ident_str = syn::LitStr::new(&item_ident.to_string(), item_ident.span());\n\n\tlet (struct_impl_params, struct_impl_args, struct_where_clause) = struct_generics.split_for_impl();\n\tlet where_extra = if let Some(ref struct_where_clause) = struct_where_clause {\n\t\tif struct_where_clause.predicates.is_empty() {\n\t\t\tquote!(where)\n\t\t} else if struct_where_clause.predicates.trailing_punct() {\n\t\t\tquote!()\n\t\t} else {\n\t\t\tquote!(,)\n\t\t}\n\t} else {\n\t\tquote!(where)\n\t};\n\tlet struct_lt_params = &struct_generics.lifetimes().collect::<Vec<_>>();\n\tlet struct_nonlt_params = &struct_generics.params.iter().filter(|param| if let syn::GenericParam::Lifetime(..) = **param { false } else { true }).collect::<Vec<_>>();\n\tlet struct_lt_args = &struct_lt_params.iter().map(|lt_def| &lt_def.lifetime).collect::<Vec<_>>();\n\n\tlet struct_nonlt_args = &struct_nonlt_params.iter().map(|param| match **param {\n\t\tsyn::GenericParam::Type(ref ty) => &ty.ident,\n\t\tsyn::GenericParam::Const(ref co) => &co.ident,\n\t\tsyn::GenericParam::Lifetime(..) => unreachable!(),\n\t}).collect::<Vec<_>>();\n\n\tlet rental_trait_ident = syn::Ident::new(&format!(\"Rental{}\", struct_rlt_args.len()), def_site);\n\tlet field_idents = &fields.iter().map(|field| &field.name).collect::<Vec<_>>();\n\tlet local_idents = field_idents;\n\tlet field_ident_strs = &field_idents.iter().map(|ident| syn::LitStr::new(&ident.to_string(), ident.span())).collect::<Vec<_>>();\n\n\tlet (ref self_ref_param, ref self_lt_ref_param, ref self_mut_param, ref self_move_param, ref self_arg) = if attribs.is_deref_suffix {\n\t\t(quote!(_self: &Self), quote!(_self: &'__s Self),  quote!(_self: &mut Self), quote!(_self: Self), quote!(_self))\n\t} else {\n\t\t(quote!(&self), quote!(&'__s self), quote!(&mut self), quote!(self), quote!(self))\n\t};\n\n\tlet borrow_ident = syn::Ident::new(&(struct_info.ident.to_string() + \"_Borrow\"), call_site);\n\tlet borrow_mut_ident = syn::Ident::new(&(struct_info.ident.to_string() + \"_BorrowMut\"), call_site);\n\tlet borrow_quotes = &make_borrow_quotes(self_arg, &fields, attribs.is_rental_mut);\n\tlet borrow_tys = &borrow_quotes.iter().map(|&BorrowQuotes{ref ty, ..}| ty).collect::<Vec<_>>();\n\tlet borrow_ty_hacks = &borrow_quotes.iter().map(|&BorrowQuotes{ref ty_hack, ..}| ty_hack).collect::<Vec<_>>();\n\tlet borrow_suffix_ty = &borrow_tys[fields.len() - 1];\n\tlet borrow_exprs = &borrow_quotes.iter().map(|&BorrowQuotes{ref expr, ..}| expr).collect::<Vec<_>>();\n\tlet borrow_suffix_expr = &borrow_exprs[fields.len() - 1];\n\tlet borrow_mut_tys = &borrow_quotes.iter().map(|&BorrowQuotes{ref mut_ty, ..}| mut_ty).collect::<Vec<_>>();\n\tlet borrow_mut_ty_hacks = &borrow_quotes.iter().map(|&BorrowQuotes{ref mut_ty_hack, ..}| mut_ty_hack).collect::<Vec<_>>();\n\tlet borrow_mut_suffix_ty = &borrow_mut_tys[fields.len() - 1];\n\tlet borrow_mut_exprs = &borrow_quotes.iter().map(|&BorrowQuotes{ref mut_expr, ..}| mut_expr).collect::<Vec<_>>();\n\tlet borrow_mut_suffix_expr = &borrow_mut_exprs[fields.len() - 1];\n\n\tlet struct_rlt_params = &struct_rlt_args.iter().zip(struct_rlt_args.iter().skip(1)).map(|(rlt_arg, next_rlt_arg)| {\n\t\tsyn::LifetimeDef {\n\t\t\tattrs: Vec::with_capacity(0),\n\t\t\tlifetime: (*rlt_arg).clone(),\n\t\t\tbounds: vec![(*next_rlt_arg).clone()].into_iter().collect(),\n\t\t\tcolon_token: Default::default(),\n\t\t}\n\t}).chain(Some(syn::LifetimeDef {\n\t\t\tattrs: Vec::with_capacity(0),\n\t\t\tlifetime: struct_rlt_args[struct_rlt_args.len() - 1].clone(),\n\t\t\tbounds: syn::punctuated::Punctuated::new(),\n\t\t\tcolon_token: Default::default(),\n\t})).collect::<Vec<_>>();\n\n\tlet borrow_lt_params = &struct_rlt_params.iter().cloned()\n\t\t.chain( struct_lt_params.iter().map(|lt_def| {\n\t\t\tlet mut lt_def = (*lt_def).clone();\n\t\t\tlt_def.bounds.push(struct_rlt_args[0].clone());\n\t\t\tlt_def\n\t\t})).collect::<Vec<_>>();\n\n\tlet field_tys = &fields.iter().map(|field| &field.erased.ty).collect::<Vec<_>>();\n\tlet head_ident = &local_idents[0];\n\tlet head_ident_rep = &iter::repeat(&head_ident).take(fields.len() - 1).collect::<Vec<_>>();\n\tlet head_ty = &fields[0].orig_ty;\n\tlet tail_tys = &field_tys.iter().skip(1).collect::<Vec<_>>();\n\tlet tail_idents = &local_idents.iter().skip(1).collect::<Vec<_>>();\n\tlet tail_closure_tys = &fields.iter().skip(1).map(|field| syn::Ident::new(&format!(\"__F{}\", field.name), call_site)).collect::<Vec<_>>();\n\tlet tail_closure_quotes = make_tail_closure_quotes(&fields, borrow_quotes, attribs.is_rental_mut);\n\tlet tail_closure_bounds = &tail_closure_quotes.iter().map(|&ClosureQuotes{ref bound, ..}| bound).collect::<Vec<_>>();\n\tlet tail_closure_exprs = &tail_closure_quotes.iter().map(|&ClosureQuotes{ref expr, ..}| expr).collect::<Vec<_>>();\n\tlet tail_try_closure_bounds = &tail_closure_quotes.iter().map(|&ClosureQuotes{ref try_bound, ..}| try_bound).collect::<Vec<_>>();\n\tlet tail_try_closure_exprs = &tail_closure_quotes.iter().map(|&ClosureQuotes{ref try_expr, ..}| try_expr).collect::<Vec<_>>();\n\tlet suffix_ident = &field_idents[fields.len() - 1];\n\tlet suffix_ty = &fields[fields.len() - 1].erased.ty;\n\tlet suffix_rlt_args = &fields[fields.len() - 1].self_rlt_args.iter().chain(fields[fields.len() - 1].used_rlt_args.iter()).collect::<Vec<_>>();\n\tlet suffix_ident_str = syn::LitStr::new(&suffix_ident.to_string(), suffix_ident.span());\n\tlet suffix_orig_ty = &fields[fields.len() - 1].orig_ty;\n\n\tlet rstruct = syn::ItemStruct{\n\t\tident: struct_info.ident.clone(),\n\t\tvis: item_vis.clone(),\n\t\tattrs: attribs.doc.clone(),\n\t\tfields: syn::Fields::Named(syn::FieldsNamed{\n\t\t\tbrace_token: fields_brace,\n\t\t\tnamed: fields.iter().enumerate().map(|(i, field)| {\n\t\t\t\tlet mut field_erased = field.erased.clone();\n\t\t\t\tif i < fields.len() - 1 {\n\t\t\t\t\tfield_erased.attrs.push(parse_quote!(#[allow(dead_code)]));\n\t\t\t\t}\n\t\t\t\tfield_erased\n\t\t\t}).rev().collect(),\n\t\t}),\n\t\tgenerics: struct_info.generics.clone(),\n\t\tstruct_token: struct_info.struct_token,\n\t\tsemi_token: None,\n\t};\n\n\tlet borrow_struct = syn::ItemStruct{\n\t\tident: borrow_ident.clone(),\n\t\tvis: item_vis.clone(),\n\t\tattrs: Vec::with_capacity(0),\n\t\tfields: syn::Fields::Named(syn::FieldsNamed{\n\t\t\tbrace_token: Default::default(),\n\t\t\tnamed: fields.iter().zip(borrow_tys).enumerate().map(|(idx, (field, borrow_ty))| {\n\t\t\t\tlet mut field = field.erased.clone();\n\t\t\t\tfield.vis = if !attribs.is_rental_mut || idx == fields.len() - 1 { item_vis.clone() } else { syn::Visibility::Inherited };\n\t\t\t\tfield.ty = syn::parse::<syn::Type>((**borrow_ty).clone().into()).unwrap();\n\t\t\t\tfield\n\t\t\t}).collect(),\n\t\t}),\n\t\tgenerics: {\n\t\t\tlet mut gen = struct_generics.clone();\n\t\t\tlet params = borrow_lt_params.iter().map(|lt| syn::GenericParam::Lifetime(lt.clone()))\n\t\t\t\t.chain(gen.type_params().map(|p| syn::GenericParam::Type(p.clone())))\n\t\t\t\t.chain(gen.const_params().map(|p| syn::GenericParam::Const(p.clone())))\n\t\t\t\t.collect();\n\t\t\tgen.params = params;\n\t\t\tgen\n\t\t},\n\t\tstruct_token: Default::default(),\n\t\tsemi_token: None,\n\t};\n\n\tlet borrow_mut_struct = syn::ItemStruct{\n\t\tident: borrow_mut_ident.clone(),\n\t\tvis: item_vis.clone(),\n\t\tattrs: Vec::with_capacity(0),\n\t\tfields: syn::Fields::Named(syn::FieldsNamed{\n\t\t\tbrace_token: Default::default(),\n\t\t\tnamed: fields.iter().zip(borrow_mut_tys).enumerate().map(|(idx, (field, borrow_mut_ty))| {\n\t\t\t\tlet mut field = field.erased.clone();\n\t\t\t\tfield.vis = if idx == fields.len() - 1 || !attribs.is_rental_mut { (*item_vis).clone() } else { syn::Visibility::Inherited };\n\t\t\t\tfield.ty = syn::parse::<syn::Type>((**borrow_mut_ty).clone().into()).unwrap();\n\t\t\t\tfield\n\t\t\t}).collect(),\n\t\t}),\n\t\tgenerics: {\n\t\t\tlet mut gen = struct_generics.clone();\n\t\t\tlet params = borrow_lt_params.iter().map(|lt| syn::GenericParam::Lifetime(lt.clone()))\n\t\t\t\t.chain(gen.type_params().map(|p| syn::GenericParam::Type(p.clone())))\n\t\t\t\t.chain(gen.const_params().map(|p| syn::GenericParam::Const(p.clone())))\n\t\t\t\t.collect();\n\t\t\tgen.params = params;\n\t\t\tgen\n\t\t},\n\t\tstruct_token: Default::default(),\n\t\tsemi_token: None,\n\t};\n\n\tlet prefix_tys = &fields.iter().map(|field| &field.erased.ty).take(fields.len() - 1).collect::<Vec<_>>();\n\tlet static_assert_prefix_stable_derefs = &prefix_tys.iter().map(|field| {\n\t\tif attribs.is_rental_mut {\n\t\t\tquote_spanned!(field.span()/*.resolved_at(def_site)*/ => __rental_prelude::static_assert_mut_stable_deref::<#field>();)\n\t\t} else {\n\t\t\tquote_spanned!(field.span()/*.resolved_at(def_site)*/ => __rental_prelude::static_assert_stable_deref::<#field>();)\n\t\t}\n\t}).collect::<Vec<_>>();\n\tlet prefix_clone_traits = iter::repeat(quote!(__rental_prelude::CloneStableDeref)).take(prefix_tys.len());\n\n\tlet struct_span = struct_info.span()/*.resolved_at(def_site)*/;\n\tlet suffix_ty_span = suffix_ty.span()/*.resolved_at(def_site)*/;\n\n\tquote_spanned!(struct_span =>\n\t\t#rstruct\n\n\t\t/// Shared borrow of a rental struct.\n\t\t#[allow(non_camel_case_types, non_snake_case, dead_code)]\n\t\t#borrow_struct\n\n\t\t/// Mutable borrow of a rental struct.\n\t\t#[allow(non_camel_case_types, non_snake_case, dead_code)]\n\t\t#borrow_mut_struct\n\t).to_tokens(tokens);\n\n\tquote_spanned!(struct_span =>\n\t\t#[allow(dead_code)]\n\t\timpl<#(#borrow_lt_params,)* #(#struct_nonlt_params),*> #borrow_ident<#(#struct_rlt_args,)* #(#struct_lt_args,)* #(#struct_nonlt_args),*> #struct_where_clause {\n\t\t\tfn unify_tys_hack(#(#local_idents: #borrow_ty_hacks),*) -> #borrow_ident<#(#struct_rlt_args,)* #(#struct_lt_args,)* #(#struct_nonlt_args),*> {\n\t\t\t\t#borrow_ident {\n\t\t\t\t\t#(#field_idents: #local_idents,)*\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t).to_tokens(tokens);\n\n\tquote_spanned!(struct_span =>\n\t\t#[allow(dead_code)]\n\t\timpl<#(#borrow_lt_params,)* #(#struct_nonlt_params),*> #borrow_mut_ident<#(#struct_rlt_args,)* #(#struct_lt_args,)* #(#struct_nonlt_args),*> #struct_where_clause {\n\t\t\tfn unify_tys_hack(#(#local_idents: #borrow_mut_ty_hacks),*) -> #borrow_mut_ident<#(#struct_rlt_args,)* #(#struct_lt_args,)* #(#struct_nonlt_args),*> {\n\t\t\t\t#borrow_mut_ident {\n\t\t\t\t\t#(#field_idents: #local_idents,)*\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t).to_tokens(tokens);\n\n\tquote_spanned!(struct_span =>\n\t\tunsafe impl<#(#borrow_lt_params,)* #(#struct_nonlt_params),*> __rental_prelude::#rental_trait_ident<#(#struct_rlt_args),*> for #item_ident #struct_impl_args #struct_where_clause {\n\t\t\ttype Borrow = #borrow_ident<#(#struct_rlt_args,)* #(#struct_lt_args,)* #(#struct_nonlt_args),*>;\n\t\t\ttype BorrowMut = #borrow_mut_ident<#(#struct_rlt_args,)* #(#struct_lt_args,)* #(#struct_nonlt_args),*>;\n\t\t}\n\t).to_tokens(tokens);\n\n\tquote_spanned!(struct_span =>\n\t\t#[allow(dead_code, unused_mut, unused_unsafe, non_camel_case_types)]\n\t\timpl #struct_impl_params #item_ident #struct_impl_args #struct_where_clause {\n\t\t\t/// Create a new instance of the rental struct.\n\t\t\t///\n\t\t\t/// The first argument provided is the head, followed by a series of closures, one for each tail field. Each of these closures will receive, as its arguments, a borrow of the previous field, followed by borrows of the remaining prefix fields if the struct is a shared rental. If the struct is a mutable rental, only the immediately preceding field is passed.\n\t\t\tpub fn new<#(#tail_closure_tys),*>(\n\t\t\t\tmut #head_ident: #head_ty,\n\t\t\t\t#(#tail_idents: #tail_closure_tys),*\n\t\t\t) -> Self where #(#tail_closure_tys: #tail_closure_bounds),*\n\t\t\t{\n\t\t\t\t#(#static_assert_prefix_stable_derefs)*\n\n\t\t\t\t#(let mut #tail_idents = unsafe { __rental_prelude::transmute::<_, #tail_tys>(#tail_closure_exprs) };)*\n\n\t\t\t\t#item_ident {\n\t\t\t\t\t#(#field_idents: #local_idents,)*\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t/// Attempt to create a new instance of the rental struct.\n\t\t\t///\n\t\t\t/// As `new`, but each closure returns a `Result`. If one of them fails, execution is short-circuited and a tuple of the error and the original head value is returned to you.\n\t\t\tpub fn try_new<#(#tail_closure_tys,)* __E>(\n\t\t\t\tmut #head_ident: #head_ty,\n\t\t\t\t#(#tail_idents: #tail_closure_tys),*\n\t\t\t) -> __rental_prelude::RentalResult<Self, __E, #head_ty> where\n\t\t\t\t#(#tail_closure_tys: #tail_try_closure_bounds,)*\n\t\t\t{\n\t\t\t\t#(#static_assert_prefix_stable_derefs)*\n\n\t\t\t\t#(let mut #tail_idents = {\n\t\t\t\t\tlet temp = #tail_try_closure_exprs.map(|t| unsafe { __rental_prelude::transmute::<_, #tail_tys>(t) });\n\t\t\t\t\tmatch temp {\n\t\t\t\t\t\t__rental_prelude::Result::Ok(t) => t,\n\t\t\t\t\t\t__rental_prelude::Result::Err(e) => return __rental_prelude::Result::Err(__rental_prelude::RentalError(e.into(), #head_ident_rep)),\n\t\t\t\t\t}\n\t\t\t\t};)*\n\n\t\t\t\t__rental_prelude::Result::Ok(#item_ident {\n\t\t\t\t\t#(#field_idents: #local_idents,)*\n\t\t\t\t})\n\t\t\t}\n\n\t\t\t/// Attempt to create a new instance of the rental struct.\n\t\t\t///\n\t\t\t/// As `try_new`, but only the error value is returned upon failure; the head value is dropped. This method interacts more smoothly with existing error conversions.\n\t\t\tpub fn try_new_or_drop<#(#tail_closure_tys,)* __E>(\n\t\t\t\tmut #head_ident: #head_ty,\n\t\t\t\t#(#tail_idents: #tail_closure_tys),*\n\t\t\t) -> __rental_prelude::Result<Self, __E> where\n\t\t\t\t#(#tail_closure_tys: #tail_try_closure_bounds,)*\n\t\t\t{\n\t\t\t\t#(#static_assert_prefix_stable_derefs)*\n\n\t\t\t\t#(let mut #tail_idents = {\n\t\t\t\t\tlet temp = #tail_try_closure_exprs.map(|t| unsafe { __rental_prelude::transmute::<_, #tail_tys>(t) });\n\t\t\t\t\tmatch temp {\n\t\t\t\t\t\t__rental_prelude::Result::Ok(t) => t,\n\t\t\t\t\t\t__rental_prelude::Result::Err(e) => return __rental_prelude::Result::Err(e.into()),\n\t\t\t\t\t}\n\t\t\t\t};)*\n\n\t\t\t\t__rental_prelude::Result::Ok(#item_ident {\n\t\t\t\t\t#(#field_idents: #local_idents,)*\n\t\t\t\t})\n\t\t\t}\n\n\t\t\t/// Return lifetime-erased shared borrows of the fields of the struct.\n\t\t\t///\n\t\t\t/// This is unsafe because the erased lifetimes are fake. Use this only if absolutely necessary and be very mindful of what the true lifetimes are.\n\t\t\tpub unsafe fn all_erased(#self_ref_param) -> <Self as __rental_prelude::#rental_trait_ident>::Borrow {\n\t\t\t\t#borrow_ident::unify_tys_hack(#(__rental_prelude::transmute(#borrow_exprs),)*)\n\t\t\t}\n\n\t\t\t/// Return a lifetime-erased mutable borrow of the suffix of the struct.\n\t\t\t///\n\t\t\t/// This is unsafe because the erased lifetimes are fake. Use this only if absolutely necessary and be very mindful of what the true lifetimes are.\n\t\t\tpub unsafe fn all_mut_erased(#self_mut_param) -> <Self as __rental_prelude::#rental_trait_ident>::BorrowMut {\n\t\t\t\t#borrow_mut_ident::unify_tys_hack(#(__rental_prelude::transmute(#borrow_mut_exprs),)*)\n\t\t\t}\n\n\t\t\t/// Execute a closure on the shared suffix of the struct.\n\t\t\t///\n\t\t\t/// The closure may return any value not bounded by one of the special rental lifetimes of the struct.\n\t\t\tpub fn rent<__F, __R>(#self_ref_param, f: __F) -> __R where\n\t\t\t\t__F: for<#(#suffix_rlt_args,)*> __rental_prelude::FnOnce(#borrow_suffix_ty) -> __R,\n\t\t\t\t__R: #(#struct_lt_args +)*,\n\t\t\t{\n\t\t\t\tf(#borrow_suffix_expr)\n\t\t\t}\n\n\t\t\t/// Execute a closure on the mutable suffix of the struct.\n\t\t\t///\n\t\t\t/// The closure may return any value not bounded by one of the special rental lifetimes of the struct.\n\t\t\tpub fn rent_mut<__F, __R>(#self_mut_param, f: __F) -> __R where\n\t\t\t\t__F: for<#(#suffix_rlt_args,)*> __rental_prelude::FnOnce(#borrow_mut_suffix_ty) -> __R,\n\t\t\t\t__R: #(#struct_lt_args +)*,\n\t\t\t{\n\t\t\t\tf(#borrow_mut_suffix_expr)\n\t\t\t}\n\n\t\t\t/// Return a shared reference from the shared suffix of the struct.\n\t\t\t///\n\t\t\t/// This is a subtle variation of `rent` where it is legal to return a reference bounded by a rental lifetime, because that lifetime is reborrowed away before it is returned to you.\n\t\t\tpub fn ref_rent<__F, __R>(#self_ref_param, f: __F) -> &__R where\n\t\t\t\t__F: for<#(#suffix_rlt_args,)*> __rental_prelude::FnOnce(#borrow_suffix_ty) -> &#last_rlt_arg __R,\n\t\t\t\t__R: ?Sized //#(#struct_lt_args +)*,\n\t\t\t{\n\t\t\t\tf(#borrow_suffix_expr)\n\t\t\t}\n\n\t\t\t/// Optionally return a shared reference from the shared suffix of the struct.\n\t\t\t///\n\t\t\t/// This is a subtle variation of `rent` where it is legal to return a reference bounded by a rental lifetime, because that lifetime is reborrowed away before it is returned to you.\n\t\t\tpub fn maybe_ref_rent<__F, __R>(#self_ref_param, f: __F) -> __rental_prelude::Option<&__R> where\n\t\t\t\t__F: for<#(#suffix_rlt_args,)*> __rental_prelude::FnOnce(#borrow_suffix_ty) -> __rental_prelude::Option<&#last_rlt_arg __R>,\n\t\t\t\t__R: ?Sized //#(#struct_lt_args +)*,\n\t\t\t{\n\t\t\t\tf(#borrow_suffix_expr)\n\t\t\t}\n\n\t\t\t/// Try to return a shared reference from the shared suffix of the struct, or an error on failure.\n\t\t\t///\n\t\t\t/// This is a subtle variation of `rent` where it is legal to return a reference bounded by a rental lifetime, because that lifetime is reborrowed away before it is returned to you.\n\t\t\tpub fn try_ref_rent<__F, __R, __E>(#self_ref_param, f: __F) -> __rental_prelude::Result<&__R, __E> where\n\t\t\t\t__F: for<#(#suffix_rlt_args,)*> __rental_prelude::FnOnce(#borrow_suffix_ty) -> __rental_prelude::Result<&#last_rlt_arg __R, __E>,\n\t\t\t\t__R: ?Sized //#(#struct_lt_args +)*,\n\t\t\t{\n\t\t\t\tf(#borrow_suffix_expr)\n\t\t\t}\n\n\t\t\t/// Return a mutable reference from the mutable suffix of the struct.\n\t\t\t///\n\t\t\t/// This is a subtle variation of `rent_mut` where it is legal to return a reference bounded by a rental lifetime, because that lifetime is reborrowed away before it is returned to you.\n\t\t\tpub fn ref_rent_mut<__F, __R>(#self_mut_param, f: __F) -> &mut __R where\n\t\t\t\t__F: for<#(#suffix_rlt_args,)*> __rental_prelude::FnOnce(#borrow_mut_suffix_ty) -> &#last_rlt_arg  mut __R,\n\t\t\t\t__R: ?Sized //#(#struct_lt_args +)*,\n\t\t\t{\n\t\t\t\tf(#borrow_mut_suffix_expr)\n\t\t\t}\n\n\t\t\t/// Optionally return a mutable reference from the mutable suffix of the struct.\n\t\t\t///\n\t\t\t/// This is a subtle variation of `rent_mut` where it is legal to return a reference bounded by a rental lifetime, because that lifetime is reborrowed away before it is returned to you.\n\t\t\tpub fn maybe_ref_rent_mut<__F, __R>(#self_mut_param, f: __F) -> __rental_prelude::Option<&mut __R> where\n\t\t\t\t__F: for<#(#suffix_rlt_args,)*> __rental_prelude::FnOnce(#borrow_mut_suffix_ty) -> __rental_prelude::Option<&#last_rlt_arg  mut __R>,\n\t\t\t\t__R: ?Sized //#(#struct_lt_args +)*,\n\t\t\t{\n\t\t\t\tf(#borrow_mut_suffix_expr)\n\t\t\t}\n\n\t\t\t/// Try to return a mutable reference from the mutable suffix of the struct, or an error on failure.\n\t\t\t///\n\t\t\t/// This is a subtle variation of `rent_mut` where it is legal to return a reference bounded by a rental lifetime, because that lifetime is reborrowed away before it is returned to you.\n\t\t\tpub fn try_ref_rent_mut<__F, __R, __E>(#self_mut_param, f: __F) -> __rental_prelude::Result<&mut __R, __E> where\n\t\t\t\t__F: for<#(#suffix_rlt_args,)*> __rental_prelude::FnOnce(#borrow_mut_suffix_ty) -> __rental_prelude::Result<&#last_rlt_arg  mut __R, __E>,\n\t\t\t\t__R: ?Sized //#(#struct_lt_args +)*,\n\t\t\t{\n\t\t\t\tf(#borrow_mut_suffix_expr)\n\t\t\t}\n\n\t\t\t/// Drop the rental struct and return the original head value to you.\n\t\t\tpub fn into_head(#self_move_param) -> #head_ty {\n\t\t\t\tlet Self{#head_ident, ..} = #self_arg;\n\t\t\t\t#head_ident\n\t\t\t}\n\t\t}\n\t).to_tokens(tokens);\n\n\tif !attribs.is_rental_mut {\n\t\tquote_spanned!(struct_span =>\n\t\t\t#[allow(dead_code)]\n\t\t\timpl #struct_impl_params #item_ident #struct_impl_args #struct_where_clause {\n\t\t\t\t/// Return a shared reference to the head field of the struct.\n\t\t\t\tpub fn head(#self_ref_param) -> &<#head_ty as __rental_prelude::Deref>::Target {\n\t\t\t\t\t&*#self_arg.#head_ident\n\t\t\t\t}\n\n\t\t\t\t/// Execute a closure on shared borrows of the fields of the struct.\n\t\t\t\t///\n\t\t\t\t/// The closure may return any value not bounded by one of the special rental lifetimes of the struct.\n\t\t\t\tpub fn rent_all<__F, __R>(#self_ref_param, f: __F) -> __R where\n\t\t\t\t\t__F: for<#(#struct_rlt_args,)*> __rental_prelude::FnOnce(#borrow_ident<#(#struct_rlt_args,)* #(#struct_lt_args,)* #(#struct_nonlt_args),*>) -> __R,\n\t\t\t\t\t__R: #(#struct_lt_args +)*,\n\t\t\t\t{\n\t\t\t\t\tf(unsafe { #item_ident::all_erased(#self_arg) })\n\t\t\t\t}\n\n\t\t\t\t/// Return a shared reference from shared borrows of the fields of the struct.\n\t\t\t\t///\n\t\t\t\t/// This is a subtle variation of `rent_all` where it is legal to return a reference bounded by a rental lifetime, because that lifetime is reborrowed away before it is returned to you.\n\t\t\t\tpub fn ref_rent_all<__F, __R>(#self_ref_param, f: __F) -> &__R where\n\t\t\t\t\t__F: for<#(#struct_rlt_args,)*> __rental_prelude::FnOnce(#borrow_ident<#(#struct_rlt_args,)* #(#struct_lt_args,)* #(#struct_nonlt_args),*>) -> &#last_rlt_arg __R,\n\t\t\t\t\t__R: ?Sized //#(#struct_lt_args +)*,\n\t\t\t\t{\n\t\t\t\t\tf(unsafe { #item_ident::all_erased(#self_arg) })\n\t\t\t\t}\n\n\t\t\t\t/// Optionally return a shared reference from shared borrows of the fields of the struct.\n\t\t\t\t///\n\t\t\t\t/// This is a subtle variation of `rent_all` where it is legal to return a reference bounded by a rental lifetime, because that lifetime is reborrowed away before it is returned to you.\n\t\t\t\tpub fn maybe_ref_rent_all<__F, __R>(#self_ref_param, f: __F) -> __rental_prelude::Option<&__R> where\n\t\t\t\t\t__F: for<#(#struct_rlt_args,)*> __rental_prelude::FnOnce(#borrow_ident<#(#struct_rlt_args,)* #(#struct_lt_args,)* #(#struct_nonlt_args),*>) -> __rental_prelude::Option<&#last_rlt_arg __R>,\n\t\t\t\t\t__R: ?Sized //#(#struct_lt_args +)*,\n\t\t\t\t{\n\t\t\t\t\tf(unsafe { #item_ident::all_erased(#self_arg) })\n\t\t\t\t}\n\n\t\t\t\t/// Try to return a shared reference from shared borrows of the fields of the struct, or an error on failure.\n\t\t\t\t///\n\t\t\t\t/// This is a subtle variation of `rent_all` where it is legal to return a reference bounded by a rental lifetime, because that lifetime is reborrowed away before it is returned to you.\n\t\t\t\tpub fn try_ref_rent_all<__F, __R, __E>(#self_ref_param, f: __F) -> __rental_prelude::Result<&__R, __E> where\n\t\t\t\t\t__F: for<#(#struct_rlt_args,)*> __rental_prelude::FnOnce(#borrow_ident<#(#struct_rlt_args,)* #(#struct_lt_args,)* #(#struct_nonlt_args),*>) -> __rental_prelude::Result<&#last_rlt_arg __R, __E>,\n\t\t\t\t\t__R: ?Sized //#(#struct_lt_args +)*,\n\t\t\t\t{\n\t\t\t\t\tf(unsafe { #item_ident::all_erased(#self_arg) })\n\t\t\t\t}\n\n\t\t\t\t/// Execute a closure on shared borrows of the prefix fields and a mutable borrow of the suffix field of the struct.\n\t\t\t\t///\n\t\t\t\t/// The closure may return any value not bounded by one of the special rental lifetimes of the struct.\n\t\t\t\tpub fn rent_all_mut<__F, __R>(#self_mut_param, f: __F) -> __R where\n\t\t\t\t\t__F: for<#(#struct_rlt_args,)*> __rental_prelude::FnOnce(#borrow_mut_ident<#(#struct_rlt_args,)* #(#struct_lt_args,)* #(#struct_nonlt_args),*>) -> __R,\n\t\t\t\t\t__R: #(#struct_lt_args +)*,\n\t\t\t\t{\n\t\t\t\t\tf(unsafe { #item_ident::all_mut_erased(#self_arg) })\n\t\t\t\t}\n\n\t\t\t\t/// Return a mutable reference from shared borrows of the prefix fields and a mutable borrow of the suffix field of the struct.\n\t\t\t\t///\n\t\t\t\t/// This is a subtle variation of `rent_all_mut` where it is legal to return a reference bounded by a rental lifetime, because that lifetime is reborrowed away before it is returned to you.\n\t\t\t\tpub fn ref_rent_all_mut<__F, __R>(#self_mut_param, f: __F) -> &mut __R where\n\t\t\t\t\t__F: for<#(#struct_rlt_args,)*> __rental_prelude::FnOnce(#borrow_mut_ident<#(#struct_rlt_args,)* #(#struct_lt_args,)* #(#struct_nonlt_args),*>) -> &#last_rlt_arg mut __R,\n\t\t\t\t\t__R: ?Sized //#(#struct_lt_args +)*,\n\t\t\t\t{\n\t\t\t\t\tf(unsafe { #item_ident::all_mut_erased(#self_arg) })\n\t\t\t\t}\n\n\t\t\t\t/// Optionally return a mutable reference from shared borrows of the prefix fields and a mutable borrow of the suffix field of the struct.\n\t\t\t\t///\n\t\t\t\t/// This is a subtle variation of `rent_all_mut` where it is legal to return a reference bounded by a rental lifetime, because that lifetime is reborrowed away before it is returned to you.\n\t\t\t\tpub fn maybe_ref_rent_all_mut<__F, __R>(#self_mut_param, f: __F) -> __rental_prelude::Option<&mut __R> where\n\t\t\t\t\t__F: for<#(#struct_rlt_args,)*> __rental_prelude::FnOnce(#borrow_mut_ident<#(#struct_rlt_args,)* #(#struct_lt_args,)* #(#struct_nonlt_args),*>) -> __rental_prelude::Option<&#last_rlt_arg mut __R>,\n\t\t\t\t\t__R: ?Sized //#(#struct_lt_args +)*,\n\t\t\t\t{\n\t\t\t\t\tf(unsafe { #item_ident::all_mut_erased(#self_arg) })\n\t\t\t\t}\n\n\t\t\t\t/// Try to return a mutable reference from shared borrows of the prefix fields and a mutable borrow of the suffix field of the struct, or an error on failure.\n\t\t\t\t///\n\t\t\t\t/// This is a subtle variation of `rent_all_mut` where it is legal to return a reference bounded by a rental lifetime, because that lifetime is reborrowed away before it is returned to you.\n\t\t\t\tpub fn try_ref_rent_all_mut<__F, __R, __E>(#self_mut_param, f: __F) -> __rental_prelude::Result<&mut __R, __E> where\n\t\t\t\t\t__F: for<#(#struct_rlt_args,)*> __rental_prelude::FnOnce(#borrow_mut_ident<#(#struct_rlt_args,)* #(#struct_lt_args,)* #(#struct_nonlt_args),*>) -> __rental_prelude::Result<&#last_rlt_arg mut __R, __E>,\n\t\t\t\t\t__R: ?Sized //#(#struct_lt_args +)*,\n\t\t\t\t{\n\t\t\t\t\tf(unsafe { #item_ident::all_mut_erased(#self_arg) })\n\t\t\t\t}\n\t\t\t}\n\t\t).to_tokens(tokens);\n\t}\n\n\tif attribs.is_debug {\n\t\tif attribs.is_rental_mut {\n\t\t\tquote_spanned!(struct_info.ident.span()/*.resolved_at(def_site)*/ =>\n\t\t\t\timpl #struct_impl_params __rental_prelude::fmt::Debug for #item_ident #struct_impl_args #struct_where_clause #where_extra #suffix_ty: __rental_prelude::fmt::Debug {\n\t\t\t\t\tfn fmt(&self, f: &mut __rental_prelude::fmt::Formatter) -> __rental_prelude::fmt::Result {\n\t\t\t\t\t\tf.debug_struct(#item_ident_str)\n\t\t\t\t\t\t\t.field(#suffix_ident_str, &self.#suffix_ident)\n\t\t\t\t\t\t\t.finish()\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t).to_tokens(tokens);\n\t\t} else {\n\t\t\tquote_spanned!(struct_info.ident.span()/*.resolved_at(def_site)*/ =>\n\t\t\t\timpl #struct_impl_params __rental_prelude::fmt::Debug for #item_ident #struct_impl_args #struct_where_clause #where_extra #(#field_tys: __rental_prelude::fmt::Debug),* {\n\t\t\t\t\tfn fmt(&self, f: &mut __rental_prelude::fmt::Formatter) -> __rental_prelude::fmt::Result {\n\t\t\t\t\t\tf.debug_struct(#item_ident_str)\n\t\t\t\t\t\t\t#(.field(#field_ident_strs, &self.#field_idents))*\n\t\t\t\t\t\t\t.finish()\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t).to_tokens(tokens);\n\t\t}\n\t}\n\n\tif attribs.is_clone {\n\t\tquote_spanned!(struct_info.ident.span()/*.resolved_at(def_site)*/ =>\n\t\t\timpl #struct_impl_params __rental_prelude::Clone for #item_ident #struct_impl_args #struct_where_clause #where_extra #(#prefix_tys: #prefix_clone_traits,)* #suffix_ty: __rental_prelude::Clone {\n\t\t\t\tfn clone(&self) -> Self {\n\t\t\t\t\t#item_ident {\n\t\t\t\t\t\t#(#local_idents: __rental_prelude::Clone::clone(&self.#field_idents),)*\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t).to_tokens(tokens);\n\t}\n\n//\tif fields[fields.len() - 1].subrental.is_some() {\n//\t\tquote_spanned!(struct_span =>\n//\t\t\timpl<#(#borrow_lt_params,)* #(#struct_nonlt_params),*> __rental_prelude::IntoSuffix for #borrow_ident<#(#struct_rlt_args,)* #(#struct_lt_args,)* #(#struct_nonlt_args),*> #struct_where_clause {\n//\t\t\t\ttype Suffix = <#borrow_suffix_ty as __rental_prelude::IntoSuffix>::Suffix;\n//\n//\t\t\t\t#[allow(non_shorthand_field_patterns)]\n//\t\t\t\tfn into_suffix(self) -> <Self as __rental_prelude::IntoSuffix>::Suffix {\n//\t\t\t\t\tlet #borrow_ident{#suffix_ident: suffix, ..};\n//\t\t\t\t\tsuffix.into_suffix()\n//\t\t\t\t}\n//\t\t\t}\n//\t\t).to_tokens(tokens);\n//\n//\t\tquote_spanned!(struct_span =>\n//\t\t\timpl<#(#borrow_lt_params,)* #(#struct_nonlt_params),*> __rental_prelude::IntoSuffix for #borrow_mut_ident<#(#struct_rlt_args,)* #(#struct_lt_args,)* #(#struct_nonlt_args),*> #struct_where_clause {\n//\t\t\t\ttype Suffix = <#borrow_mut_suffix_ty as __rental_prelude::IntoSuffix>::Suffix;\n//\n//\t\t\t\t#[allow(non_shorthand_field_patterns)]\n//\t\t\t\tfn into_suffix(self) -> <Self as __rental_prelude::IntoSuffix>::Suffix {\n//\t\t\t\t\tlet #borrow_mut_ident{#suffix_ident: suffix, ..};\n//\t\t\t\t\tsuffix.into_suffix()\n//\t\t\t\t}\n//\t\t\t}\n//\t\t).to_tokens(tokens);\n//\n//\t\tif attribs.is_deref_suffix {\n//\t\t\tquote_spanned!(suffix_ty_span =>\n//\t\t\t\timpl #struct_impl_params __rental_prelude::Deref for #item_ident #struct_impl_args #struct_where_clause {\n//\t\t\t\t\ttype Target = <#suffix_ty as __rental_prelude::Deref>::Target;\n//\n//\t\t\t\t\tfn deref(&self) -> &<Self as __rental_prelude::Deref>::Target {\n//\t\t\t\t\t\t#item_ident::ref_rent(self, |suffix| &**__rental_prelude::IntoSuffix::into_suffix(suffix))\n//\t\t\t\t\t}\n//\t\t\t\t}\n//\t\t\t).to_tokens(tokens);\n//\t\t}\n//\n//\t\tif attribs.is_deref_mut_suffix {\n//\t\t\tquote_spanned!(suffix_ty_span =>\n//\t\t\t\timpl #struct_impl_params __rental_prelude::DerefMut for #item_ident #struct_impl_args #struct_where_clause {\n//\t\t\t\t\tfn deref_mut(&mut self) -> &mut <Self as __rental_prelude::Deref>::Target {\n//\t\t\t\t\t\t#item_ident.ref_rent_mut(self, |suffix| &mut **__rental_prelude::IntoSuffix::into_suffix(suffix))\n//\t\t\t\t\t}\n//\t\t\t\t}\n//\t\t\t).to_tokens(tokens);\n//\t\t}\n//\t} else {\n\t\tquote_spanned!(struct_span =>\n\t\t\timpl<#(#borrow_lt_params,)* #(#struct_nonlt_params),*> __rental_prelude::IntoSuffix for #borrow_ident<#(#struct_rlt_args,)* #(#struct_lt_args,)* #(#struct_nonlt_args),*> #struct_where_clause {\n\t\t\t\ttype Suffix = #borrow_suffix_ty;\n\n\t\t\t\t#[allow(non_shorthand_field_patterns)]\n\t\t\t\tfn into_suffix(self) -> <Self as __rental_prelude::IntoSuffix>::Suffix {\n\t\t\t\t\tlet #borrow_ident{#suffix_ident: suffix, ..} = self;\n\t\t\t\t\tsuffix\n\t\t\t\t}\n\t\t\t}\n\t\t).to_tokens(tokens);\n\n\t\tquote_spanned!(struct_span =>\n\t\t\timpl<#(#borrow_lt_params,)* #(#struct_nonlt_params),*> __rental_prelude::IntoSuffix for #borrow_mut_ident<#(#struct_rlt_args,)* #(#struct_lt_args,)* #(#struct_nonlt_args),*> #struct_where_clause {\n\t\t\t\ttype Suffix = #borrow_mut_suffix_ty;\n\n\t\t\t\t#[allow(non_shorthand_field_patterns)]\n\t\t\t\tfn into_suffix(self) -> <Self as __rental_prelude::IntoSuffix>::Suffix {\n\t\t\t\t\tlet #borrow_mut_ident{#suffix_ident: suffix, ..} = self;\n\t\t\t\t\tsuffix\n\t\t\t\t}\n\t\t\t}\n\t\t).to_tokens(tokens);\n\n\t\tif attribs.is_deref_suffix {\n\t\t\tquote_spanned!(suffix_ty_span =>\n\t\t\t\timpl #struct_impl_params __rental_prelude::Deref for #item_ident #struct_impl_args #struct_where_clause #where_extra {\n\t\t\t\t\ttype Target = <#suffix_ty as __rental_prelude::Deref>::Target;\n\n\t\t\t\t\tfn deref(&self) -> &<Self as __rental_prelude::Deref>::Target {\n\t\t\t\t\t\t#item_ident::ref_rent(self, |suffix| &**suffix)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t).to_tokens(tokens);\n\t\t}\n\n\t\tif attribs.is_deref_mut_suffix {\n\t\t\tquote_spanned!(suffix_ty_span =>\n\t\t\t\timpl #struct_impl_params __rental_prelude::DerefMut for #item_ident #struct_impl_args #struct_where_clause {\n\t\t\t\t\tfn deref_mut(&mut self) -> &mut <Self as __rental_prelude::Deref>::Target {\n\t\t\t\t\t\t#item_ident::ref_rent_mut(self, |suffix| &mut **suffix)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t).to_tokens(tokens);\n\t\t}\n//\t}\n\n\tif attribs.is_deref_suffix {\n\t\tquote_spanned!(suffix_ty_span =>\n\t\t\timpl #struct_impl_params __rental_prelude::AsRef<<Self as __rental_prelude::Deref>::Target> for #item_ident #struct_impl_args #struct_where_clause {\n\t\t\t\tfn as_ref(&self) -> &<Self as __rental_prelude::Deref>::Target {\n\t\t\t\t\t&**self\n\t\t\t\t}\n\t\t\t}\n\t\t).to_tokens(tokens);\n\t}\n\n\tif attribs.is_deref_mut_suffix {\n\t\tquote_spanned!(suffix_ty_span =>\n\t\t\timpl #struct_impl_params __rental_prelude::AsMut<<Self as __rental_prelude::Deref>::Target> for #item_ident #struct_impl_args #struct_where_clause {\n\t\t\t\tfn as_mut(&mut self) -> &mut <Self as __rental_prelude::Deref>::Target {\n\t\t\t\t\t&mut **self\n\t\t\t\t}\n\t\t\t}\n\t\t).to_tokens(tokens);\n\t}\n\n\tif attribs.is_covariant {\n\t\tquote_spanned!(struct_info.ident.span()/*.resolved_at(def_site)*/ =>\n\t\t\t#[allow(dead_code)]\n\t\t\timpl #struct_impl_params #item_ident #struct_impl_args #struct_where_clause {\n\t\t\t\t/// Borrow all fields of the struct by reborrowing away the rental lifetimes.\n\t\t\t\t///\n\t\t\t\t/// This is safe because the lifetimes are verified to be covariant first.\n\t\t\t\tpub fn all<'__s>(#self_lt_ref_param) -> <Self as __rental_prelude::#rental_trait_ident>::Borrow {\n\t\t\t\t\tunsafe {\n\t\t\t\t\t\tlet _covariant = __rental_prelude::PhantomData::<#borrow_ident<#(#static_rlt_args,)* #(#struct_lt_args,)* #(#struct_nonlt_args),*>>;\n\t\t\t\t\t\tlet _covariant: __rental_prelude::PhantomData<#borrow_ident<#(#self_rlt_args,)* #(#struct_lt_args,)* #(#struct_nonlt_args),*>> = _covariant; \n\n\t\t\t\t\t\t#item_ident::all_erased(#self_arg)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t/// Borrow the suffix field of the struct by reborrowing away the rental lifetimes.\n\t\t\t\t///\n\t\t\t\t/// This is safe because the lifetimes are verified to be covariant first.\n\t\t\t\tpub fn suffix(#self_ref_param) -> <<Self as __rental_prelude::#rental_trait_ident>::Borrow as __rental_prelude::IntoSuffix>::Suffix {\n\t\t\t\t\t&#self_arg.#suffix_ident\n\t\t\t\t}\n\t\t\t}\n\t\t).to_tokens(tokens);\n\t}\n\n\tif let Some(ref map_suffix_param) = attribs.map_suffix_param {\n\t\tlet mut replacer = MapTyParamReplacer{\n\t\t\tty_param: map_suffix_param,\n\t\t};\n\n\t\tlet mapped_suffix_param = replacer.fold_type_param(map_suffix_param.clone());\n\t\tlet mapped_ty = replacer.fold_path(parse_quote!(#item_ident #struct_impl_args));\n\t\tlet mapped_suffix_ty = replacer.fold_type(suffix_orig_ty.clone());\n\n\t\tlet mut map_where_clause = syn::WhereClause{\n\t\t\twhere_token: Default::default(),\n\t\t\tpredicates: syn::punctuated::Punctuated::from_iter(\n\t\t\t\tstruct_generics.type_params().filter(|p| p.ident != map_suffix_param.ident).filter_map(|p| {\n\t\t\t\t\tlet mut mapped_param = p.clone();\n\t\t\t\t\tmapped_param.bounds = syn::punctuated::Punctuated::new();\n\n\t\t\t\t\tfor mapped_bound in p.bounds.iter().filter(|b| {\n\t\t\t\t\t\tlet mut finder = MapTyParamFinder {\n\t\t\t\t\t\t\tty_param: map_suffix_param,\n\t\t\t\t\t\t\tfound: false,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tfinder.visit_type_param_bound(b);\n\t\t\t\t\t\tfinder.found\n\t\t\t\t\t}).map(|b| {\n\t\t\t\t\t\tlet mut replacer = MapTyParamReplacer{\n\t\t\t\t\t\t\tty_param: map_suffix_param,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\treplacer.fold_type_param_bound(b.clone())\n\t\t\t\t\t}) {\n\t\t\t\t\t\tmapped_param.bounds.push(mapped_bound)\n\t\t\t\t\t}\n\n\t\t\t\t\tif mapped_param.bounds.len() > 0 {\n\t\t\t\t\t\tSome(syn::punctuated::Pair::Punctuated(parse_quote!(#mapped_param), Default::default()))\n\t\t\t\t\t} else {\n\t\t\t\t\t\tNone\n\t\t\t\t\t}\n\t\t\t\t}).chain(\n\t\t\t\t\tstruct_where_clause.iter().flat_map(|w| w.predicates.iter()).filter(|p| {\n\t\t\t\t\t\tlet mut finder = MapTyParamFinder {\n\t\t\t\t\t\t\tty_param: map_suffix_param,\n\t\t\t\t\t\t\tfound: false,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tfinder.visit_where_predicate(p);\n\t\t\t\t\t\tfinder.found\n\t\t\t\t\t}).map(|p| {\n\t\t\t\t\t\tlet mut replacer = MapTyParamReplacer{\n\t\t\t\t\t\t\tty_param: map_suffix_param,\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tsyn::punctuated::Pair::Punctuated(replacer.fold_where_predicate(p.clone()), Default::default())\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t)\n\t\t};\n\n\t\tlet mut try_map_where_clause = map_where_clause.clone();\n\t\tmap_where_clause.predicates.push(parse_quote!(\n\t\t\t__F: for<#(#suffix_rlt_args),*> __rental_prelude::FnOnce(#suffix_orig_ty) -> #mapped_suffix_ty\n\t\t));\n\t\ttry_map_where_clause.predicates.push(parse_quote!(\n\t\t\t__F: for<#(#suffix_rlt_args),*> __rental_prelude::FnOnce(#suffix_orig_ty) -> __rental_prelude::Result<#mapped_suffix_ty, __E>\n\t\t));\n\n\t\tquote_spanned!(struct_span =>\n\t\t\t#[allow(dead_code)]\n\t\t\timpl #struct_impl_params #item_ident #struct_impl_args #struct_where_clause {\n\t\t\t\t/// Maps the suffix field of the rental struct to a different type.\n\t\t\t\t///\n\t\t\t\t/// Consumes the rental struct and applies the closure to the suffix field. A new rental struct is then constructed with the original prefix and new suffix.\n\t\t\t\tpub fn map<#mapped_suffix_param, __F>(#self_move_param, __f: __F) -> #mapped_ty #map_where_clause {\n\t\t\t\t\tlet #item_ident{ #(#field_idents,)* } = #self_arg;\n\n\t\t\t\t\tlet #suffix_ident = __f(#suffix_ident);\n\n\t\t\t\t\t#item_ident{ #(#field_idents: #local_idents,)* }\n\t\t\t\t}\n\n\t\t\t\t/// Try to map the suffix field of the rental struct to a different type.\n\t\t\t\t///\n\t\t\t\t/// As `map`, but the closure may fail. Upon failure, the tail is dropped, and the error is returned to you along with the head.\n\t\t\t\tpub fn try_map<#mapped_suffix_param, __F, __E>(#self_move_param, __f: __F) -> __rental_prelude::RentalResult<#mapped_ty, __E, #head_ty> #try_map_where_clause {\n\t\t\t\t\tlet #item_ident{ #(#field_idents,)* } = #self_arg;\n\n\t\t\t\t\tmatch __f(#suffix_ident) {\n\t\t\t\t\t\t__rental_prelude::Result::Ok(#suffix_ident) => __rental_prelude::Result::Ok(#item_ident { #(#field_idents: #local_idents,)* }),\n\t\t\t\t\t\t__rental_prelude::Result::Err(__e) => __rental_prelude::Result::Err(__rental_prelude::RentalError(__e, #head_ident)),\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t/// Try to map the suffix field of the rental struct to a different type.\n\t\t\t\t///\n\t\t\t\t/// As `map`, but the closure may fail. Upon failure, the struct is dropped and the error is returned.\n\t\t\t\tpub fn try_map_or_drop<#mapped_suffix_param, __F, __E>(#self_move_param, __f: __F) -> __rental_prelude::Result<#mapped_ty, __E> #try_map_where_clause {\n\t\t\t\t\tlet #item_ident{ #(#field_idents,)* } = #self_arg;\n\n\t\t\t\t\tlet #suffix_ident = __f(#suffix_ident)?;\n\n\t\t\t\t\tOk(#item_ident{ #(#field_idents: #local_idents,)* })\n\t\t\t\t}\n\t\t\t}\n\t\t).to_tokens(tokens);\n\t}\n}\n\n\nfn get_struct_attribs(struct_info: &syn::ItemStruct) -> RentalStructAttribs\n{\n\tlet mut rattribs = struct_info.attrs.clone();\n\n\tlet mut is_rental_mut = false;\n\tlet mut is_debug = false;\n\tlet mut is_clone = false;\n\tlet mut is_deref_suffix = false;\n\tlet mut is_deref_mut_suffix = false;\n\tlet mut is_covariant = false;\n\tlet mut map_suffix_param = None;\n\n\tif let Some(rental_pos) = rattribs.iter()/*.filter(|attr| !attr.is_sugared_doc)*/.position(|attr| match attr.parse_meta().expect(&format!(\"Struct `{}` Attribute `{}` is not properly formatted.\", struct_info.ident, attr.path.clone().into_token_stream())) {\n\t\tsyn::Meta::Path(ref attr_ident) => {\n\t\t\tis_rental_mut = match attr_ident.segments.first().map(|s| s.ident.to_string()).as_ref().map(String::as_str) {\n\t\t\t\tSome(\"rental\") => false,\n\t\t\t\tSome(\"rental_mut\") => true,\n\t\t\t\t_ => return false,\n\t\t\t};\n\n\t\t\ttrue\n\t\t},\n\t\tsyn::Meta::List(ref list) => {\n\t\t\tis_rental_mut = match list.path.segments.first().map(|s| s.ident.to_string()).as_ref().map(String::as_str) {\n\t\t\t\tSome(\"rental\") => false,\n\t\t\t\tSome(\"rental_mut\") => true,\n\t\t\t\t_ => return false,\n\t\t\t};\n\n\t\t\tlet leftover = list.nested.iter().filter(|nested| {\n\t\t\t\tif let syn::NestedMeta::Meta(ref meta) = **nested {\n\t\t\t\t\tmatch *meta {\n\t\t\t\t\t\tsyn::Meta::Path(ref ident) => {\n\t\t\t\t\t\t\tmatch ident.segments.first().map(|s| s.ident.to_string()).as_ref().map(String::as_str) {\n\t\t\t\t\t\t\t\tSome(\"debug\") => {\n\t\t\t\t\t\t\t\t\tis_debug = true;\n\t\t\t\t\t\t\t\t\tfalse\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tSome(\"clone\") => {\n\t\t\t\t\t\t\t\t\tis_clone = true;\n\t\t\t\t\t\t\t\t\tfalse\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tSome(\"deref_suffix\") => {\n\t\t\t\t\t\t\t\t\tis_deref_suffix = true;\n\t\t\t\t\t\t\t\t\tfalse\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tSome(\"deref_mut_suffix\") => {\n\t\t\t\t\t\t\t\t\tis_deref_suffix = true;\n\t\t\t\t\t\t\t\t\tis_deref_mut_suffix = true;\n\t\t\t\t\t\t\t\t\tfalse\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tSome(\"covariant\") => {\n\t\t\t\t\t\t\t\t\tis_covariant = true;\n\t\t\t\t\t\t\t\t\tfalse\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tSome(\"map_suffix\") => {\n\t\t\t\t\t\t\t\t\tpanic!(\"Struct `{}` `map_suffix` flag expects ` = \\\"T\\\"`.\", struct_info.ident);\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t_ => true,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\tsyn::Meta::NameValue(ref name_value) => {\n\t\t\t\t\t\t\tmatch name_value.path.segments.first().map(|s| s.ident.to_string()).as_ref().map(String::as_str) {\n\t\t\t\t\t\t\t\tSome(\"map_suffix\") => {\n\t\t\t\t\t\t\t\t\tif let syn::Lit::Str(ref ty_param_str) = name_value.lit {\n\t\t\t\t\t\t\t\t\t\tlet ty_param_str = ty_param_str.value();\n\t\t\t\t\t\t\t\t\t\tlet ty_param = struct_info.generics.type_params().find(|ty_param| {\n\t\t\t\t\t\t\t\t\t\t\tif ty_param.ident.to_string() == ty_param_str {\n\t\t\t\t\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tfalse\n\t\t\t\t\t\t\t\t\t\t}).unwrap_or_else(|| {\n\t\t\t\t\t\t\t\t\t\t\tpanic!(\"Struct `{}` `map_suffix` param `{}` does not name a type parameter.\", struct_info.ident, ty_param_str);\n\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\tlet mut finder = MapTyParamFinder{\n\t\t\t\t\t\t\t\t\t\t\tty_param: &ty_param,\n\t\t\t\t\t\t\t\t\t\t\tfound: false,\n\t\t\t\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\t\t\t\tif struct_info.fields.iter().take(struct_info.fields.iter().count() - 1).any(|f| {\n\t\t\t\t\t\t\t\t\t\t\tfinder.found = false;\n\t\t\t\t\t\t\t\t\t\t\tfinder.visit_field(f);\n\t\t\t\t\t\t\t\t\t\t\tfinder.found\n\t\t\t\t\t\t\t\t\t\t}) {\n\t\t\t\t\t\t\t\t\t\t\tpanic!(\"Struct `{}` `map_suffix` type param `{}` appears in a prefix field.\", struct_info.ident, ty_param_str);\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\tfinder.found = false;\n\t\t\t\t\t\t\t\t\t\tfinder.visit_field(struct_info.fields.iter().last().unwrap());\n\t\t\t\t\t\t\t\t\t\tif !finder.found {\n\t\t\t\t\t\t\t\t\t\t\tpanic!(\"Struct `{}` `map_suffix` type param `{}` does not appear in the suffix field.\", struct_info.ident, ty_param_str);\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\tmap_suffix_param = Some(ty_param.clone());\n\t\t\t\t\t\t\t\t\t\tfalse\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tpanic!(\"Struct `{}` `map_suffix` flag expects ` = \\\"T\\\"`.\", struct_info.ident);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t_ => true,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t\t_ => true,\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\ttrue\n\t\t\t\t}\n\t\t\t}).count();\n\n\t\t\tif leftover > 0 {\n\t\t\t\tpanic!(\"Struct `{}` rental attribute takes optional arguments: `debug`, `clone`, `deref_suffix`, `deref_mut_suffix`, `covariant`, and `map_suffix = \\\"T\\\"`.\", struct_info.ident);\n\t\t\t}\n\n\t\t\ttrue\n\t\t},\n\t\t_ => false,\n\t}) {\n\t\trattribs.remove(rental_pos);\n\t} else {\n\t\tpanic!(\"Struct `{}` must have a `rental` or `rental_mut` attribute.\", struct_info.ident);\n\t}\n\n\tif rattribs.iter().any(|attr| attr.path != syn::parse_str::<syn::Path>(\"doc\").unwrap()) {\n\t\tpanic!(\"Struct `{}` must not have attributes other than one `rental` or `rental_mut`.\", struct_info.ident);\n\t}\n\n\tif is_rental_mut && is_clone {\n\t\tpanic!(\"Struct `{}` cannot be both `rental_mut` and `clone`.\", struct_info.ident);\n\t}\n\n\tRentalStructAttribs{\n\t\tdoc: rattribs,\n\t\tis_rental_mut: is_rental_mut,\n\t\tis_debug: is_debug,\n\t\tis_clone: is_clone,\n\t\tis_deref_suffix: is_deref_suffix,\n\t\tis_deref_mut_suffix: is_deref_mut_suffix,\n\t\tis_covariant: is_covariant,\n\t\tmap_suffix_param: map_suffix_param,\n\t}\n}\n\n\nfn prepare_fields(struct_info: &syn::ItemStruct) -> (Vec<RentalField>, syn::token::Brace) {\n\tlet def_site: Span = Span::call_site(); // FIXME: hygiene\n\tlet call_site: Span = Span::call_site();\n\n\tlet (fields, fields_brace) = match struct_info.fields {\n\t\tsyn::Fields::Named(ref fields) => (&fields.named, fields.brace_token),\n\t\tsyn::Fields::Unnamed(..) => panic!(\"Struct `{}` must not be a tuple struct.\", struct_info.ident),\n\t\t_ => panic!(\"Struct `{}` must have at least 2 fields.\", struct_info.ident),\n\t};\n\n\tif fields.len() < 2 {\n\t\tpanic!(\"Struct `{}` must have at least 2 fields.\", struct_info.ident);\n\t}\n\n\tlet mut rfields = Vec::with_capacity(fields.len());\n\tfor (field_idx, field) in fields.iter().enumerate() {\n\t\tif field.vis != syn::Visibility::Inherited {\n\t\t\tpanic!(\n\t\t\t\t\"Struct `{}` field `{}` must be private.\",\n\t\t\t\tstruct_info.ident,\n\t\t\t\tfield.ident.as_ref().map(|ident| ident.to_string()).unwrap_or_else(|| field_idx.to_string())\n\t\t\t);\n\t\t}\n\n\t\tlet mut rfattribs = field.attrs.clone();\n\t\tlet mut subrental = None;\n\t\tlet mut target_ty_hack = None;\n\n\t\tif let Some(sr_pos) = rfattribs.iter().position(|attr| match attr.parse_meta() {\n\t\t\tOk(syn::Meta::List(ref list)) if list.path.segments.first().map(|s| s.ident.to_string()).as_ref().map(String::as_str) == Some(\"subrental\") => {\n\t\t\t\tpanic!(\n\t\t\t\t\t\"`subrental` attribute on struct `{}` field `{}` expects ` = arity`.\",\n\t\t\t\t\tstruct_info.ident,\n\t\t\t\t\tfield.ident.as_ref().map(|ident| ident.to_string()).unwrap_or_else(|| field_idx.to_string())\n\t\t\t\t);\n\t\t\t},\n\t\t\tOk(syn::Meta::Path(ref word)) if word.segments.first().map(|s| s.ident.to_string()).as_ref().map(String::as_str) == Some(\"subrental\") => {\n\t\t\t\tpanic!(\n\t\t\t\t\t\"`subrental` attribute on struct `{}` field `{}` expects ` = arity`.\",\n\t\t\t\t\tstruct_info.ident,\n\t\t\t\t\tfield.ident.as_ref().map(|ident| ident.to_string()).unwrap_or_else(|| field_idx.to_string())\n\t\t\t\t);\n\t\t\t},\n\t\t\tOk(syn::Meta::NameValue(ref name_value)) if name_value.path.segments.first().map(|s| s.ident.to_string()).as_ref().map(String::as_str) == Some(\"subrental\") => {\n\t\t\t\tmatch name_value.lit {\n\t\t\t\t\tsyn::Lit::Int(ref arity) => {\n\t\t\t\t\t\tsubrental = Some(Subrental{\n\t\t\t\t\t\t\tarity: arity.base10_parse::<usize>().unwrap(),\n\t\t\t\t\t\t\trental_trait_ident: syn::Ident::new(&format!(\"Rental{}\", arity.base10_parse::<usize>().unwrap()), def_site),\n\t\t\t\t\t\t})\n\t\t\t\t\t},\n\t\t\t\t\t_ => panic!(\n\t\t\t\t\t\t\"`subrental` attribute on struct `{}` field `{}` expects ` = arity`.\",\n\t\t\t\t\t\tstruct_info.ident,\n\t\t\t\t\t\tfield.ident.as_ref().map(|ident| ident.to_string()).unwrap_or_else(|| field_idx.to_string())\n\t\t\t\t\t),\n\t\t\t\t}\n\n\t\t\t\ttrue\n\t\t\t},\n\t\t\t_ => false,\n\t\t}) {\n\t\t\trfattribs.remove(sr_pos);\n\t\t}\n\n\t\tif subrental.is_some() && field_idx == fields.len() - 1 {\n\t\t\tpanic!(\n\t\t\t\t\"struct `{}` field `{}` cannot be a subrental because it is the suffix field.\",\n\t\t\t\tstruct_info.ident,\n\t\t\t\tfield.ident.as_ref().map(|ident| ident.to_string()).unwrap_or_else(|| field_idx.to_string())\n\t\t\t);\n\t\t}\n\n\t\tif let Some(tth_pos) = rfattribs.iter().position(|a|\n\t\t\tmatch a.parse_meta() {\n\t\t\t\tOk(syn::Meta::NameValue(syn::MetaNameValue{ref path, lit: syn::Lit::Str(ref ty_str), ..})) if path.segments.first().map(|s| s.ident.to_string()).as_ref().map(String::as_str) == Some(\"target_ty\") => {\n\t\t\t\t\tif let Ok(ty) = syn::parse_str::<syn::Type>(&ty_str.value()) {\n\t\t\t\t\t\ttarget_ty_hack = Some(ty);\n\n\t\t\t\t\t\ttrue\n\t\t\t\t\t} else {\n\t\t\t\t\t\tpanic!(\n\t\t\t\t\t\t\t\"`target_ty` attribute on struct `{}` field `{}` has an invalid ty string.\",\n\t\t\t\t\t\t\tstruct_info.ident,\n\t\t\t\t\t\t\tfield.ident.as_ref().map(|ident| ident.to_string()).unwrap_or_else(|| field_idx.to_string())\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t_ => false,\n\t\t\t}\n\t\t) {\n\t\t\trfattribs.remove(tth_pos);\n\t\t}\n\n\t\tif field_idx == fields.len() - 1 && target_ty_hack.is_some() {\n\t\t\tpanic!(\n\t\t\t\t\"Struct `{}` field `{}` cannot have `target_ty` attribute because it is the suffix field.\",\n\t\t\t\tstruct_info.ident,\n\t\t\t\tfield.ident.as_ref().map(|ident| ident.to_string()).unwrap_or_else(|| field_idx.to_string())\n\t\t\t);\n\t\t}\n\n\t\tlet target_ty_hack = target_ty_hack.as_ref().map(|ty| (*ty).clone()).or_else(|| if field_idx < fields.len() - 1 {\n\t\t\tlet guess = if let syn::Type::Path(ref ty_path) = field.ty {\n\t\t\t\tmatch ty_path.path.segments[ty_path.path.segments.len() - 1] {\n\t\t\t\t\tsyn::PathSegment{ref ident, arguments: syn::PathArguments::AngleBracketed(syn::AngleBracketedGenericArguments{ref args, ..})} => {\n\t\t\t\t\t\tif let Some(&syn::GenericArgument::Type(ref ty)) = args.first() {\n\t\t\t\t\t\t\tif ident == \"Vec\" {\n\t\t\t\t\t\t\t\tSome(syn::Type::Slice(syn::TypeSlice{bracket_token: Default::default(), elem: Box::new(ty.clone())}))\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tSome(ty.clone())\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tNone\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tsyn::PathSegment{ref ident, arguments: syn::PathArguments::None} => {\n\t\t\t\t\t\tif ident == \"String\" {\n\t\t\t\t\t\t\tSome(parse_quote!(str))\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tNone\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t_ => {\n\t\t\t\t\t\tNone\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t} else if let syn::Type::Reference(syn::TypeReference{elem: ref box_ty, ..}) = field.ty {\n\t\t\t\tSome((**box_ty).clone())\n\t\t\t} else {\n\t\t\t\tNone\n\t\t\t};\n\n\t\t\tlet guess = guess.or_else(|| if field_idx == 0 {\n\t\t\t\tlet field_ty = &field.ty;\n\t\t\t\tSome(parse_quote!(<#field_ty as __rental_prelude::Deref>::Target))\n\t\t\t} else {\n\t\t\t\tNone\n\t\t\t});\n\n\t\t\tif guess.is_none() {\n\t\t\t\tpanic!(\"Struct `{}` field `{}` must be a type path with 1 type param, `String`, or a reference.\", struct_info.ident, field.ident.as_ref().unwrap())\n\t\t\t}\n\n\t\t\tguess\n\t\t} else {\n\t\t\tNone\n\t\t});\n\n\t\tif subrental.is_some() {\n\t\t\tif match target_ty_hack {\n\t\t\t\tSome(syn::Type::Path(ref ty_path)) => ty_path.qself.is_some(),\n\t\t\t\tSome(_) => true,\n\t\t\t\t_ => false,\n\t\t\t} {\n\t\t\t\tpanic!(\n\t\t\t\t\t\"Struct `{}` field `{}` must have an unqualified path for its `target_ty` to be a valid subrental.\",\n\t\t\t\t\tstruct_info.ident,\n\t\t\t\t\tfield.ident.as_ref().map(|ident| ident.to_string()).unwrap_or_else(|| field_idx.to_string())\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tlet target_ty_hack_erased = target_ty_hack.as_ref().map(|tth| {\n\t\t\tlet mut eraser = RentalLifetimeEraser{\n\t\t\t\tfields: &rfields,\n\t\t\t\tused_rlt_args: &mut Vec::new(),\n\t\t\t};\n\n\t\t\teraser.fold_type(tth.clone())\n\t\t});\n\n\t\tlet mut self_rlt_args = Vec::new();\n\t\tif let Some(Subrental{arity: sr_arity, ..}) = subrental {\n\t\t\tlet field_ident = field.ident.as_ref().unwrap();\n\t\t\tfor sr_idx in 0 .. sr_arity {\n\t\t\t\tself_rlt_args.push(syn::Lifetime::new(&format!(\"'{}_{}\", field_ident, sr_idx), call_site));\n\t\t\t}\n\t\t} else {\n\t\t\tlet field_ident = field.ident.as_ref().unwrap();\n\t\t\tself_rlt_args.push(syn::Lifetime::new(&format!(\"'{}\", field_ident), call_site));\n\t\t}\n\n\t\tlet mut used_rlt_args = Vec::new();\n\t\tlet rty = {\n\t\t\tlet mut eraser = RentalLifetimeEraser{\n\t\t\t\tfields: &rfields,\n\t\t\t\tused_rlt_args: &mut used_rlt_args,\n\t\t\t};\n\n\t\t\teraser.fold_type(field.ty.clone())\n\t\t};\n\n\t\tif rfattribs.iter().any(|attr| match attr.parse_meta() { Ok(syn::Meta::NameValue(syn::MetaNameValue{ref path, ..})) if path.segments.first().map(|s| s.ident.to_string()).as_ref().map(String::as_str) == Some(\"doc\") => false, _ => true }) {\n\t\t\tpanic!(\n\t\t\t\t\"Struct `{}` field `{}` must not have attributes other than one `subrental` and `target_ty`.\",\n\t\t\t\tstruct_info.ident,\n\t\t\t\tfield.ident.as_ref().map(|ident| ident.to_string()).unwrap_or_else(|| field_idx.to_string())\n\t\t\t);\n\t\t}\n\n\t\trfields.push(RentalField{\n\t\t\tname: field.ident.as_ref().unwrap().clone(),\n\t\t\torig_ty: field.ty.clone(),\n\t\t\terased: syn::Field{\n\t\t\t\tcolon_token: field.colon_token,\n\t\t\t\tident: field.ident.clone(),\n\t\t\t\tvis: field.vis.clone(),\n\t\t\t\tattrs: rfattribs,\n\t\t\t\tty: rty,\n\t\t\t},\n\t\t\tsubrental: subrental,\n\t\t\tself_rlt_args: self_rlt_args,\n\t\t\tused_rlt_args: used_rlt_args,\n\t\t\ttarget_ty_hack: target_ty_hack,\n\t\t\ttarget_ty_hack_erased: target_ty_hack_erased,\n\t\t});\n\t}\n\n\t(rfields, fields_brace)\n}\n\n\nfn make_borrow_quotes(self_arg: &proc_macro2::TokenStream, fields: &[RentalField], is_rental_mut: bool) -> Vec<BorrowQuotes> {\n\tlet call_site: Span = Span::call_site();\n\n\t(0 .. fields.len()).map(|idx| {\n\t\tlet (field_ty, deref) = if idx == fields.len() - 1 {\n\t\t\tlet orig_ty = &fields[idx].orig_ty;\n\t\t\t(\n\t\t\t\tquote!(#orig_ty),\n\t\t\t\tquote!()\n\t\t\t)\n\t\t} else {\n\t\t\tlet orig_ty = &fields[idx].orig_ty;\n\t\t\t(\n\t\t\t\tquote!(<#orig_ty as __rental_prelude::Deref>::Target),\n\t\t\t\tquote!(*)\n\t\t\t)\n\t\t};\n\n\t\tlet field_ty_hack = fields[idx].target_ty_hack.as_ref().unwrap_or(&fields[idx].orig_ty);\n\t\tlet field_ty_hack_erased = fields[idx].target_ty_hack_erased.as_ref().unwrap_or(&fields[idx].erased.ty);\n\n\t\tif let Some(ref subrental) = fields[idx].subrental {\n\t\t\tlet field_ident = &fields[idx].name;\n\t\t\tlet rental_trait_ident = &subrental.rental_trait_ident;\n\t\t\tlet field_rlt_args = &fields[idx].self_rlt_args;\n\n\t\t\tlet (ref borrow_ty_hack, ref borrow_mut_ty_hack, ref field_args) = if let syn::Type::Path(syn::TypePath{ref qself, path: ref ty_path}) = *field_ty_hack {\n\t\t\t\tlet seg_idx = ty_path.segments.len() - 1;\n\t\t\t\tlet ty_name = &ty_path.segments[seg_idx].ident.to_string();\n\n\t\t\t\tlet mut borrow_ty_path = ty_path.clone();\n\t\t\t\tborrow_ty_path.segments[seg_idx].ident = syn::Ident::new(&format!(\"{}_Borrow\", ty_name), call_site);\n\t\t\t\tborrow_ty_path.segments[seg_idx].arguments = syn::PathArguments::None;\n\n\t\t\t\tlet mut borrow_mut_ty_path = ty_path.clone();\n\t\t\t\tborrow_mut_ty_path.segments[seg_idx].ident = syn::Ident::new(&format!(\"{}_BorrowMut\", ty_name), call_site);\n\t\t\t\tborrow_mut_ty_path.segments[seg_idx].arguments = syn::PathArguments::None;\n\n\t\t\t\tmatch ty_path.segments[seg_idx].arguments {\n\t\t\t\t\tsyn::PathArguments::AngleBracketed(ref args) => {\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tsyn::Type::Path(syn::TypePath{qself: qself.clone(), path: borrow_ty_path}),\n\t\t\t\t\t\t\tsyn::Type::Path(syn::TypePath{qself: qself.clone(), path: borrow_mut_ty_path}),\n\t\t\t\t\t\t\targs.args.iter().collect::<Vec<_>>(),\n\t\t\t\t\t\t)\n\t\t\t\t\t},\n\t\t\t\t\tsyn::PathArguments::None => {\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tsyn::Type::Path(syn::TypePath{qself: qself.clone(), path: borrow_ty_path}),\n\t\t\t\t\t\t\tsyn::Type::Path(syn::TypePath{qself: qself.clone(), path: borrow_mut_ty_path}),\n\t\t\t\t\t\t\tVec::with_capacity(0),\n\t\t\t\t\t\t)\n\t\t\t\t\t},\n\t\t\t\t\t_ => panic!(\"Field `{}` must have angle-bracketed args.\", fields[idx].name),\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tpanic!(\"Field `{}` must be a type path.\", fields[idx].name)\n\t\t\t};\n\n\t\t\tBorrowQuotes {\n\t\t\t\tty: if idx == fields.len() - 1 || !is_rental_mut {\n\t\t\t\t\tquote!(<#field_ty as __rental_prelude::#rental_trait_ident<#(#field_rlt_args),*>>::Borrow)\n\t\t\t\t} else {\n\t\t\t\t\tquote!(__rental_prelude::PhantomData<<#field_ty as __rental_prelude::#rental_trait_ident<#(#field_rlt_args),*>>::Borrow>)\n\t\t\t\t},\n\t\t\t\tty_hack: if idx == fields.len() - 1 || !is_rental_mut {\n\t\t\t\t\tquote!(#borrow_ty_hack<#(#field_rlt_args,)* #(#field_args),*>)\n\t\t\t\t} else {\n\t\t\t\t\tquote!(__rental_prelude::PhantomData<#borrow_ty_hack<#(#field_rlt_args,)* #(#field_args),*>>)\n\t\t\t\t},\n\t\t\t\texpr: if idx == fields.len() - 1 || !is_rental_mut {\n\t\t\t\t\tquote!(unsafe { <#field_ty_hack_erased>::all_erased(&#deref #self_arg.#field_ident) })\n\t\t\t\t} else {\n\t\t\t\t\tquote!(__rental_prelude::PhantomData::<()>)\n\t\t\t\t},\n\n\t\t\t\tmut_ty: if idx == fields.len() - 1 {\n\t\t\t\t\tquote!(<#field_ty as __rental_prelude::#rental_trait_ident<#(#field_rlt_args),*>>::BorrowMut)\n\t\t\t\t} else if !is_rental_mut {\n\t\t\t\t\tquote!(<#field_ty as __rental_prelude::#rental_trait_ident<#(#field_rlt_args),*>>::Borrow)\n\t\t\t\t} else {\n\t\t\t\t\tquote!(__rental_prelude::PhantomData<<#field_ty as __rental_prelude::#rental_trait_ident<#(#field_rlt_args),*>>::BorrowMut>)\n\t\t\t\t},\n\t\t\t\tmut_ty_hack: if idx == fields.len() - 1 {\n\t\t\t\t\tquote!(#borrow_mut_ty_hack<#(#field_rlt_args,)* #(#field_args),*>)\n\t\t\t\t} else if !is_rental_mut {\n\t\t\t\t\tquote!(#borrow_ty_hack<#(#field_rlt_args,)* #(#field_args),*>)\n\t\t\t\t} else {\n\t\t\t\t\tquote!(__rental_prelude::PhantomData<#borrow_mut_ty_hack<#(#field_rlt_args,)* #(#field_args),*>>)\n\t\t\t\t},\n\t\t\t\tmut_expr: if idx == fields.len() - 1 {\n\t\t\t\t\tquote!(unsafe { <#field_ty_hack_erased>::all_mut_erased(&mut #deref #self_arg.#field_ident) })\n\t\t\t\t} else if !is_rental_mut {\n\t\t\t\t\tquote!(unsafe { <#field_ty_hack_erased>::all_erased(&#deref #self_arg.#field_ident) })\n\t\t\t\t} else {\n\t\t\t\t\tquote!(__rental_prelude::PhantomData::<()>)\n\t\t\t\t},\n\n\t\t\t\tnew_ty: if !is_rental_mut  {\n\t\t\t\t\t//quote!(<#field_ty as __rental_prelude::#rental_trait_ident<#(#field_rlt_args),*>>::Borrow)\n\t\t\t\t\tquote!(#borrow_ty_hack<#(#field_rlt_args,)* #(#field_args),*>)\n\t\t\t\t} else {\n\t\t\t\t\t//quote!(<#field_ty as __rental_prelude::#rental_trait_ident<#(#field_rlt_args),*>>::BorrowMut)\n\t\t\t\t\tquote!(#borrow_mut_ty_hack<#(#field_rlt_args,)* #(#field_args),*>)\n\t\t\t\t},\n\t\t\t\tnew_expr: if !is_rental_mut {\n\t\t\t\t\tquote!(unsafe { <#field_ty_hack_erased>::all_erased(&#deref #field_ident) })\n\t\t\t\t} else {\n\t\t\t\t\tquote!(unsafe { <#field_ty_hack_erased>::all_mut_erased(&mut #deref #field_ident) })\n\t\t\t\t},\n\t\t\t}\n\t\t} else {\n\t\t\tlet field_ident = &fields[idx].name;\n\t\t\tlet field_rlt_arg = &fields[idx].self_rlt_args[0];\n\n\t\t\tBorrowQuotes {\n\t\t\t\tty: if idx == fields.len() - 1 || !is_rental_mut {\n\t\t\t\t\tquote!(&#field_rlt_arg (#field_ty))\n\t\t\t\t} else {\n\t\t\t\t\tquote!(__rental_prelude::PhantomData<&#field_rlt_arg #field_ty>)\n\t\t\t\t},\n\t\t\t\tty_hack: if idx == fields.len() - 1 || !is_rental_mut {\n\t\t\t\t\tquote!(&#field_rlt_arg (#field_ty_hack))\n\t\t\t\t} else {\n\t\t\t\t\tquote!(__rental_prelude::PhantomData<&#field_rlt_arg #field_ty_hack>)\n\t\t\t\t},\n\t\t\t\texpr: if idx == fields.len() - 1 || !is_rental_mut {\n\t\t\t\t\tquote!(&#deref #self_arg.#field_ident)\n\t\t\t\t} else {\n\t\t\t\t\tquote!(__rental_prelude::PhantomData::<()>)\n\t\t\t\t},\n\n\t\t\t\tmut_ty: if idx == fields.len() - 1 {\n\t\t\t\t\tquote!(&#field_rlt_arg mut (#field_ty))\n\t\t\t\t} else if !is_rental_mut {\n\t\t\t\t\tquote!(&#field_rlt_arg (#field_ty))\n\t\t\t\t} else {\n\t\t\t\t\tquote!(__rental_prelude::PhantomData<&#field_rlt_arg mut #field_ty>)\n\t\t\t\t},\n\t\t\t\tmut_ty_hack: if idx == fields.len() - 1 {\n\t\t\t\t\tquote!(&#field_rlt_arg mut (#field_ty_hack))\n\t\t\t\t} else if !is_rental_mut {\n\t\t\t\t\tquote!(&#field_rlt_arg (#field_ty_hack))\n\t\t\t\t} else {\n\t\t\t\t\tquote!(__rental_prelude::PhantomData<&#field_rlt_arg mut #field_ty_hack>)\n\t\t\t\t},\n\t\t\t\tmut_expr: if idx == fields.len() - 1 {\n\t\t\t\t\tquote!(&mut #deref #self_arg.#field_ident)\n\t\t\t\t} else if !is_rental_mut {\n\t\t\t\t\tquote!(&#deref #self_arg.#field_ident)\n\t\t\t\t} else {\n\t\t\t\t\tquote!(__rental_prelude::PhantomData::<()>)\n\t\t\t\t},\n\n\t\t\t\tnew_ty: if !is_rental_mut {\n\t\t\t\t\t//quote!(&#field_rlt_arg #field_ty)\n\t\t\t\t\tquote!(&#field_rlt_arg (#field_ty_hack))\n\t\t\t\t} else {\n\t\t\t\t\t//quote!(&#field_rlt_arg mut #field_ty)\n\t\t\t\t\tquote!(&#field_rlt_arg mut (#field_ty_hack))\n\t\t\t\t},\n\t\t\t\tnew_expr: if !is_rental_mut {\n\t\t\t\t\tquote!(& #deref #field_ident)\n\t\t\t\t} else {\n\t\t\t\t\tquote!(&mut #deref #field_ident)\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\t}).collect()\n}\n\n\nfn make_tail_closure_quotes(fields: &[RentalField], borrows: &[BorrowQuotes], is_rental_mut: bool) -> Vec<ClosureQuotes> {\n\t(1 .. fields.len()).map(|idx| {\n\t\tlet local_name = &fields[idx].name;\n\t\tlet field_ty = &fields[idx].orig_ty;\n\n\t\tif !is_rental_mut {\n\t\t\tlet prev_new_tys_reverse = &borrows[0 .. idx].iter().map(|b| &b.new_ty).rev().collect::<Vec<_>>();\n\t\t\tlet prev_new_exprs_reverse = &borrows[0 .. idx].iter().map(|b| &b.new_expr).rev().collect::<Vec<_>>();;\n\t\t\tlet mut prev_rlt_args = Vec::<syn::Lifetime>::new();\n\t\t\tfor prev_field in &fields[0 .. idx] {\n\t\t\t\tprev_rlt_args.extend(prev_field.self_rlt_args.iter().cloned());\n\t\t\t}\n\t\t\tlet prev_rlt_args = &prev_rlt_args;\n\n\t\t\tClosureQuotes {\n\t\t\t\tbound: quote!(for<#(#prev_rlt_args),*> __rental_prelude::FnOnce(#(#prev_new_tys_reverse),*) -> #field_ty),\n\t\t\t\texpr: quote!(#local_name(#(#prev_new_exprs_reverse),*)),\n\t\t\t\ttry_bound: quote!(for<#(#prev_rlt_args),*> __rental_prelude::FnOnce(#(#prev_new_tys_reverse),*) -> __rental_prelude::Result<#field_ty, __E>),\n\t\t\t\ttry_expr: quote!(#local_name(#(#prev_new_exprs_reverse),*)),\n\t\t\t}\n\t\t} else {\n\t\t\tlet prev_new_ty = &borrows[idx - 1].new_ty;\n\t\t\tlet prev_new_expr = &borrows[idx - 1].new_expr;\n\t\t\tlet prev_rlt_args = &fields[idx - 1].self_rlt_args.iter().chain(&fields[idx - 1].used_rlt_args).collect::<Vec<_>>();\n\n\t\t\tClosureQuotes {\n\t\t\t\tbound: quote!(for<#(#prev_rlt_args),*> __rental_prelude::FnOnce(#prev_new_ty) -> #field_ty),\n\t\t\t\texpr: quote!(#local_name(#prev_new_expr)),\n\t\t\t\ttry_bound: quote!(for<#(#prev_rlt_args),*> __rental_prelude::FnOnce(#prev_new_ty) -> __rental_prelude::Result<#field_ty, __E>),\n\t\t\t\ttry_expr: quote!(#local_name(#prev_new_expr)),\n\t\t\t}\n\t\t}\n\t}).collect()\n}\n\n\nstruct RentalStructAttribs {\n\tpub doc: Vec<syn::Attribute>,\n\tpub is_rental_mut: bool,\n\tpub is_debug: bool,\n\tpub is_clone: bool,\n\tpub is_deref_suffix: bool,\n\tpub is_deref_mut_suffix: bool,\n\tpub is_covariant: bool,\n\tpub map_suffix_param: Option<syn::TypeParam>,\n}\n\n\nstruct RentalField {\n\tpub name: syn::Ident,\n\tpub orig_ty: syn::Type,\n\tpub erased: syn::Field,\n\tpub subrental: Option<Subrental>,\n\tpub self_rlt_args: Vec<syn::Lifetime>,\n\tpub used_rlt_args: Vec<syn::Lifetime>,\n\tpub target_ty_hack: Option<syn::Type>,\n\tpub target_ty_hack_erased: Option<syn::Type>,\n}\n\n\nstruct Subrental {\n\tarity: usize,\n\trental_trait_ident: syn::Ident,\n}\n\n\nstruct BorrowQuotes {\n\tpub ty: proc_macro2::TokenStream,\n\tpub ty_hack: proc_macro2::TokenStream,\n\tpub expr: proc_macro2::TokenStream,\n\tpub mut_ty: proc_macro2::TokenStream,\n\tpub mut_ty_hack: proc_macro2::TokenStream,\n\tpub mut_expr: proc_macro2::TokenStream,\n\tpub new_ty: proc_macro2::TokenStream,\n\tpub new_expr: proc_macro2::TokenStream,\n}\n\n\nstruct ClosureQuotes {\n\tpub bound: proc_macro2::TokenStream,\n\tpub expr: proc_macro2::TokenStream,\n\tpub try_bound: proc_macro2::TokenStream,\n\tpub try_expr: proc_macro2::TokenStream,\n}\n\n\nstruct RentalLifetimeEraser<'a> {\n\tpub fields: &'a [RentalField],\n\tpub used_rlt_args: &'a mut Vec<syn::Lifetime>,\n}\n\n\nimpl<'a> syn::fold::Fold for RentalLifetimeEraser<'a> {\n\tfn fold_lifetime(&mut self, lifetime: syn::Lifetime) -> syn::Lifetime {\n\t\tlet def_site: Span = Span::call_site(); // FIXME: hygiene\n\n\t\tif self.fields.iter().any(|field| field.self_rlt_args.contains(&lifetime)) {\n\t\t\tif !self.used_rlt_args.contains(&lifetime) {\n\t\t\t\tself.used_rlt_args.push(lifetime.clone());\n\t\t\t}\n\n\t\t\tsyn::Lifetime::new(\"'static\", def_site)\n\t\t} else {\n\t\t\tlifetime\n\t\t}\n\t}\n}\n\n\nstruct MapTyParamFinder<'p> {\n\tpub ty_param: &'p syn::TypeParam,\n\tpub found: bool,\n}\n\n\nimpl<'p, 'ast> syn::visit::Visit<'ast> for MapTyParamFinder<'p> {\n\tfn visit_path(&mut self, path: &'ast syn::Path) {\n\t\tif path.leading_colon.is_none() && path.segments.len() == 1 && path.segments[0].ident == self.ty_param.ident && path.segments[0].arguments == syn::PathArguments::None {\n\t\t\tself.found = true;\n\t\t} else {\n\t\t\tfor seg in &path.segments {\n\t\t\t\tself.visit_path_segment(seg)\n\t\t\t};\n\t\t}\n\t}\n}\n\n\nstruct MapTyParamReplacer<'p> {\n\tpub ty_param: &'p syn::TypeParam,\n}\n\n\nimpl<'p> syn::fold::Fold for MapTyParamReplacer<'p> {\n\tfn fold_path(&mut self, path: syn::Path) -> syn::Path {\n\t\tif path.leading_colon.is_none() && path.segments.len() == 1 && path.segments[0].ident == self.ty_param.ident && path.segments[0].arguments == syn::PathArguments::None {\n\t\t\tlet def_site: Span = Span::call_site(); // FIXME: hygiene\n\n\t\t\tsyn::Path{\n\t\t\t\tleading_colon: None,\n\t\t\t\tsegments: syn::punctuated::Punctuated::from_iter(Some(\n\t\t\t\t\tsyn::punctuated::Pair::End(syn::PathSegment{ident: syn::Ident::new(\"__U\", def_site), arguments: syn::PathArguments::None})\n\t\t\t\t)),\n\t\t\t}\n\t\t} else {\n\t\t\tlet syn::Path{\n\t\t\t\tleading_colon,\n\t\t\t\tsegments,\n\t\t\t} = path;\n\n\t\t\tsyn::Path{\n\t\t\t\tleading_colon: leading_colon,\n\t\t\t\tsegments: syn::punctuated::Punctuated::from_iter(segments.into_pairs().map(|p| match p {\n\t\t\t\t\tsyn::punctuated::Pair::Punctuated(seg, punc) => syn::punctuated::Pair::Punctuated(self.fold_path_segment(seg), punc),\n\t\t\t\t\tsyn::punctuated::Pair::End(seg) => syn::punctuated::Pair::End(self.fold_path_segment(seg)),\n\t\t\t\t}))\n\t\t\t}\n\t\t}\n\t}\n\n\n\tfn fold_type_param(&mut self, mut ty_param: syn::TypeParam) -> syn::TypeParam {\n\t\tif ty_param.ident == self.ty_param.ident {\n\t\t\tlet def_site: Span = Span::call_site(); // FIXME: hygiene\n\t\t\tty_param.ident = syn::Ident::new(\"__U\", def_site);\n\t\t}\n\n\t\tlet bounds = syn::punctuated::Punctuated::from_iter(ty_param.bounds.iter().map(|b| self.fold_type_param_bound(b.clone())));\n\t\tty_param.bounds = bounds;\n\n\t\tty_param\n\t}\n}\n\n\n"
  },
  {
    "path": "src/lib.rs",
    "content": "//! A macro to generate safe self-referential structs, plus premade types for common use cases.\n//! \n//! # Overview\n//! It can sometimes occur in the course of designing an API that it would be convenient, or even necessary, to allow fields within a struct to hold references to other fields within that same struct. Rust's concept of ownership and borrowing is powerful, but can't express such a scenario yet.\n//! \n//! Creating such a struct manually would require unsafe code to erase lifetime parameters from the field types. Accessing the fields directly would be completely unsafe as a result. This library addresses that issue by allowing access to the internal fields only under carefully controlled circumstances, through closures that are bounded by generic lifetimes to prevent infiltration or exfiltration of any data with an incorrect lifetime. In short, while the struct internally uses unsafe code to store the fields, the interface exposed to the consumer of the struct is completely safe. The implementation of this interface is subtle and verbose, hence the macro to automate the process.\n//! \n//! The API of this crate consists of the [`rental`](macro.rental.html) macro that generates safe self-referential structs, a few example instantiations to demonstrate the API provided by such structs (see [`examples`](examples/index.html)), and a module of premade instantiations to cover common use cases (see [`common`](common/index.html)).\n//! \n//! # Example\n//! One instance where this crate is useful is when working with `libloading`. That crate provides a `Library` struct that defines methods to borrow `Symbol`s from it. These symbols are bounded by the lifetime of the library, and are thus considered a borrow. Under normal circumstances, one would be unable to store both the library and the symbols within a single struct, but the macro defined in this crate allows you to define a struct that is capable of storing both simultaneously, like so:\n//! \n//! ```rust,ignore\n//! rental! {\n//!     pub mod rent_libloading {\n//!         use libloading;\n//! \n//!         #[rental(deref_suffix)] // This struct will deref to the Deref::Target of Symbol.\n//!         pub struct RentSymbol<S: 'static> {\n//!             lib: Box<libloading::Library>, // Library is boxed for StableDeref.\n//!             sym: libloading::Symbol<'lib, S>, // The 'lib lifetime borrows lib.\n//!         }\n//!     }\n//! }\n//! \n//! fn main() {\n//!     let lib = libloading::Library::new(\"my_lib.so\").unwrap(); // Open our dylib.\n//!     if let Ok(rs) = rent_libloading::RentSymbol::try_new(\n//!         Box::new(lib),\n//!         |lib| unsafe { lib.get::<extern \"C\" fn()>(b\"my_symbol\") }) // Loading symbols is unsafe.\n//!     {\n//!         (*rs)(); // Call our function\n//!     };\n//! }\n//! ```\n//! \n//! In this way we can store both the `Library` and the `Symbol` that borrows it in a single struct. We can even tell our struct to deref to the function pointer itself so we can easily call it. This is legal because the function pointer does not contain any of the special lifetimes introduced by the rental struct in its type signature, which means reborrowing will not expose them to the outside world. As an aside, the `unsafe` block for loading the symbol is necessary because the act of loading a symbol from a dylib is unsafe, and is unrelated to rental.\n//!\n//! **NOTE for Rust 2018:** Relying on implicit crate imports may cause compile errors in code generated by this macro. To avoid this, import the crate manually like so:\n//! ```rust,ignore\n//! #[macro_use]\n//! extern crate rental; \n//! ```\n//! \n//! # Limitations\n//! There are a few limitations with the current implementation due to bugs or pending features in rust itself. These will be lifted once the underlying language allows it.\n//! \n//! * Currently, the rental struct itself can only take lifetime parameters under certain conditions. These conditions are difficult to fully describe, but in general, a lifetime param of the rental struct itself must appear \"outside\" of any special rental lifetimes in the type signatures of the struct fields. To put it another way, replacing the rental lifetimes with `'static` must still produce legal types, otherwise it will not compile. In most situations this is fine, since most of the use cases for this library involve erasing all of the lifetimes anyway, but there's no reason why the head element of a rental struct shouldn't be able to take arbitrary lifetime params. This is currently impossible to fully support due to lack of an `'unsafe` lifetime or equivalent feature.\n//! * Prefix fields, and the head field if it IS a subrental, must be of the form `Foo<T>` where `Foo` is some `StableDeref` container, or rental will not be able to correctly guess the `Deref::Target` of the type. If you are using a custom type that does not fit this pattern, you can use the `target_ty` attribute on the field to manually specify the target type. If the head field is NOT a subrental, then it may have any form as long as it is `StableDeref`.\n//! * Rental structs can only have a maximum of 32 rental lifetimes, including transitive rental lifetimes from subrentals. This limitation is the result of needing to implement a new trait for each rental arity. This limit can be easily increased if necessary.\n//! * The references received in the constructor closures don't currently have their lifetime relationship to eachother expressed in bounds, since HRTB lifetimes do not currently support bounds. This is not a soundness hole, but it does prevent some otherwise valid uses from compiling.\n\n\n#![cfg_attr(not(feature = \"std\"), no_std)]\n\n#[cfg(feature = \"std\")]\nextern crate core;\n#[macro_use]\nextern crate rental_impl;\nextern crate stable_deref_trait;\n\n#[doc(hidden)]\npub use rental_impl::*;\n\n\n/// This trait converts any `*_Borrow` or `*_BorrowMut` structs generated by the [`rental`](macro.rental.html) macro into their suffix (most dependent) field.\n///\n/// When you own a borrow struct, such as in the body of the closure provided to the `rent_all` or `ref_rent_all` methods of a rental struct, you can call `into_suffix()` to discard the borrow struct and obtain the suffix field if you don't need any of the other fields.\npub trait IntoSuffix {\n\t/// Type of the transitive suffix of the borrow struct.\n\t///\n\t/// If the suffix field of the borrow struct is itself a borrow struct of a subrental, then this type is the suffix of that nested borrow struct, recursively.\n\ttype Suffix;\n\n\t/// Discard the borrow struct and return the transitive suffix field.\n\t///\n\t/// If the suffix field of the borrow struct is itself a borrow struct of a subrental, then this function will return the nested suffix of that borrow struct, recursively.\n\tfn into_suffix(self) -> <Self as IntoSuffix>::Suffix;\n}\n\n\n/// An error wrapper returned by the `try_new` method of a rental struct.\n///\n/// This will contain the first error returned by the closure chain, as well as the original head value you passed in so you can do something else with it.\npub struct RentalError<E, H> (pub E, pub H);\n\npub type RentalResult<T, E, H> = Result<T, RentalError<E, H>>;\n\n\nmacro_rules! define_rental_traits {\n\t($max_arity:expr) => {\n\t\t#[allow(unused)]\n\t\t#[derive(__rental_traits)]\n\t\tenum ProceduralMasqueradeDummyType {\n\t\t\tInput = (0, stringify!($max_arity)).0,\n\t\t}\n\t};\n}\n\n\n#[doc(hidden)]\npub mod __rental_prelude {\n\tpub use core::marker::PhantomData;\n\tpub use core::clone::Clone;\n\tpub use core::ops::{FnOnce, Deref, DerefMut, Drop};\n\tpub use core::convert::{AsRef, AsMut, Into};\n\tpub use core::borrow::{Borrow, BorrowMut};\n\tpub use core::mem::transmute;\n\tpub use core::result::Result;\n\tpub use core::option::Option;\n\tpub use core::fmt;\n\tpub use stable_deref_trait::{StableDeref, CloneStableDeref};\n\n\tpub use super::{IntoSuffix, RentalError, RentalResult};\n\n\n\tdefine_rental_traits!(32);\n\n\n\t#[inline(always)]\n\tpub fn static_assert_stable_deref<T: StableDeref>() { }\n\t#[inline(always)]\n\tpub fn static_assert_mut_stable_deref<T: DerefMut + StableDeref>() { }\n}\n\n\n/// The bedrock of this crate, this macro will generate self-referential structs.\n/// \n/// This macro is invoked in item position. The body parses as valid rust and contains no special syntax. Only certain constructs are allowed, and a few special attributes and lifetimes are recognized.\n/// \n/// To start, the top level item of the macro invocation must be a single module. This module will contain all items that the macro generates and export them to you. Within the module, only three types of items are accepted: `use` statements, type aliases, and struct definitions. The `use` statements and type aliases are passed directly through with no special consideration; the primary concern is the struct definitions.\n/// \n/// First, all struct definitions must have a `#[rental]` or `#[rental_mut]` attribute to indicate that they are self-referential. The `mut` variant indicates that the struct mutably borrows itself, while the normal attribute assumes shared borrows. These attributes also accept certain flags to enable specific features, described below.\n/// \n/// Next, the structs must have named fields (no tuple structs) and they must have at least 2 fields, since a struct with 1 field can't meaningfully reference itself anyway.\n/// \n/// The order of the fields is significant, as they are declared in order of least to most dependent. The first field, also referred to as the \"head\" of the struct, contains no self-references, the second field may borrow the first, the third field may borrow the second or first, and so on. The chain of fields after the head is called the \"tail\".\n/// \n/// Because rental structs are self-referential, special care is taken to ensure that moving the struct will not invalidate any internal references. This is accomplished by requiring all fields but the last one, collectively known as the \"prefix\" of the struct, to implement [`StableDeref`](https://crates.io/crates/stable_deref_trait). This is not required for the final field of the struct, known as the \"suffix\", since nothing holds a reference to it.\n///\n/// NOTE: Because of a workaround for a compiler bug, rental might not always correctly determine the `Deref::Target` type of your prefix fields. If you receive type errors when compiling, you can try using the `target_ty` attribute on the field of the struct. Set this attribute equal to a string that names the correct target type (e.g. `#[target_ty = \"[u8]\"]` for `Vec<u8>`.\n/// \n/// Each field that you declare creates a special lifetime of the same name that can be used by later fields to borrow it. This is how the referential relationships are established in the struct definition.\n/// \n/// This is a all a bit to chew on so far, so let's stop and take a look at an example:\n///\n/// ```rust\n/// # #[macro_use] extern crate rental;\n/// pub struct Foo { i: i32 }\n/// pub struct Bar<'a> { foo: &'a Foo }\n/// pub struct Qux<'a: 'b, 'b> { bar: &'b Bar<'a> }\n/// \n/// rental! {\n///     mod my_rentals {\n///         use super::*;\n///\n///         #[rental]\n///         pub struct MyRental {\n///             foo: Box<Foo>,\n///             bar: Box<Bar<'foo>>,\n///             qux: Qux<'foo, 'bar>,\n///         }\n///     }\n/// }\n/// # fn main () { }\n/// ```\n/// \n/// Here we see each field use the special lifetimes of the previous fields to establish the borrowing chain.\n/// \n/// In addition to the rental struct itself, two other structs are generated, with `_Borrow` and `_BorrowMut` appended to the original struct name (e.g. `MyRental_Borrow` and `MyRental_BorrowMut`). These structs contain the same fields as the original struct, but are borrows of the originals. These structs are passed into certain closures that you provide to the [`rent_all`](examples/struct.RentRef.html#method.rent_all) suite of methods to allow you access to the struct's fields. For mutable rentals, these structs will only contain a borrow of the suffix; the other fields will be erased with `PhantomData`.\n/// \n/// # Attribute Flags\n/// \n/// A `rental` or `rental_mut` attribute accepts various options that affect the code generated by the macro to add certain features if your type supports them. These flags are placed in parens after the attribute, similar to the `cfg` attribute, e.g. `#[rental(debug)]`.\n///\n/// ## debug\n/// If all the fields of your struct implement `Debug` then you can use the `debug` option on the rental attribute to gain a `Debug` impl on the struct itself. For mutable rental structs, only the suffix field needs to be `Debug`, as it is the only one that will be printed. The prefix fields are mutably borrowed so cannot be accessed while the suffix exists.\n///\n/// ## clone\n/// If the prefix fields of your struct impl `CloneStableDeref` (which means clones still deref to the same object), and the suffix field is `Clone`, then your rental struct can be `Clone` as well.\n///\n/// ## deref_suffix / deref_mut_suffix\n/// If the suffix field of the struct implements `Deref` or `DerefMut`, you can add a `deref_suffix` or `deref_mut_suffix` argument to the `rental` attribute on the struct. This will generate a `Deref` implementation for the rental struct itself that will deref through the suffix and return the borrow to you, for convenience. Note, however, that this will only be legal if none of the special rental lifetimes appear in the type signature of the deref target. If they do, exposing them to the outside world could result in unsafety, so this is not allowed and such a scenario will not compile.\n///\n/// ## covariant\n/// Since the true lifetime of a self-referential field is currently inexpressible in rust, the lifetimes the fields use internally are fake. This means that directly borrowing the fields of the struct would be quite unsafe. However, if we know that the type is covariant over its lifetime parameters, then we can reborrow away the fake rental lifetimes to something concrete and safe. This tag will provide methods that access the fields of the struct directly, while also ensuring that the covariance requirement is met, otherwise the struct will fail to compile. For an exmaple see [`SimpleRefCovariant`](examples/struct.SimpleRefCovariant.html).\n///\n/// ## map_suffix = \"T\"\n/// For rental structs that contain some kind of smart reference as their suffix field, such as a `Ref` or `MutexGuard`, it can be useful to be able to map the reference to another type. This option allows you to do so, given certain conditions. First, your rental struct must have a type parameter in the position that you want to map, such as `Ref<'head, T>` or `MutexGuard<'head, T>`. Second, this type param must ONLY be used in the suffix field. Specify the type parameter you wish to use with `map_suffix = \"T\"` where `T` is the name of the type param that satisfies these conditions. For an example of the methods this option provides, see [`SimpleRefMap`](examples/struct.SimpleRefMap.html).\n/// \n/// # Subrentals\n///\n/// Finally, there is one other capability to discuss. If a rental struct has been defined elsewhere, either in our own crate or in a dependency, we'd like to be able to chain our own rental struct off of it. In this way, we can use another rental struct as a sort of pre-packaged prefix of our own. As a variation on the above example, it would look like this:\n///\n/// ```rust\n/// # #[macro_use] extern crate rental;\n/// pub struct Foo { i: i32 }\n/// pub struct Bar<'a> { foo: &'a Foo }\n/// pub struct Qux<'a: 'b, 'b> { bar: &'b Bar<'a> }\n/// \n/// rental! {\n///     mod my_rentals {\n///         use super::*;\n///\n///         #[rental]\n///         pub struct OtherRental {\n///             foo: Box<Foo>,\n///             bar: Bar<'foo>,\n///         }\n///         \n///         #[rental]\n///         pub struct MyRental {\n///             #[subrental = 2]\n///             prefix: Box<OtherRental>,\n///             qux: Qux<'prefix_0, 'prefix_1>,\n///         }\n///     }\n/// }\n/// # fn main () { }\n/// ```\n/// \n/// The first rental struct is fairly standard, so we'll focus on the second one. The head field is given a `subrental` attribute and set equal to an integer indicating the arity. The arity of a rental struct is the number of special lifetimes it creates. As can be seen above, the first struct has two fields, neither of which is itself a subrental, so it has an arity of 2. The arity of the second struct would be 3, since it includes the two fields of the first rental as well as one new one. In this way, arity is transitive. So if we used our new struct itself as a subrental of yet another struct, we'd need to declare the field with `subrental = 3`. The special lifetimes created by a subrental are the field name followed by a `_` and a zero-based index. Also note that the suffix field cannot itself be a subrental, only prefix fields.\n/// \n/// This covers the essential capabilities of the macro itself. For details on the API of the structs themselves, see the [`examples`](examples/index.html) module.\n#[macro_export]\nmacro_rules! rental {\n\t{\n\t\t$(#[$attr:meta])*\n\t\tmod $rental_mod:ident {\n\t\t\t$($body:tt)*\n\t\t}\n\t} => {\n\t\t$(#[$attr])*\n\t\tmod $rental_mod {\n\t\t\t#[allow(unused_imports)]\n\t\t\tuse $crate::__rental_prelude;\n\n\t\t\t#[allow(unused)]\n\t\t\t#[derive(__rental_structs_and_impls)]\n\t\t\tenum ProceduralMasqueradeDummyType {\n\t\t\t\tInput = (0, stringify!($($body)*)).0,\n\t\t\t}\n\t\t}\n\t};\n\t{\n\t\t$(#[$attr:meta])*\n\t\tpub mod $rental_mod:ident {\n\t\t\t$($body:tt)*\n\t\t}\n\t} => {\n\t\t$(#[$attr])*\n\t\tpub mod $rental_mod {\n\t\t\t#[allow(unused_imports)]\n\t\t\tuse $crate::__rental_prelude;\n\n\t\t\t#[allow(unused)]\n\t\t\t#[derive(__rental_structs_and_impls)]\n\t\t\tenum ProceduralMasqueradeDummyType {\n\t\t\t\tInput = (0, stringify!($($body)*)).0,\n\t\t\t}\n\t\t}\n\t};\n\t{\n\t\t$(#[$attr:meta])*\n\t\tpub($($vis:tt)*) mod $rental_mod:ident {\n\t\t\t$($body:tt)*\n\t\t}\n\t} => {\n\t\t$(#[$attr])*\n\t\tpub($($vis)*) mod $rental_mod {\n\t\t\t#[allow(unused_imports)]\n\t\t\tuse $crate::__rental_prelude;\n\n\t\t\t#[allow(unused)]\n\t\t\t#[derive(__rental_structs_and_impls)]\n\t\t\tenum ProceduralMasqueradeDummyType {\n\t\t\t\tInput = (0, stringify!($($body)*)).0,\n\t\t\t}\n\t\t}\n\t};\n}\n\n\n#[cfg(feature = \"std\")]\nrental! {\n\t/// Example types that demonstrate the API generated by the rental macro.\n\tpub mod examples {\n\t\tuse std::sync;\n\n\t\t/// The simplest shared rental. The head is a boxed integer, and the suffix is a ref to that integer. This struct demonstrates the basic API that all shared rental structs have. See [`SimpleMut`](struct.SimpleMut.html) for the mutable analog.\n\t\t#[rental]\n\t\tpub struct SimpleRef {\n\t\t\thead: Box<i32>,\n\t\t\tiref: &'head i32,\n\t\t}\n\n\t\t/// The simplest mutable rental. Mutable rentals have a slightly different API; compare this struct to [`SimpleRef`](struct.SimpleRef.html) for the clearest picture of how they differ.\n\t\t#[rental_mut]\n\t\tpub struct SimpleMut {\n\t\t\thead: Box<i32>,\n\t\t\tiref: &'head mut i32,\n\t\t}\n\n\t\t/// Identical to [`SimpleRef`](struct.SimpleRef.html), but with the `debug` flag enabled. This will provide a `Debug` impl for the struct as long as all of the fields are `Debug`.\n\t\t#[rental(debug)]\n\t\tpub struct SimpleRefDebug {\n\t\t\thead: Box<i32>,\n\t\t\tiref: &'head i32,\n\t\t}\n\n\t\t/// Similar to [`SimpleRef`](struct.SimpleRef.html), but with the `clone` flag enabled. This will provide a `Clone` impl for the struct as long as the prefix fields are `CloneStableDeref` and the suffix is `Clone` . Notice that the head is an `Arc`, since a clone of an `Arc` will deref to the same object as the original.\n\t\t#[rental(clone)]\n\t\tpub struct SimpleRefClone {\n\t\t\thead: sync::Arc<i32>,\n\t\t\tiref: &'head i32,\n\t\t}\n\n\t\t/// Identical to [`SimpleRef`](struct.SimpleRef.html), but with the `deref_suffix` flag enabled. This will provide a `Deref` impl for the struct, which will in turn deref the suffix. Notice that this flag also removes the `self` param from all methods, replacing it with an explicit param. This prevents any rental methods from blocking deref.\n\t\t#[rental(deref_suffix)]\n\t\tpub struct SimpleRefDeref {\n\t\t\thead: Box<i32>,\n\t\t\tiref: &'head i32,\n\t\t}\n\n\t\t/// Identical to [`SimpleMut`](struct.SimpleMut.html), but with the `deref_mut_suffix` flag enabled. This will provide a `DerefMut` impl for the struct, which will in turn deref the suffix.Notice that this flag also removes the `self` param from all methods, replacing it with an explicit param. This prevents any rental methods from blocking deref.\n\t\t#[rental_mut(deref_mut_suffix)]\n\t\tpub struct SimpleMutDeref {\n\t\t\thead: Box<i32>,\n\t\t\tiref: &'head mut i32,\n\t\t}\n\n\t\t/// Identical to [`SimpleRef`](struct.SimpleRef.html), but with the `covariant` flag enabled. For rental structs where the field types have covariant lifetimes, this will allow you to directly borrow the fields, as they can be safely reborrowed to a shorter lifetime. See the [`all`](struct.SimpleRefCovariant.html#method.all) and [`suffix`](struct.SimpleRefCovariant.html#method.suffix) methods.\n\t\t#[rental(covariant)]\n\t\tpub struct SimpleRefCovariant {\n\t\t\thead: Box<i32>,\n\t\t\tiref: &'head i32,\n\t\t}\n\n\t\t/// Identical to [`SimpleRef`](struct.SimpleRef.html), but with the `map_suffix` flag enabled. This will allow the type of the suffix to be changed by mapping it to another instantiation of the same struct with the different type param. See the [`map`](struct.SimpleRefMap.html#method.map), [`try_map`](struct.SimpleRefMap.html#method.try_map), and [`try_map_or_drop`](struct.SimpleRefMap.html#method.try_map_or_drop) methods.\n\t\t#[rental(map_suffix = \"T\")]\n\t\tpub struct SimpleRefMap<T: 'static> {\n\t\t\thead: Box<i32>,\n\t\t\tiref: &'head T,\n\t\t}\n\t}\n}\n\n\n#[cfg(feature = \"std\")]\nrental! {\n\t/// Premade types for the most common use cases.\n\tpub mod common {\n\t\tuse std::ops::DerefMut;\n\t\tuse stable_deref_trait::StableDeref;\n\t\tuse std::cell;\n\t\tuse std::sync;\n\n\t\t/// Stores an owner and a shared reference in the same struct.\n\t\t///\n\t\t/// ```rust\n\t\t/// # extern crate rental;\n\t\t/// # use rental::common::RentRef;\n\t\t/// # fn main() {\n\t\t/// let r = RentRef::new(Box::new(5), |i| &*i);\n\t\t/// assert_eq!(*r, RentRef::rent(&r, |iref| **iref));\n\t\t/// # }\n\t\t/// ```\n\t\t#[rental(debug, clone, deref_suffix, covariant, map_suffix = \"T\")]\n\t\tpub struct RentRef<H: 'static + StableDeref, T: 'static> {\n\t\t\thead: H,\n\t\t\tsuffix: &'head T,\n\t\t}\n\n\t\t/// Stores an owner and a mutable reference in the same struct.\n\t\t///\n\t\t/// ```rust\n\t\t/// # extern crate rental;\n\t\t/// # use rental::common::RentMut;\n\t\t/// # fn main() {\n\t\t/// let mut r = RentMut::new(Box::new(5), |i| &mut *i);\n\t\t/// *r = 12;\n\t\t/// assert_eq!(12, RentMut::rent(&mut r, |iref| **iref));\n\t\t/// # }\n\t\t/// ```\n\t\t#[rental_mut(debug, deref_mut_suffix, covariant, map_suffix = \"T\")]\n\t\tpub struct RentMut<H: 'static + StableDeref + DerefMut, T: 'static> {\n\t\t\thead: H,\n\t\t\tsuffix: &'head mut T,\n\t\t}\n\n\t\t/// Stores a `RefCell` and a `Ref` in the same struct.\n\t\t///\n\t\t/// ```rust\n\t\t/// # extern crate rental;\n\t\t/// # use rental::common::RentRefCell;\n\t\t/// # fn main() {\n\t\t/// use std::cell;\n\t\t///\n\t\t/// let r = RentRefCell::new(Box::new(cell::RefCell::new(5)), |c| c.borrow());\n\t\t/// assert_eq!(*r, RentRefCell::rent(&r, |c| **c));\n\t\t/// # }\n\t\t/// ```\n\t\t#[rental(debug, clone, deref_suffix, covariant, map_suffix = \"T\")]\n\t\tpub struct RentRefCell<H: 'static + StableDeref, T: 'static> {\n\t\t\thead: H,\n\t\t\tsuffix: cell::Ref<'head, T>,\n\t\t}\n\n\t\t/// Stores a `RefCell` and a `RefMut` in the same struct.\n\t\t///\n\t\t/// ```rust\n\t\t/// # extern crate rental;\n\t\t/// # use rental::common::RentRefCellMut;\n\t\t/// # fn main() {\n\t\t/// use std::cell;\n\t\t///\n\t\t/// let mut r = RentRefCellMut::new(Box::new(cell::RefCell::new(5)), |c| c.borrow_mut());\n\t\t/// *r = 12;\n\t\t/// assert_eq!(12, RentRefCellMut::rent(&r, |c| **c));\n\t\t/// # }\n\t\t/// ```\n\t\t#[rental_mut(debug, deref_mut_suffix, covariant, map_suffix = \"T\")]\n\t\tpub struct RentRefCellMut<H: 'static + StableDeref + DerefMut, T: 'static> {\n\t\t\thead: H,\n\t\t\tsuffix: cell::RefMut<'head, T>,\n\t\t}\n\n\n\t\t/// Stores a `Mutex` and a `MutexGuard` in the same struct.\n\t\t///\n\t\t/// ```rust\n\t\t/// # extern crate rental;\n\t\t/// # use rental::common::RentMutex;\n\t\t/// # fn main() {\n\t\t/// use std::sync;\n\t\t///\n\t\t/// let mut r = RentMutex::new(Box::new(sync::Mutex::new(5)), |c| c.lock().unwrap());\n\t\t/// *r = 12;\n\t\t/// assert_eq!(12, RentMutex::rent(&r, |c| **c));\n\t\t/// # }\n\t\t/// ```\n\t\t#[rental(debug, clone, deref_mut_suffix, covariant, map_suffix = \"T\")]\n\t\tpub struct RentMutex<H: 'static + StableDeref + DerefMut, T: 'static> {\n\t\t\thead: H,\n\t\t\tsuffix: sync::MutexGuard<'head, T>,\n\t\t}\n\n\t\t/// Stores an `RwLock` and an `RwLockReadGuard` in the same struct.\n\t\t///\n\t\t/// ```rust\n\t\t/// # extern crate rental;\n\t\t/// # use rental::common::RentRwLock;\n\t\t/// # fn main() {\n\t\t/// use std::sync;\n\t\t///\n\t\t/// let r = RentRwLock::new(Box::new(sync::RwLock::new(5)), |c| c.read().unwrap());\n\t\t/// assert_eq!(*r, RentRwLock::rent(&r, |c| **c));\n\t\t/// # }\n\t\t/// ```\n\t\t#[rental(debug, clone, deref_suffix, covariant, map_suffix = \"T\")]\n\t\tpub struct RentRwLock<H: 'static + StableDeref, T: 'static> {\n\t\t\thead: H,\n\t\t\tsuffix: sync::RwLockReadGuard<'head, T>,\n\t\t}\n\n\t\t/// Stores an `RwLock` and an `RwLockWriteGuard` in the same struct.\n\t\t///\n\t\t/// ```rust\n\t\t/// # extern crate rental;\n\t\t/// # use rental::common::RentRwLockMut;\n\t\t/// # fn main() {\n\t\t/// use std::sync;\n\t\t///\n\t\t/// let mut r = RentRwLockMut::new(Box::new(sync::RwLock::new(5)), |c| c.write().unwrap());\n\t\t/// *r = 12;\n\t\t/// assert_eq!(12, RentRwLockMut::rent(&r, |c| **c));\n\t\t/// # }\n\t\t/// ```\n\t\t#[rental(debug, clone, deref_mut_suffix, covariant, map_suffix = \"T\")]\n\t\tpub struct RentRwLockMut<H: 'static + StableDeref, T: 'static> {\n\t\t\thead: H,\n\t\t\tsuffix: sync::RwLockWriteGuard<'head, T>,\n\t\t}\n\t}\n}\n\n\n"
  },
  {
    "path": "tests/clone.rs",
    "content": "#[macro_use]\nextern crate rental;\n\n\npub struct Foo {\n\ti: i32,\n}\n\npub struct Bar<'i> {\n\tiref: &'i i32,\n\tmisc: i32,\n}\n\nimpl <'i> Clone for Bar<'i> {\n\tfn clone (&self) -> Self {\n\t\tBar{\n\t\t\tiref: Clone::clone(&self.iref),\n\t\t\tmisc: Clone::clone(&self.misc),\n\t\t}\n\t}\n}\n\n\nrental! {\n\tmod rentals {\n\t\tuse super::*;\n\t\tuse std::sync::Arc;\n\n\t\t#[rental(clone)]\n\t\tpub struct FooClone {\n\t\t\tfoo: Arc<Foo>,\n\t\t\tfr: Bar<'foo>,\n\t\t}\n\t}\n}\n\n\n#[test]\nfn clone() {\n\tuse std::sync::Arc;\n\n\tlet foo = Foo { i: 5 };\n\tlet rf = rentals::FooClone::new(Arc::new(foo), |foo| Bar{ iref: &foo.i, misc: 12 });\n\tassert_eq!(5, rf.rent(|f| *f.iref));\n\n\tlet rfc = rf.clone();\n\tassert_eq!(5, rfc.rent(|f| *f.iref));\n}\n\n\n"
  },
  {
    "path": "tests/complex.rs",
    "content": "#[macro_use]\nextern crate rental;\n\n\npub struct Foo {\n\ti: i32,\n}\n\npub struct Bar<'a> {\n\tfoo: &'a Foo,\n}\n\npub struct Baz<'a: 'b, 'b> {\n\tbar: &'b Bar<'a>\n}\n\npub struct Qux<'a: 'b, 'b: 'c, 'c> {\n\tbaz: &'c Baz<'a, 'b>\n}\n\npub struct Xyzzy<'a: 'b, 'b: 'c, 'c: 'd, 'd> {\n\tqux: &'d Qux<'a, 'b, 'c>\n}\n\n\nimpl Foo {\n\tpub fn borrow<'a>(&'a self) -> Bar<'a> { Bar { foo: self } }\n\tpub fn try_borrow<'a>(&'a self) -> Result<Bar<'a>, ()> { Ok(Bar { foo: self }) }\n\tpub fn fail_borrow<'a>(&'a self) -> Result<Bar<'a>, ()> { Err(()) }\n}\n\nimpl<'a> Bar<'a> {\n\tpub fn borrow<'b>(&'b self) -> Baz<'a, 'b> { Baz { bar: self } }\n\tpub fn try_borrow<'b>(&'b self) -> Result<Baz<'a, 'b>, ()> { Ok(Baz { bar: self }) }\n\tpub fn fail_borrow<'b>(&'b self) -> Result<Baz<'a, 'b>, ()> { Err(()) }\n}\n\nimpl<'a: 'b, 'b> Baz<'a, 'b> {\n\tpub fn borrow<'c>(&'c self) -> Qux<'a, 'b, 'c> { Qux { baz: self } }\n\tpub fn try_borrow<'c>(&'c self) -> Result<Qux<'a, 'b, 'c>, ()> { Ok(Qux { baz: self }) }\n\tpub fn fail_borrow<'c>(&'c self) -> Result<Qux<'a, 'b, 'c>, ()> { Err(()) }\n}\n\nimpl<'a: 'b, 'b: 'c, 'c> Qux<'a, 'b, 'c> {\n\tpub fn borrow<'d>(&'d self) -> Xyzzy<'a, 'b, 'c, 'd> { Xyzzy { qux: self } }\n\tpub fn try_borrow<'d>(&'d self) -> Result<Xyzzy<'a, 'b, 'c, 'd>, ()> { Ok(Xyzzy { qux: self }) }\n\tpub fn fail_borrow<'d>(&'d self) -> Result<Xyzzy<'a, 'b, 'c, 'd>, ()> { Err(()) }\n}\n\n\nrental! {\n\tmod rentals {\n\t\tuse super::*;\n\n\t\t#[rental]\n\t\tpub struct ComplexRent {\n\t\t\tfoo: Box<Foo>,\n\t\t\tbar: Box<Bar<'foo>>,\n\t\t\tbaz: Box<Baz<'foo, 'bar>>,\n\t\t\tqux: Box<Qux<'foo, 'bar, 'baz>>,\n\t\t\txyzzy: Xyzzy<'foo, 'bar, 'baz, 'qux>,\n\t\t}\n\t}\n}\n\n\n#[test]\nfn new() {\n\tlet foo = Foo { i: 5 };\n\tlet _ = rentals::ComplexRent::new(\n\t\tBox::new(foo),\n\t\t|foo| Box::new(foo.borrow()),\n\t\t|bar, _| Box::new(bar.borrow()),\n\t\t|baz, _, _| Box::new(baz.borrow()),\n\t\t|qux, _, _, _| qux.borrow()\n\t);\n\n\tlet foo = Foo { i: 5 };\n\tlet cr = rentals::ComplexRent::try_new(\n\t\tBox::new(foo),\n\t\t|foo| foo.try_borrow().map(|bar| Box::new(bar)),\n\t\t|bar, _| bar.try_borrow().map(|baz| Box::new(baz)),\n\t\t|baz, _, _| baz.try_borrow().map(|qux| Box::new(qux)),\n\t\t|qux, _, _, _| qux.try_borrow()\n\t);\n\tassert!(cr.is_ok());\n\n\tlet foo = Foo { i: 5 };\n\tlet cr = rentals::ComplexRent::try_new(\n\t\tBox::new(foo),\n\t\t|foo| foo.try_borrow().map(|bar| Box::new(bar)),\n\t\t|bar, _| bar.try_borrow().map(|baz| Box::new(baz)),\n\t\t|baz, _, _| baz.try_borrow().map(|qux| Box::new(qux)),\n\t\t|qux, _, _, _| qux.fail_borrow()\n\t);\n\tassert!(cr.is_err());\n}\n\n\n#[test]\nfn read() {\n\tlet foo = Foo { i: 5 };\n\tlet cr = rentals::ComplexRent::new(\n\t\tBox::new(foo),\n\t\t|foo| Box::new(foo.borrow()),\n\t\t|bar, _| Box::new(bar.borrow()),\n\t\t|baz, _, _| Box::new(baz.borrow()),\n\t\t|qux, _, _, _| qux.borrow()\n\t);\n\tlet i = cr.rent(|xyzzy| xyzzy.qux.baz.bar.foo.i);\n\tassert_eq!(i, 5);\n\n\tlet iref = cr.ref_rent(|xyzzy| &xyzzy.qux.baz.bar.foo.i);\n\tassert_eq!(*iref, 5);\n}\n"
  },
  {
    "path": "tests/complex_mut.rs",
    "content": "#[macro_use]\nextern crate rental;\n\n\npub struct Foo {\n\ti: i32,\n}\n\npub struct Bar<'a> {\n\tfoo: &'a mut Foo,\n}\n\npub struct Baz<'a: 'b, 'b> {\n\tbar: &'b mut Bar<'a>\n}\n\npub struct Qux<'a: 'b, 'b: 'c, 'c> {\n\tbaz: &'c mut Baz<'a, 'b>\n}\n\npub struct Xyzzy<'a: 'b, 'b: 'c, 'c: 'd, 'd> {\n\tqux: &'d mut Qux<'a, 'b, 'c>\n}\n\n\nimpl Foo {\n\tpub fn borrow_mut<'a>(&'a mut self) -> Bar<'a> { Bar { foo: self } }\n\tpub fn try_borrow_mut<'a>(&'a mut self) -> Result<Bar<'a>, ()> { Ok(Bar { foo: self }) }\n\tpub fn fail_borrow_mut<'a>(&'a mut self) -> Result<Bar<'a>, ()> { Err(()) }\n}\n\nimpl<'a> Bar<'a> {\n\tpub fn borrow_mut<'b>(&'b mut self) -> Baz<'a, 'b> { Baz { bar: self } }\n\tpub fn try_borrow_mut<'b>(&'b mut self) -> Result<Baz<'a, 'b>, ()> { Ok(Baz { bar: self }) }\n\tpub fn fail_borrow_mut<'b>(&'b mut self) -> Result<Baz<'a, 'b>, ()> { Err(()) }\n}\n\nimpl<'a: 'b, 'b> Baz<'a, 'b> {\n\tpub fn borrow_mut<'c>(&'c mut self) -> Qux<'a, 'b, 'c> { Qux { baz: self } }\n\tpub fn try_borrow_mut<'c>(&'c mut self) -> Result<Qux<'a, 'b, 'c>, ()> { Ok(Qux { baz: self }) }\n\tpub fn fail_borrow_mut<'c>(&'c mut self) -> Result<Qux<'a, 'b, 'c>, ()> { Err(()) }\n}\n\nimpl<'a: 'b, 'b: 'c, 'c> Qux<'a, 'b, 'c> {\n\tpub fn borrow_mut<'d>(&'d mut self) -> Xyzzy<'a, 'b, 'c, 'd> { Xyzzy { qux: self } }\n\tpub fn try_borrow_mut<'d>(&'d mut self) -> Result<Xyzzy<'a, 'b, 'c, 'd>, ()> { Ok(Xyzzy { qux: self }) }\n\tpub fn fail_borrow_mut<'d>(&'d mut self) -> Result<Xyzzy<'a, 'b, 'c, 'd>, ()> { Err(()) }\n}\n\n\nrental! {\n\tmod rentals {\n\t\tuse super::*;\n\n\t\t#[rental_mut]\n\t\tpub struct ComplexRent {\n\t\t\tfoo: Box<Foo>,\n\t\t\tbar: Box<Bar<'foo>>,\n\t\t\tbaz: Box<Baz<'foo, 'bar>>,\n\t\t\tqux: Box<Qux<'foo, 'bar, 'baz>>,\n\t\t\txyzzy: Xyzzy<'foo, 'bar, 'baz, 'qux>,\n\t\t}\n\t}\n}\n\n\n#[test]\nfn new() {\n\tlet foo = Foo { i: 5 };\n\tlet _ = rentals::ComplexRent::new(\n\t\tBox::new(foo),\n\t\t|foo| Box::new(foo.borrow_mut()),\n\t\t|bar| Box::new(bar.borrow_mut()),\n\t\t|baz| Box::new(baz.borrow_mut()),\n\t\t|qux| qux.borrow_mut()\n\t);\n\n\tlet foo = Foo { i: 5 };\n\tlet cm = rentals::ComplexRent::try_new(\n\t\tBox::new(foo),\n\t\t|foo| foo.try_borrow_mut().map(|bar| Box::new(bar)),\n\t\t|bar| bar.try_borrow_mut().map(|baz| Box::new(baz)),\n\t\t|baz| baz.try_borrow_mut().map(|qux| Box::new(qux)),\n\t\t|qux| qux.try_borrow_mut()\n\t);\n\tassert!(cm.is_ok());\n\n\tlet foo = Foo { i: 5 };\n\tlet cm = rentals::ComplexRent::try_new(\n\t\tBox::new(foo),\n\t\t|foo| foo.try_borrow_mut().map(|bar| Box::new(bar)),\n\t\t|bar| bar.try_borrow_mut().map(|baz| Box::new(baz)),\n\t\t|baz| baz.try_borrow_mut().map(|qux| Box::new(qux)),\n\t\t|qux| qux.fail_borrow_mut()\n\t);\n\tassert!(cm.is_err());\n}\n\n\n#[test]\nfn read() {\n\tlet foo = Foo { i: 5 };\n\tlet cm = rentals::ComplexRent::new(\n\t\tBox::new(foo),\n\t\t|foo| Box::new(foo.borrow_mut()),\n\t\t|bar| Box::new(bar.borrow_mut()),\n\t\t|baz| Box::new(baz.borrow_mut()),\n\t\t|qux| qux.borrow_mut()\n\t);\n\tlet i = cm.rent(|xyzzy| xyzzy.qux.baz.bar.foo.i);\n\tassert_eq!(i, 5);\n\n\tlet iref = cm.ref_rent(|xyzzy| &xyzzy.qux.baz.bar.foo.i);\n\tassert_eq!(*iref, 5);\n}\n\n\n#[test]\nfn write() {\n\tlet foo = Foo { i: 5 };\n\tlet mut cm = rentals::ComplexRent::new(\n\t\tBox::new(foo),\n\t\t|foo| Box::new(foo.borrow_mut()),\n\t\t|bar| Box::new(bar.borrow_mut()),\n\t\t|baz| Box::new(baz.borrow_mut()),\n\t\t|qux| qux.borrow_mut()\n\t);\n\n\t{\n\t\tlet iref: &mut i32 = cm.ref_rent_mut(|xyzzy| &mut xyzzy.qux.baz.bar.foo.i);\n\t\t*iref = 12;\n\t}\n\n\tlet i = cm.rent(|xyzzy| xyzzy.qux.baz.bar.foo.i);\n\tassert_eq!(i, 12);\n}\n"
  },
  {
    "path": "tests/covariant.rs",
    "content": "#[macro_use]\nextern crate rental;\n\n\n//use std::marker::PhantomData;\n\n\npub struct Foo {\n\ti: i32,\n}\n\n\n//pub struct Invariant<'a> {\n//\tiref: &'a i32,\n//\tinv: PhantomData<&'a mut &'a ()>,\n//}\n\n\nrental! {\n\tmod rentals {\n\t\tuse super::*;\n\n\t\t#[rental(covariant)]\n\t\tpub struct SimpleRef {\n\t\t\tfoo: Box<Foo>,\n\t\t\tiref: &'foo i32,\n\t\t}\n\n\t\t#[rental_mut(covariant)]\n\t\tpub struct SimpleMut {\n\t\t\tfoo: Box<Foo>,\n\t\t\tiref: &'foo mut i32,\n\t\t}\n\n//\t\t#[rental(covariant)]\n//\t\tpub struct ShouldBreak {\n//\t\t\tfoo: Box<Foo>,\n//\t\t\tinv: Invariant<'foo>,\n//\t\t}\n\t}\n}\n\n\n#[test]\nfn borrow() {\n\tlet foo = Foo { i: 5 };\n\tlet fr = rentals::SimpleRef::new(Box::new(foo), |foo| &foo.i);\n\tlet b = fr.all();\n\tassert_eq!(**b.iref, 5);\n}\n\n\n"
  },
  {
    "path": "tests/debug.rs",
    "content": "#[macro_use]\nextern crate rental;\n\n\n#[derive(Debug)]\npub struct Foo {\n\ti: i32,\n}\n\n\nrental! {\n\tmod rentals {\n\t\tuse super::*;\n\n\t\t#[rental(debug, deref_suffix)]\n\t\tpub struct SimpleRef {\n\t\t\tfoo: Box<Foo>,\n\t\t\tiref: &'foo i32,\n\t\t}\n\n\t\t#[rental_mut(debug, deref_suffix)]\n\t\tpub struct SimpleMut {\n\t\t\tfoo: Box<Foo>,\n\t\t\tiref: &'foo mut i32,\n\t\t}\n\t}\n}\n\n\n#[test]\nfn print() {\n\tlet foo = Foo { i: 5 };\n\tlet sr = rentals::SimpleRef::new(Box::new(foo), |foo| &foo.i);\n\tprintln!(\"{:?}\", sr);\n\n\tlet foo = Foo { i: 5 };\n\tlet sm = rentals::SimpleMut::new(Box::new(foo), |foo| &mut foo.i);\n\tprintln!(\"{:?}\", sm);\n}\n"
  },
  {
    "path": "tests/drop_order.rs",
    "content": "#![allow(dead_code)]\n\n#[macro_use]\nextern crate rental;\n\nuse std::cell::RefCell;\nuse std::rc::Rc;\n\n\npub struct Foo {\n\ti: i32,\n\td: Rc<RefCell<String>>,\n}\n\npub struct Bar<'a> {\n\tfoo: &'a Foo,\n\td: Rc<RefCell<String>>,\n}\n\npub struct Baz<'a: 'b, 'b> {\n\tbar: &'b Bar<'a>,\n\td: Rc<RefCell<String>>,\n}\n\npub struct Qux<'a: 'b, 'b: 'c, 'c> {\n\tbaz: &'c Baz<'a, 'b>,\n\td: Rc<RefCell<String>>,\n}\n\npub struct Xyzzy<'a: 'b, 'b: 'c, 'c: 'd, 'd> {\n\tqux: &'d Qux<'a, 'b, 'c>,\n\td: Rc<RefCell<String>>,\n}\n\n\nimpl Foo {\n\tpub fn borrow<'a>(&'a self) -> Bar<'a> { Bar { foo: self, d: self.d.clone() } }\n}\n\nimpl Drop for Foo {\n\tfn drop(&mut self) {\n\t\tself.d.borrow_mut().push_str(\"Foo\");\n\t}\n}\n\nimpl<'a> Bar<'a> {\n\tpub fn borrow<'b>(&'b self) -> Baz<'a, 'b> { Baz { bar: self, d: self.d.clone() } }\n}\n\nimpl<'a> Drop for Bar<'a> {\n\tfn drop(&mut self) {\n\t\tself.d.borrow_mut().push_str(\"Bar\");\n\t}\n}\n\nimpl<'a: 'b, 'b> Baz<'a, 'b> {\n\tpub fn borrow<'c>(&'c self) -> Qux<'a, 'b, 'c> { Qux { baz: self, d: self.d.clone() } }\n}\n\nimpl<'a: 'b, 'b> Drop for Baz<'a, 'b> {\n\tfn drop(&mut self) {\n\t\tself.d.borrow_mut().push_str(\"Baz\");\n\t}\n}\n\nimpl<'a: 'b, 'b: 'c, 'c> Qux<'a, 'b, 'c> {\n\tpub fn borrow<'d>(&'d self) -> Xyzzy<'a, 'b, 'c, 'd> { Xyzzy { qux: self, d: self.d.clone() } }\n}\n\nimpl<'a: 'b, 'b: 'c, 'c> Drop for Qux<'a, 'b, 'c> {\n\tfn drop(&mut self) {\n\t\tself.d.borrow_mut().push_str(\"Qux\");\n\t}\n}\n\nimpl<'a: 'b, 'b: 'c, 'c: 'd, 'd> Drop for Xyzzy<'a, 'b, 'c, 'd> {\n\tfn drop(&mut self) {\n\t\tself.d.borrow_mut().push_str(\"Xyzzy\");\n\t}\n}\n\n\nrental! {\n\tpub mod rentals {\n\t\tuse super::*;\n\n\t\t#[rental]\n\t\tpub struct DropTestRent {\n\t\t\tfoo: Box<Foo>,\n\t\t\tbar: Box<Bar<'foo>>,\n\t\t\tbaz: Box<Baz<'foo, 'bar>>,\n\t\t\tqux: Box<Qux<'foo, 'bar, 'baz>>,\n\t\t\txyzzy: Xyzzy<'foo, 'bar, 'baz, 'qux>,\n\t\t}\n\t}\n}\n\n\n#[test]\nfn drop_order() {\n\tlet d = Rc::new(RefCell::new(String::new()));\n\t{\n\t\tlet foo = Foo { i: 5, d: d.clone() };\n\t\tlet _ = rentals::DropTestRent::new(\n\t\t\tBox::new(foo),\n\t\t\t|foo| Box::new(foo.borrow()),\n\t\t\t|bar, _| Box::new(bar.borrow()),\n\t\t\t|baz, _, _| Box::new(baz.borrow()),\n\t\t\t|qux, _, _, _| qux.borrow()\n\t\t);\n\t}\n\tassert_eq!(*d.borrow(), \"XyzzyQuxBazBarFoo\");\n\n\tlet d = Rc::new(RefCell::new(String::new()));\n\t{\n\t\tlet foo = Foo { i: 5, d: d.clone() };\n\t\tlet r = rentals::DropTestRent::new(\n\t\t\tBox::new(foo),\n\t\t\t|foo| Box::new(foo.borrow()),\n\t\t\t|bar, _| Box::new(bar.borrow()),\n\t\t\t|baz, _, _| Box::new(baz.borrow()),\n\t\t\t|qux, _, _, _| qux.borrow()\n\t\t);\n\n\t\tlet _head = r.into_head();\n\t}\n\tassert_eq!(*d.borrow(), \"XyzzyQuxBazBarFoo\");\n}\n\n"
  },
  {
    "path": "tests/generic.rs",
    "content": "#[macro_use]\nextern crate rental;\n\n\npub struct Foo<T: 'static> {\n\tt: T,\n}\n\nimpl<T: 'static> Foo<T> {\n\tfn try_borrow(&self) -> Result<&T, ()> { Ok(&self.t) }\n\tfn fail_borrow(&self) -> Result<&T, ()> { Err(()) }\n}\n\n\nrental! {\n\tmod rentals {\n\t\ttype FooAlias<T> = super::Foo<T>;\n\n\t\t#[rental]\n\t\tpub struct SimpleRef<T: 'static> {\n\t\t\tfoo: Box<FooAlias<T>>,\n\t\t\ttref: &'foo T,\n\t\t}\n\t}\n}\n\n\n#[test]\nfn new() {\n\tlet foo = Foo { t: 5 };\n\tlet _ = rentals::SimpleRef::new(Box::new(foo), |foo| &foo.t);\n\n\tlet foo = Foo { t: 5 };\n\tlet sr = rentals::SimpleRef::try_new(Box::new(foo), |foo| foo.try_borrow());\n\tassert!(sr.is_ok());\n\n\tlet foo = Foo { t: 5 };\n\tlet sr = rentals::SimpleRef::try_new(Box::new(foo), |foo| foo.fail_borrow());\n\tassert!(sr.is_err());\n}\n\n\n#[test]\nfn read() {\n\tlet foo = Foo { t: 5 };\n\n\tlet sr = rentals::SimpleRef::new(Box::new(foo), |foo| &foo.t);\n\tlet t: i32 = sr.rent(|tref| **tref);\n\tassert_eq!(t, 5);\n\n\tlet tref: &i32 = sr.ref_rent(|tref| *tref);\n\tassert_eq!(*tref, 5);\n}\n"
  },
  {
    "path": "tests/lt_params.rs",
    "content": "#[macro_use]\nextern crate rental;\n\n\npub struct Foo<'a> {\n\ti: &'a i32,\n}\n\nimpl<'a> Foo<'a> {\n\tfn borrow(&self) -> &i32 { self.i }\n\tfn try_borrow(&self) -> Result<&i32, ()> { Ok(self.i) }\n\tfn fail_borrow(&self) -> Result<&i32, ()> { Err(()) }\n}\n\n\nrental! {\n\tmod rentals {\n\t\tuse super::*;\n\n\t\t#[rental]\n\t\tpub struct LtParam<'a> {\n\t\t\tfoo: Box<Foo<'a>>,\n\t\t\tiref: &'foo i32,\n\t\t}\n\t}\n}\n\n\n#[test]\nfn new() {\n\tlet i = 5;\n\n\tlet foo = Foo { i: &i };\n\tlet _ = rentals::LtParam::new(Box::new(foo), |foo| foo.borrow());\n\n\tlet foo = Foo { i: &i };\n\tlet sr = rentals::LtParam::try_new(Box::new(foo), |foo| foo.try_borrow());\n\tassert!(sr.is_ok());\n\n\tlet foo = Foo { i: &i };\n\tlet sr = rentals::LtParam::try_new(Box::new(foo), |foo| foo.fail_borrow());\n\tassert!(sr.is_err());\n}\n\n\n#[test]\nfn read() {\n\tlet i = 5;\n\n\tlet foo = Foo { i: &i };\n\n\tlet mut sr = rentals::LtParam::new(Box::new(foo), |foo| foo.borrow());\n\n\t{\n\t\tlet i: i32 = sr.rent(|iref| **iref);\n\t\tassert_eq!(i, 5);\n\t}\n\n\t{\n\t\tlet iref: &i32 = sr.ref_rent(|iref| *iref);\n\t\tassert_eq!(*iref, 5);\n\t}\n\n\tassert_eq!(sr.rent_all_mut(|borrows| *borrows.foo.i), 5);\n}\n"
  },
  {
    "path": "tests/map.rs",
    "content": "#[macro_use]\nextern crate rental;\n\n\npub struct Foo {\n\ti: i32,\n}\n\n\nrental! {\n\tmod rentals {\n\t\tuse super::*;\n\n\t\t#[rental(map_suffix = \"T\")]\n\t\tpub struct SimpleRef<T: 'static> {\n\t\t\tfoo: Box<Foo>,\n\t\t\tfr: &'foo T,\n\t\t}\n\n\t\t#[rental_mut(map_suffix = \"T\")]\n\t\tpub struct SimpleMut<T: 'static> {\n\t\t\tfoo: Box<Foo>,\n\t\t\tfr: &'foo mut T,\n\t\t}\n\t}\n}\n\n\n#[test]\nfn map() {\n\tlet foo = Foo { i: 5 };\n\tlet sr = rentals::SimpleRef::new(Box::new(foo), |foo| foo);\n\tlet sr = sr.map(|fr| &fr.i);\n\tassert_eq!(sr.rent(|ir| **ir), 5);\n\n\tlet foo = Foo { i: 12 };\n\tlet sm = rentals::SimpleMut::new(Box::new(foo), |foo| foo);\n\tlet sm = sm.map(|fr| &mut fr.i);\n\tassert_eq!(sm.rent(|ir| **ir), 12);\n}\n\n\n"
  },
  {
    "path": "tests/simple_mut.rs",
    "content": "#[macro_use]\nextern crate rental;\n\n\npub struct Foo {\n\ti: i32,\n}\n\nimpl Foo {\n\tfn try_borrow_mut(&mut self) -> Result<&mut i32, ()> { Ok(&mut self.i) }\n\tfn fail_borrow_mut(&mut self) -> Result<&mut i32, ()> { Err(()) }\n}\n\n\nrental! {\n\tmod rentals {\n\t\tuse super::*;\n\n\t\t#[rental_mut]\n\t\tpub struct SimpleMut {\n\t\t\tfoo: Box<Foo>,\n\t\t\tiref: &'foo mut i32,\n\t\t}\n\t}\n}\n\n\n#[test]\nfn new() {\n\tlet foo = Foo { i: 5 };\n\tlet _ = rentals::SimpleMut::new(Box::new(foo), |foo| &mut foo.i);\n\n\tlet foo = Foo { i: 5 };\n\tlet sm = rentals::SimpleMut::try_new(Box::new(foo), |foo| foo.try_borrow_mut());\n\tassert!(sm.is_ok());\n\n\tlet foo = Foo { i: 5 };\n\tlet sm = rentals::SimpleMut::try_new(Box::new(foo), |foo| foo.fail_borrow_mut());\n\tassert!(sm.is_err());\n}\n\n\n#[test]\nfn read() {\n\tlet foo = Foo { i: 5 };\n\n\tlet sm = rentals::SimpleMut::new(Box::new(foo), |foo| &mut foo.i);\n\tlet i: i32 = sm.rent(|iref| **iref);\n\tassert_eq!(i, 5);\n\n\tlet iref: &i32 = sm.ref_rent(|iref| *iref);\n\tassert_eq!(*iref, 5);\n}\n\n\n#[test]\nfn write() {\n\tlet foo = Foo { i: 5 };\n\n\tlet mut sm = rentals::SimpleMut::new(Box::new(foo), |foo| &mut foo.i);\n\n\t{\n\t\tlet iref: &mut i32 = sm.ref_rent_mut(|iref| *iref);\n\t\t*iref = 12;\n\t\tassert_eq!(*iref, 12);\n\t}\n}\n"
  },
  {
    "path": "tests/simple_ref.rs",
    "content": "#[macro_use]\nextern crate rental;\n\n\npub struct Foo {\n\ti: i32,\n}\n\nimpl Foo {\n\tfn try_borrow(&self) -> Result<&i32, ()> { Ok(&self.i) }\n\tfn fail_borrow(&self) -> Result<&i32, ()> { Err(()) }\n}\n\npub struct FooRef<'i> {\n\tiref: &'i i32,\n\tmisc: i32,\n}\n\n\nimpl<'i> ::std::ops::Deref for FooRef<'i> {\n\ttype Target = i32;\n\n\tfn deref(&self) -> &i32 { self.iref }\n}\n\n\nrental! {\n\tmod rentals {\n\t\tuse super::*;\n\n\t\t#[rental]\n\t\tpub struct SimpleRef {\n\t\t\tfoo: Box<Foo>,\n\t\t\tfr: FooRef<'foo>,\n\t\t}\n\t}\n}\n\n\n#[test]\nfn new() {\n\tlet foo = Foo { i: 5 };\n\tlet _ = rentals::SimpleRef::new(Box::new(foo), |foo| FooRef{ iref: &foo.i, misc: 12 });\n\n\tlet foo = Foo { i: 5 };\n\tlet sr: rental::RentalResult<rentals::SimpleRef, (), _> = rentals::SimpleRef::try_new(Box::new(foo), |foo| Ok(FooRef{ iref: foo.try_borrow()?, misc: 12 }));\n\tassert!(sr.is_ok());\n\n\tlet foo = Foo { i: 5 };\n\tlet sr: rental::RentalResult<rentals::SimpleRef, (), _> = rentals::SimpleRef::try_new(Box::new(foo), |foo| Ok(FooRef{ iref: foo.fail_borrow()?, misc: 12 }));\n\tassert!(sr.is_err());\n}\n\n\n#[test]\nfn read() {\n\tlet foo = Foo { i: 5 };\n\n\tlet mut sr = rentals::SimpleRef::new(Box::new(foo), |foo| FooRef{ iref: &foo.i, misc: 12 });\n\n\t{\n\t\tlet i: i32 = sr.rent(|iref| **iref);\n\t\tassert_eq!(i, 5);\n\t}\n\n\t{\n\t\tlet iref: &i32 = sr.ref_rent(|fr| fr.iref);\n\t\tassert_eq!(*iref, 5);\n\t\tlet iref: Option<&i32> = sr.maybe_ref_rent(|fr| Some(fr.iref));\n\t\tassert_eq!(iref, Some(&5));\n\t\tlet iref: Result<&i32, ()> = sr.try_ref_rent(|fr| Ok(fr.iref));\n\t\tassert_eq!(iref, Ok(&5));\n\t}\n\n\t{\n\t\tassert_eq!(sr.head().i, 5);\n\t\tassert_eq!(sr.rent_all(|borrows| borrows.foo.i), 5);\n\t\tassert_eq!(sr.rent_all_mut(|borrows| borrows.foo.i), 5);\n\t}\n\n\t{\n\t\tlet iref: Option<&i32> = sr.maybe_ref_rent_all(|borrows| Some(borrows.fr.iref));\n\t\tassert_eq!(iref, Some(&5));\n\t\tlet iref: Result<&i32, ()> = sr.try_ref_rent_all(|borrows| Ok(borrows.fr.iref));\n\t\tassert_eq!(iref, Ok(&5));\n\t}\n\n\t{\n\t\tlet iref: &mut i32 = sr.ref_rent_all_mut(|borrows| &mut borrows.fr.misc);\n\t\t*iref = 57;\n\t\tassert_eq!(*iref, 57);\n\t}\n\n\t{\n\t\tlet iref: Option<&mut i32> = sr.maybe_ref_rent_all_mut(|borrows| Some(&mut borrows.fr.misc));\n\t\tassert_eq!(iref, Some(&mut 57));\n\t}\n\n\t{\n\t\tlet iref: Result<&mut i32, ()> = sr.try_ref_rent_all_mut(|borrows| Ok(&mut borrows.fr.misc));\n\t\tassert_eq!(iref, Ok(&mut 57));\n\t}\n}\n"
  },
  {
    "path": "tests/string.rs",
    "content": "#[macro_use]\nextern crate rental;\n\n\nrental! {\n\tpub mod rent_string {\n\t\t#[rental(deref_suffix)]\n\t\tpub struct OwnedStr {\n\t\t\tbuffer: String,\n\t\t\tslice: &'buffer str,\n\t\t\tslice_2: &'slice str,\n\t\t}\n\t}\n}\n\n\n#[test]\nfn new() {\n\tlet buf = \"Hello, World!\".to_string();\n\tlet _ = rent_string::OwnedStr::new(buf, |slice| slice, |slice, _| slice);\n}\n\n\n#[test]\nfn read() {\n\tlet buf = \"Hello, World!\".to_string();\n\tlet rbuf = rent_string::OwnedStr::new(buf, |slice| slice, |slice, _| slice);\n\n\tassert_eq!(&*rbuf, \"Hello, World!\");\n}\n"
  },
  {
    "path": "tests/subrental.rs",
    "content": "#[macro_use]\nextern crate rental;\n\n\npub struct Foo {\n\tpub i: i32,\n}\n\npub struct Bar<'a> {\n\tpub foo: &'a Foo,\n}\n\npub struct Qux<'a: 'b, 'b> {\n\tpub bar: &'b Bar<'a>,\n}\n\n\nimpl Foo {\n\tpub fn borrow(&self) -> Bar { Bar { foo: self } }\n\tpub fn try_borrow<'a>(&'a self) -> Result<Bar<'a>, ()> { Ok(Bar { foo: self }) }\n\tpub fn fail_borrow<'a>(&'a self) -> Result<Bar<'a>, ()> { Err(()) }\n}\n\nimpl<'a> Bar<'a> {\n\tpub fn borrow<'b>(&'b self) -> Qux<'a, 'b> { Qux { bar: self } }\n\tpub fn try_borrow<'b>(&'b self) -> Result<Qux<'a, 'b>, ()> { Ok(Qux { bar: self }) }\n\tpub fn fail_borrow<'b>(&'b self) -> Result<Qux<'a, 'b>, ()> { Err(()) }\n}\n\n\nrental! {\n\tpub mod rentals {\n\t\tuse super::*;\n\n\t\t#[rental]\n\t\tpub struct Sub {\n\t\t\tfoo: Box<Foo>,\n\t\t\tbar: Bar<'foo>,\n\t\t}\n\n\t\t#[rental]\n\t\tpub struct Rent {\n\t\t\t#[subrental = 2]\n\t\t\tsub: Box<Sub>,\n\t\t\tqux: Qux<'sub_0, 'sub_1>,\n\t\t}\n\n\t\t#[rental]\n\t\tpub struct BorrowSub<'f> {\n\t\t\tfoo: &'f Foo,\n\t\t\tbar: Bar<'foo>,\n\t\t}\n\n\t\t#[rental]\n\t\tpub struct TailRent {\n\t\t\tfoo: Box<Foo>,\n\t\t\t#[subrental = 2]\n\t\t\tsub: Box<BorrowSub<'foo>>,\n\t\t\tiref: &'sub_1 i32,\n\t\t}\n\t}\n}\n\n\n#[test]\nfn new() {\n\tlet foo = Foo { i: 5 };\n\tlet sub = rentals::Sub::new(Box::new(foo), |foo| foo.borrow());\n\tlet _ = rentals::Rent::new(Box::new(sub), |sub| sub.bar.borrow());\n\n\tlet foo = Foo { i: 5 };\n\tlet sub = rentals::Sub::new(Box::new(foo), |foo| foo.borrow());\n\tlet rent = rentals::Rent::try_new(Box::new(sub), |sub| sub.bar.try_borrow());\n\tassert!(rent.is_ok());\n\n\tlet foo = Foo { i: 5 };\n\tlet sub = rentals::Sub::new(Box::new(foo), |foo| foo.borrow());\n\tlet rent = rentals::Rent::try_new(Box::new(sub), |sub| sub.bar.fail_borrow());\n\tassert!(rent.is_err());\n}\n\n\n#[test]\nfn read() {\n\tlet foo = Foo { i: 5 };\n\tlet sub = rentals::Sub::new(Box::new(foo), |foo| foo.borrow());\n\tlet _ = rentals::Rent::new(Box::new(sub), |sub| sub.bar.borrow());\n}\n"
  },
  {
    "path": "tests/target_ty_hack.rs",
    "content": "#[macro_use]\nextern crate rental;\n\n\ntype MyVec<T> = Vec<T>;\n\n\nrental! {\n\tpub mod rent_vec_slice {\n\t\tuse super::*;\n\n\t\t#[rental]\n\t\tpub struct OwnedSlice {\n\t\t\t#[target_ty = \"[u8]\"]\n\t\t\tbuffer: MyVec<u8>,\n\t\t\tslice: &'buffer [u8],\n\t\t}\n\n\t\t#[rental_mut]\n\t\tpub struct OwnedMutSlice {\n\t\t\t#[target_ty = \"[u8]\"]\n\t\t\tbuffer: MyVec<u8>,\n\t\t\tslice: &'buffer mut [u8],\n\t\t}\n\t}\n}\n\n\n#[test]\nfn new() {\n\tlet vec = vec![1, 2, 3];\n\tlet _ = rent_vec_slice::OwnedSlice::new(vec, |slice| slice);\n}\n\n\n#[test]\nfn read() {\n\tlet vec = vec![1, 2, 3];\n\tlet rvec = rent_vec_slice::OwnedSlice::new(vec, |slice| slice);\n\n\tassert_eq!(rvec.rent(|slice| slice[1]), 2);\n\tassert_eq!(rvec.rent(|slice| slice[1]), rvec.rent(|slice| slice[1]));\n}\n\n\n#[test]\nfn write() {\n\tlet vec = vec![1, 2, 3];\n\tlet mut rvec = rent_vec_slice::OwnedMutSlice::new(vec, |slice| slice);\n\n\trvec.rent_mut(|slice| slice[1] = 4);\n\tassert_eq!(rvec.rent(|slice| slice[1]), 4);\n\tassert_eq!(rvec.rent(|slice| slice[1]), rvec.rent(|slice| slice[1]));\n}\n"
  },
  {
    "path": "tests/trait.rs",
    "content": "#[macro_use]\nextern crate rental;\n\n\npub trait MyTrait { }\n\n\npub struct MyStruct { }\n\n\nimpl MyTrait for MyStruct { }\n\n\nrental! {\n    pub mod rentals {\n\t\tuse ::MyTrait;\n\n\t\t#[rental]\n\t\tpub struct RentTrait {\n\t\t\tmy_trait: Box<MyTrait + 'static>,\n\t\t\tmy_suffix: &'my_trait (MyTrait + 'static),\n\t\t}\n\t}\n}\n\n\n#[test]\nfn new() {\n\tlet _tr = rentals::RentTrait::new(\n\t\tBox::new(MyStruct{}),\n\t\t|t| &*t,\n\t);\n}\n"
  },
  {
    "path": "tests/unused.rs",
    "content": "use std::rc::Rc;\n\n#[macro_use]\nextern crate rental;\n\npub struct Sample {\n    field: i32,\n}\n\nrental! {\n    mod sample_rental {\n        use super::*;\n\n        #[rental]\n        pub struct SampleRental {\n            sample: Rc<Sample>,\n            sref: &'sample i32,\n        }\n    }\n}\nuse self::sample_rental::SampleRental;\n\n#[test]\nfn unused() {\n    let sample = Rc::new(Sample { field: 42 });\n    let rental = SampleRental::new(sample, |sample_rc| &sample_rc.field);\n    rental.rent(|this| println!(\"{}\", this));\n}\n"
  },
  {
    "path": "tests/vec_slice.rs",
    "content": "#[macro_use]\nextern crate rental;\n\n\nrental! {\n\tpub mod rent_vec_slice {\n\t\t#[rental]\n\t\tpub struct OwnedSlice {\n\t\t\tbuffer: Vec<u8>,\n\t\t\tslice: &'buffer [u8],\n\t\t}\n\n\t\t#[rental_mut]\n\t\tpub struct OwnedMutSlice {\n\t\t\tbuffer: Vec<u8>,\n\t\t\tslice: &'buffer mut [u8],\n\t\t}\n\t}\n}\n\n\n#[test]\nfn new() {\n\tlet vec = vec![1, 2, 3];\n\tlet _ = rent_vec_slice::OwnedSlice::new(vec, |slice| slice);\n}\n\n\n#[test]\nfn read() {\n\tlet vec = vec![1, 2, 3];\n\tlet rvec = rent_vec_slice::OwnedSlice::new(vec, |slice| slice);\n\n\tassert_eq!(rvec.rent(|slice| slice[1]), 2);\n\tassert_eq!(rvec.rent(|slice| slice[1]), rvec.rent(|slice| slice[1]));\n}\n\n\n#[test]\nfn write() {\n\tlet vec = vec![1, 2, 3];\n\tlet mut rvec = rent_vec_slice::OwnedMutSlice::new(vec, |slice| slice);\n\n\trvec.rent_mut(|slice| slice[1] = 4);\n\tassert_eq!(rvec.rent(|slice| slice[1]), 4);\n\tassert_eq!(rvec.rent(|slice| slice[1]), rvec.rent(|slice| slice[1]));\n}\n"
  }
]