1
1
use darling:: { util:: SpannedValue , Error , FromMeta } ;
2
2
use k8s_version:: Version ;
3
3
use proc_macro2:: Span ;
4
- use syn:: { spanned:: Spanned , Attribute , Ident , Path } ;
4
+ use syn:: { spanned:: Spanned , Attribute , Ident , Path , Type } ;
5
5
6
6
use crate :: {
7
7
attrs:: common:: ContainerAttributes ,
@@ -55,14 +55,14 @@ where
55
55
}
56
56
}
57
57
58
- for rename in & * self . common_attributes ( ) . renames {
58
+ for change in & * self . common_attributes ( ) . changes {
59
59
if !container_attrs
60
60
. versions
61
61
. iter ( )
62
- . any ( |v| v. name == * rename . since )
62
+ . any ( |v| v. name == * change . since )
63
63
{
64
64
errors. push (
65
- Error :: custom ( "variant action `renamed ` uses version which was not declared via #[versioned(version)]" )
65
+ Error :: custom ( "variant action `changed ` uses version which was not declared via #[versioned(version)]" )
66
66
. with_span ( item)
67
67
) ;
68
68
}
@@ -104,8 +104,8 @@ pub(crate) enum ItemType {
104
104
/// ### Shared Item Rules
105
105
///
106
106
/// - An item can only ever be added once at most. An item not marked as 'added'
107
- /// is part of the container in every version until renamed or deprecated.
108
- /// - An item can be renamed many times. That's why renames are stored in a
107
+ /// is part of the container in every version until changed or deprecated.
108
+ /// - An item can be changed many times. That's why changes are stored in a
109
109
/// [`Vec`].
110
110
/// - An item can only be deprecated once. A field or variant not marked as
111
111
/// 'deprecated' will be included up until the latest version.
@@ -115,10 +115,10 @@ pub(crate) struct ItemAttributes {
115
115
/// only be present at most once.
116
116
pub ( crate ) added : Option < AddedAttributes > ,
117
117
118
- /// This parses the `renamed ` attribute on items (fields or variants). It
118
+ /// This parses the `changed ` attribute on items (fields or variants). It
119
119
/// can be present 0..n times.
120
- #[ darling( multiple, rename = "renamed " ) ]
121
- pub ( crate ) renames : Vec < RenamedAttributes > ,
120
+ #[ darling( multiple, rename = "changed " ) ]
121
+ pub ( crate ) changes : Vec < ChangedAttributes > ,
122
122
123
123
/// This parses the `deprecated` attribute on items (fields or variants). It
124
124
/// can only be present at most once.
@@ -175,34 +175,34 @@ impl ItemAttributes {
175
175
/// cannot be marked as added in a particular version and then marked as
176
176
/// deprecated immediately after. Fields and variants must be included for
177
177
/// at least one version before being marked deprecated.
178
- /// - `added` and `renamed ` using the same version: The same reasoning from
178
+ /// - `added` and `changed ` using the same version: The same reasoning from
179
179
/// above applies here as well. Fields and variants must be included for
180
- /// at least one version before being renamed .
181
- /// - `renamed ` and `deprecated` using the same version: Again, the same
180
+ /// at least one version before being changed .
181
+ /// - `changed ` and `deprecated` using the same version: Again, the same
182
182
/// rules from above apply here as well.
183
183
fn validate_action_combinations (
184
184
& self ,
185
185
item_ident : & Ident ,
186
186
item_type : & ItemType ,
187
187
) -> Result < ( ) , Error > {
188
- match ( & self . added , & self . renames , & self . deprecated ) {
188
+ match ( & self . added , & self . changes , & self . deprecated ) {
189
189
( Some ( added) , _, Some ( deprecated) ) if * added. since == * deprecated. since => {
190
190
Err ( Error :: custom ( format ! (
191
191
"{item_type} cannot be marked as `added` and `deprecated` in the same version"
192
192
) )
193
193
. with_span ( item_ident) )
194
194
}
195
- ( Some ( added) , renamed , _) if renamed . iter ( ) . any ( |r| * r. since == * added. since ) => {
195
+ ( Some ( added) , changed , _) if changed . iter ( ) . any ( |r| * r. since == * added. since ) => {
196
196
Err ( Error :: custom ( format ! (
197
- "{item_type} cannot be marked as `added` and `renamed ` in the same version"
197
+ "{item_type} cannot be marked as `added` and `changed ` in the same version"
198
198
) )
199
199
. with_span ( item_ident) )
200
200
}
201
- ( _, renamed , Some ( deprecated) )
202
- if renamed . iter ( ) . any ( |r| * r. since == * deprecated. since ) =>
201
+ ( _, changed , Some ( deprecated) )
202
+ if changed . iter ( ) . any ( |r| * r. since == * deprecated. since ) =>
203
203
{
204
204
Err ( Error :: custom (
205
- format ! ( "{item_type} cannot be marked as `deprecated` and `renamed ` in the same version" ) ,
205
+ format ! ( "{item_type} cannot be marked as `deprecated` and `changed ` in the same version" ) ,
206
206
)
207
207
. with_span ( item_ident) )
208
208
}
@@ -220,7 +220,7 @@ impl ItemAttributes {
220
220
/// ensures that these versions are chronologically sound, that means,
221
221
/// that the version of the deprecated action must be greater than the
222
222
/// version of the added action.
223
- /// - All `renamed ` actions must use a greater version than `added` but a
223
+ /// - All `changed ` actions must use a greater version than `added` but a
224
224
/// lesser version than `deprecated`.
225
225
fn validate_action_order ( & self , item_ident : & Ident , item_type : & ItemType ) -> Result < ( ) , Error > {
226
226
let added_version = self . added . as_ref ( ) . map ( |a| * a. since ) ;
@@ -238,14 +238,14 @@ impl ItemAttributes {
238
238
}
239
239
}
240
240
241
- // Now, iterate over all renames and ensure that their versions are
241
+ // Now, iterate over all changes and ensure that their versions are
242
242
// between the added and deprecated version.
243
- if !self . renames . iter ( ) . all ( |r| {
243
+ if !self . changes . iter ( ) . all ( |r| {
244
244
added_version. map_or ( true , |a| a < * r. since )
245
245
&& deprecated_version. map_or ( true , |d| d > * r. since )
246
246
} ) {
247
247
return Err ( Error :: custom (
248
- "all renames must use versions higher than `added` and lower than `deprecated`" ,
248
+ "all changes must use versions higher than `added` and lower than `deprecated`" ,
249
249
)
250
250
. with_span ( item_ident) ) ;
251
251
}
@@ -320,19 +320,24 @@ pub(crate) struct AddedAttributes {
320
320
321
321
fn default_default_fn ( ) -> SpannedValue < Path > {
322
322
SpannedValue :: new (
323
- syn:: parse_str ( "std::default::Default::default" ) . expect ( "internal error: path must parse" ) ,
323
+ syn:: parse_str ( "::std::default::Default::default" )
324
+ . expect ( "internal error: path must parse" ) ,
324
325
Span :: call_site ( ) ,
325
326
)
326
327
}
327
328
328
- /// For the renamed () action
329
+ /// For the changed () action
329
330
///
330
331
/// Example usage:
331
- /// - `renamed(since = "...", from = "...")`
332
+ /// - `changed(since = "...", from_name = "...")`
333
+ /// - `changed(since = "...", from_name = "..." from_type="...")`
332
334
#[ derive( Clone , Debug , FromMeta ) ]
333
- pub ( crate ) struct RenamedAttributes {
335
+ pub ( crate ) struct ChangedAttributes {
334
336
pub ( crate ) since : SpannedValue < Version > ,
335
- pub ( crate ) from : SpannedValue < String > ,
337
+ pub ( crate ) from_name : Option < SpannedValue < String > > ,
338
+
339
+ #[ allow( dead_code) ]
340
+ pub ( crate ) from_type : Option < SpannedValue < Type > > ,
336
341
}
337
342
338
343
/// For the deprecated() action
0 commit comments