@@ -143,20 +143,20 @@ impl ItemAttributes {
143
143
144
144
let mut errors = Error :: accumulator ( ) ;
145
145
146
- // Semantic validation
146
+ // Common validation
147
147
errors. handle ( self . validate_action_combinations ( item_ident, item_type) ) ;
148
148
errors. handle ( self . validate_action_order ( item_ident, item_type) ) ;
149
149
errors. handle ( self . validate_item_name ( item_ident, item_type) ) ;
150
- errors. handle ( self . validate_changed_item_name ( item_type) ) ;
151
150
errors. handle ( self . validate_item_attributes ( item_attrs) ) ;
152
151
152
+ // Action specific validation
153
+ errors. handle ( self . validate_changed_action ( item_ident, item_type) ) ;
154
+
153
155
// TODO (@Techassi): Add hint if a field or variant is added in the
154
156
// first version that it might be clever to remove the 'added'
155
157
// attribute.
156
158
157
- errors. finish ( ) ?;
158
-
159
- Ok ( ( ) )
159
+ errors. finish ( )
160
160
}
161
161
162
162
/// This associated function is called by the top-level validation function
@@ -293,22 +293,35 @@ impl ItemAttributes {
293
293
}
294
294
}
295
295
}
296
+
296
297
Ok ( ( ) )
297
298
}
298
299
299
300
/// This associated function is called by the top-level validation function
300
301
/// and validates that parameters provided to the `changed` actions are
301
302
/// valid.
302
- fn validate_changed_item_name ( & self , item_type : & ItemType ) -> Result < ( ) , Error > {
303
+ fn validate_changed_action (
304
+ & self ,
305
+ item_ident : & Ident ,
306
+ item_type : & ItemType ,
307
+ ) -> Result < ( ) , Error > {
303
308
let prefix = match item_type {
304
309
ItemType :: Field => DEPRECATED_FIELD_PREFIX ,
305
310
ItemType :: Variant => DEPRECATED_VARIANT_PREFIX ,
306
311
} ;
307
312
308
313
let mut errors = Error :: accumulator ( ) ;
309
314
310
- // This ensures that `from_name` doesn't include the deprecation prefix.
311
315
for change in & self . changes {
316
+ // Ensure that from_name and from_type are not empty at the same
317
+ // time.
318
+ if change. from_name . is_none ( ) && change. from_type . is_none ( ) {
319
+ errors. push ( Error :: custom ( format ! (
320
+ "{item_type} was marked as `changed`, but both `from_name` and `from_type` are unset"
321
+ ) ) . with_span ( item_ident) ) ;
322
+ }
323
+
324
+ // Ensure that `from_name` doesn't include the deprecation prefix.
312
325
if let Some ( from_name) = change. from_name . as_ref ( ) {
313
326
if from_name. starts_with ( prefix) {
314
327
errors. push (
0 commit comments