@@ -258,50 +258,47 @@ fn generate_projections(
258258 let projection = format_ident ! ( "{ident}Projection" ) ;
259259 let this = format_ident ! ( "this" ) ;
260260
261- let ( fields_decl, fields_proj) = fields
262- . iter ( )
263- . map (
264- |f @ Field {
265- vis,
266- ident,
267- ty,
268- attrs,
269- ..
270- } | {
271- let mut attrs = attrs. clone ( ) ;
272- attrs. retain ( |a| !a. path ( ) . is_ident ( "pin" ) ) ;
273- let mut no_doc_attrs = attrs. clone ( ) ;
274- no_doc_attrs. retain ( |a| !a. path ( ) . is_ident ( "doc" ) ) ;
275- let ident = ident
276- . as_ref ( )
277- . expect ( "only structs with named fields are supported" ) ;
278- if is_field_structurally_pinned ( f) {
279- (
280- quote ! (
281- #( #attrs) *
282- #vis #ident: :: core:: pin:: Pin <& ' __pin mut #ty>,
283- ) ,
284- quote ! (
285- #( #no_doc_attrs) *
286- // SAFETY: this field is structurally pinned.
287- #ident: unsafe { :: core:: pin:: Pin :: new_unchecked( & mut #this. #ident) } ,
288- ) ,
289- )
290- } else {
291- (
292- quote ! (
293- #( #attrs) *
294- #vis #ident: & ' __pin mut #ty,
295- ) ,
296- quote ! (
297- #( #no_doc_attrs) *
298- #ident: & mut #this. #ident,
299- ) ,
300- )
301- }
302- } ,
303- )
304- . collect :: < ( Vec < _ > , Vec < _ > ) > ( ) ;
261+ let ( fields_decl, fields_proj) = collect_tuple ( fields. iter ( ) . map (
262+ |f @ Field {
263+ vis,
264+ ident,
265+ ty,
266+ attrs,
267+ ..
268+ } | {
269+ let mut attrs = attrs. clone ( ) ;
270+ attrs. retain ( |a| !a. path ( ) . is_ident ( "pin" ) ) ;
271+ let mut no_doc_attrs = attrs. clone ( ) ;
272+ no_doc_attrs. retain ( |a| !a. path ( ) . is_ident ( "doc" ) ) ;
273+ let ident = ident
274+ . as_ref ( )
275+ . expect ( "only structs with named fields are supported" ) ;
276+ if is_field_structurally_pinned ( f) {
277+ (
278+ quote ! (
279+ #( #attrs) *
280+ #vis #ident: :: core:: pin:: Pin <& ' __pin mut #ty>,
281+ ) ,
282+ quote ! (
283+ #( #no_doc_attrs) *
284+ // SAFETY: this field is structurally pinned.
285+ #ident: unsafe { :: core:: pin:: Pin :: new_unchecked( & mut #this. #ident) } ,
286+ ) ,
287+ )
288+ } else {
289+ (
290+ quote ! (
291+ #( #attrs) *
292+ #vis #ident: & ' __pin mut #ty,
293+ ) ,
294+ quote ! (
295+ #( #no_doc_attrs) *
296+ #ident: & mut #this. #ident,
297+ ) ,
298+ )
299+ }
300+ } ,
301+ ) ) ;
305302 let structurally_pinned_fields_docs = fields
306303 . iter ( )
307304 . filter ( |f| is_field_structurally_pinned ( f) )
@@ -523,3 +520,14 @@ impl VisitMut for SelfReplacer {
523520 // Do not descend into items, since items reset/change what `Self` refers to.
524521 }
525522}
523+
524+ // replace with `.collect()` once MSRV is above 1.79
525+ fn collect_tuple < A , B > ( iter : impl Iterator < Item = ( A , B ) > ) -> ( Vec < A > , Vec < B > ) {
526+ let mut res_a = vec ! [ ] ;
527+ let mut res_b = vec ! [ ] ;
528+ for ( a, b) in iter {
529+ res_a. push ( a) ;
530+ res_b. push ( b) ;
531+ }
532+ ( res_a, res_b)
533+ }
0 commit comments