@@ -11,7 +11,7 @@ use crate::{
1111 codegen:: {
1212 Direction , VersionDefinition ,
1313 changes:: { BTreeMapExt , ChangesetExt } ,
14- item:: ItemStatus ,
14+ item:: { ItemStatus , generate_attributes } ,
1515 module:: ModuleGenerationContext ,
1616 } ,
1717 utils:: { ItemIdentExt , ItemIdents } ,
@@ -20,6 +20,16 @@ use crate::{
2020#[ derive( Debug ) ]
2121pub struct VersionedField {
2222 pub original_attributes : Vec < Attribute > ,
23+
24+ /// A sparse map of changed doc comments.
25+ ///
26+ /// This map being sparse means that access to it must be able to deal with a version not being
27+ /// present. Using `unwrap()`, [`BTreeMapExt::get_expect`] or other similar functions is not
28+ /// recommended. Also see `CommonItemAttributes::changed_docs` for further details.
29+ //
30+ // NOTE (@Techassi): Potentially roll this into the changeset below so that there will be a
31+ // single sure of truth for field generation again.
32+ pub changed_docs : BTreeMap < Version , Vec < String > > ,
2333 pub changes : Option < BTreeMap < Version , ItemStatus > > ,
2434 pub idents : FieldIdents ,
2535 pub hint : Option < Hint > ,
@@ -45,6 +55,7 @@ impl VersionedField {
4555 } ) ?;
4656 let idents = FieldIdents :: from ( ident) ;
4757
58+ let changed_docs = field_attributes. common . changed_docs ( ) ;
4859 let changes = field_attributes
4960 . common
5061 . into_changeset ( & idents, field. ty . clone ( ) ) ;
@@ -53,6 +64,7 @@ impl VersionedField {
5364 Ok ( Self {
5465 original_attributes : field_attributes. attrs ,
5566 hint : field_attributes. hint ,
67+ changed_docs,
5668 ty : field. ty ,
5769 changes,
5870 idents,
@@ -82,7 +94,11 @@ impl VersionedField {
8294 /// }
8395 /// ```
8496 pub fn generate_for_container ( & self , version : & VersionDefinition ) -> Option < TokenStream > {
85- let original_attributes = & self . original_attributes ;
97+ let attributes = generate_attributes (
98+ & self . original_attributes ,
99+ & self . changed_docs ,
100+ & version. inner ,
101+ ) ;
86102
87103 #[ allow( clippy:: single_match_else) ]
88104 match & self . changes {
@@ -106,13 +122,13 @@ impl VersionedField {
106122 )
107123 } ) {
108124 ItemStatus :: Addition { ident, ty, .. } => Some ( quote ! {
109- #( #original_attributes ) *
125+ #attributes
110126 pub #ident: #ty,
111127 } ) ,
112128 ItemStatus :: Change {
113129 to_ident, to_type, ..
114130 } => Some ( quote ! {
115- #( #original_attributes ) *
131+ #attributes
116132 pub #to_ident: #to_type,
117133 } ) ,
118134 ItemStatus :: Deprecation {
@@ -133,7 +149,7 @@ impl VersionedField {
133149 } ;
134150
135151 Some ( quote ! {
136- #( #original_attributes ) *
152+ #attributes
137153 #deprecated_attr
138154 pub #field_ident: #field_type,
139155 } )
@@ -149,7 +165,7 @@ impl VersionedField {
149165 let deprecated_attr = previously_deprecated. then ( || quote ! { #[ deprecated] } ) ;
150166
151167 Some ( quote ! {
152- #( #original_attributes ) *
168+ #attributes
153169 #deprecated_attr
154170 pub #ident: #ty,
155171 } )
@@ -163,7 +179,7 @@ impl VersionedField {
163179 let field_type = & self . ty ;
164180
165181 Some ( quote ! {
166- #( #original_attributes ) *
182+ #attributes
167183 pub #field_ident: #field_type,
168184 } )
169185 }
0 commit comments