@@ -8,7 +8,7 @@ use syn::{Attribute, Path, Type, spanned::Spanned};
88
99use crate :: {
1010 codegen:: { VersionDefinition , item:: ItemStatus } ,
11- utils:: ItemIdentExt ,
11+ utils:: ItemIdents ,
1212} ;
1313
1414mod field;
@@ -50,14 +50,14 @@ pub struct CommonItemAttributes {
5050// it contains functions which can only be called after the initial parsing and validation because
5151// they need additional context, namely the list of versions defined on the container or module.
5252impl CommonItemAttributes {
53- pub fn validate ( & self , item_ident : impl ItemIdentExt , item_attrs : & [ Attribute ] ) -> Result < ( ) > {
53+ pub fn validate ( & self , item_idents : impl ItemIdents , item_attrs : & [ Attribute ] ) -> Result < ( ) > {
5454 let mut errors = Error :: accumulator ( ) ;
5555
56- errors. handle ( self . validate_action_combinations ( & item_ident ) ) ;
57- errors. handle ( self . validate_action_order ( & item_ident ) ) ;
58- errors. handle ( self . validate_item_name ( & item_ident ) ) ;
56+ errors. handle ( self . validate_action_combinations ( & item_idents ) ) ;
57+ errors. handle ( self . validate_action_order ( & item_idents ) ) ;
58+ errors. handle ( self . validate_item_name ( & item_idents ) ) ;
5959 errors. handle ( self . validate_added_action ( ) ) ;
60- errors. handle ( self . validate_changed_action ( & item_ident ) ) ;
60+ errors. handle ( self . validate_changed_action ( & item_idents ) ) ;
6161 errors. handle ( self . validate_item_attributes ( item_attrs) ) ;
6262
6363 errors. finish ( )
@@ -106,23 +106,23 @@ impl CommonItemAttributes {
106106 /// at least one version before being changed.
107107 /// - `changed` and `deprecated` using the same version: Again, the same
108108 /// rules from above apply here as well.
109- fn validate_action_combinations ( & self , item_ident : & impl ItemIdentExt ) -> Result < ( ) > {
109+ fn validate_action_combinations ( & self , item_idents : & impl ItemIdents ) -> Result < ( ) > {
110110 match ( & self . added , & self . changes , & self . deprecated ) {
111111 ( Some ( added) , _, Some ( deprecated) ) if * added. since == * deprecated. since => Err (
112112 Error :: custom ( "cannot be marked as `added` and `deprecated` in the same version" )
113- . with_span ( item_ident ) ,
113+ . with_span ( item_idents . original ( ) ) ,
114114 ) ,
115115 ( Some ( added) , changed, _) if changed. iter ( ) . any ( |r| * r. since == * added. since ) => Err (
116116 Error :: custom ( "cannot be marked as `added` and `changed` in the same version" )
117- . with_span ( item_ident ) ,
117+ . with_span ( item_idents . original ( ) ) ,
118118 ) ,
119119 ( _, changed, Some ( deprecated) )
120120 if changed. iter ( ) . any ( |r| * r. since == * deprecated. since ) =>
121121 {
122122 Err ( Error :: custom (
123123 "cannot be marked as `deprecated` and `changed` in the same version" ,
124124 )
125- . with_span ( item_ident ) )
125+ . with_span ( item_idents . original ( ) ) )
126126 }
127127 _ => Ok ( ( ) ) ,
128128 }
@@ -140,7 +140,7 @@ impl CommonItemAttributes {
140140 /// version of the added action.
141141 /// - All `changed` actions must use a greater version than `added` but a
142142 /// lesser version than `deprecated`.
143- fn validate_action_order ( & self , item_ident : & impl ItemIdentExt ) -> Result < ( ) > {
143+ fn validate_action_order ( & self , item_idents : & impl ItemIdents ) -> Result < ( ) > {
144144 let added_version = self . added . as_ref ( ) . map ( |a| * a. since ) ;
145145 let deprecated_version = self . deprecated . as_ref ( ) . map ( |d| * d. since ) ;
146146
@@ -152,7 +152,7 @@ impl CommonItemAttributes {
152152 if added_version > deprecated_version {
153153 return Err ( Error :: custom ( format ! (
154154 "cannot marked as `added` in version `{added_version}` while being marked as `deprecated` in an earlier version `{deprecated_version}`"
155- ) ) . with_span ( item_ident ) ) ;
155+ ) ) . with_span ( item_idents . original ( ) ) ) ;
156156 }
157157 }
158158
@@ -165,7 +165,7 @@ impl CommonItemAttributes {
165165 return Err ( Error :: custom (
166166 "all changes must use versions higher than `added` and lower than `deprecated`" ,
167167 )
168- . with_span ( item_ident ) ) ;
168+ . with_span ( item_idents . original ( ) ) ) ;
169169 }
170170
171171 Ok ( ( ) )
@@ -180,21 +180,22 @@ impl CommonItemAttributes {
180180 /// - Fields or variants marked as deprecated need to include the
181181 /// deprecation prefix in their name. The prefix must not be included for
182182 /// fields or variants which are not deprecated.
183- fn validate_item_name ( & self , item_ident : & impl ItemIdentExt ) -> Result < ( ) > {
184- let starts_with_deprecated = item_ident . starts_with_deprecated_prefix ( ) ;
183+ fn validate_item_name ( & self , item_idents : & impl ItemIdents ) -> Result < ( ) > {
184+ let starts_with_deprecated = item_idents . starts_with_deprecation_prefix ( ) ;
185185
186186 if self . deprecated . is_some ( ) && !starts_with_deprecated {
187187 return Err ( Error :: custom ( format ! (
188- "marked as `deprecated` and thus must include the `{deprecated_prefix }` prefix" ,
189- deprecated_prefix = item_ident . deprecated_prefix ( )
188+ "marked as `deprecated` and thus must include the `{deprecation_prefix }` prefix" ,
189+ deprecation_prefix = item_idents . deprecation_prefix ( )
190190 ) )
191- . with_span ( item_ident ) ) ;
191+ . with_span ( item_idents . original ( ) ) ) ;
192192 }
193193
194194 if self . deprecated . is_none ( ) && starts_with_deprecated {
195- return Err ( Error :: custom (
196- format ! ( "not marked as `deprecated` and thus must not include the `{deprecated_prefix}` prefix" , deprecated_prefix = item_ident. deprecated_prefix( ) )
197- ) . with_span ( item_ident) ) ;
195+ return Err ( Error :: custom ( format ! (
196+ "not marked as `deprecated` and thus must not include the `{deprecation_prefix}` prefix" ,
197+ deprecation_prefix = item_idents. deprecation_prefix( )
198+ ) ) . with_span ( item_idents. original ( ) ) ) ;
198199 }
199200
200201 Ok ( ( ) )
@@ -218,7 +219,7 @@ impl CommonItemAttributes {
218219 /// This associated function is called by the top-level validation function
219220 /// and validates that parameters provided to the `changed` actions are
220221 /// valid.
221- fn validate_changed_action ( & self , item_ident : & impl ItemIdentExt ) -> Result < ( ) > {
222+ fn validate_changed_action ( & self , item_ident : & impl ItemIdents ) -> Result < ( ) > {
222223 let mut errors = Error :: accumulator ( ) ;
223224
224225 for change in & self . changes {
@@ -230,7 +231,7 @@ impl CommonItemAttributes {
230231
231232 // This ensures that `from_name` doesn't include the deprecation prefix.
232233 if let Some ( from_name) = change. from_name . as_ref ( ) {
233- if from_name. starts_with ( item_ident. deprecated_prefix ( ) ) {
234+ if from_name. starts_with ( item_ident. deprecation_prefix ( ) ) {
234235 errors. push (
235236 Error :: custom (
236237 "the previous name must not start with the deprecation prefix" ,
@@ -291,17 +292,17 @@ impl CommonItemAttributes {
291292impl CommonItemAttributes {
292293 pub fn into_changeset (
293294 self ,
294- ident : & impl ItemIdentExt ,
295+ idents : & impl ItemIdents ,
295296 ty : Type ,
296297 ) -> Option < BTreeMap < Version , ItemStatus > > {
297298 // TODO (@Techassi): Use Change instead of ItemStatus
298299 if let Some ( deprecated) = self . deprecated {
299- let deprecated_ident = ident . deref ( ) ;
300+ let deprecated_ident = idents . original ( ) ;
300301
301302 // When the item is deprecated, any change which occurred beforehand
302303 // requires access to the item ident to infer the item ident for
303304 // the latest change.
304- let mut ident = ident . as_cleaned_ident ( ) ;
305+ let mut ident = idents . cleaned ( ) . clone ( ) ;
305306 let mut ty = ty;
306307
307308 let mut actions = BTreeMap :: new ( ) ;
@@ -361,7 +362,7 @@ impl CommonItemAttributes {
361362
362363 Some ( actions)
363364 } else if !self . changes . is_empty ( ) {
364- let mut ident = ident . deref ( ) . clone ( ) ;
365+ let mut ident = idents . original ( ) . clone ( ) ;
365366 let mut ty = ty;
366367
367368 let mut actions = BTreeMap :: new ( ) ;
@@ -419,7 +420,7 @@ impl CommonItemAttributes {
419420 * added. since ,
420421 ItemStatus :: Addition {
421422 default_fn : added. default_fn . deref ( ) . clone ( ) ,
422- ident : ident . deref ( ) . clone ( ) ,
423+ ident : idents . original ( ) . clone ( ) ,
423424 ty : Box :: new ( ty) ,
424425 } ,
425426 ) ;
0 commit comments