Skip to content

Commit f2c367e

Browse files
committed
feat: Make note of deprecated action optional
1 parent 3937f57 commit f2c367e

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

crates/stackable-versioned-macros/src/attrs/common/item.rs

+2-15
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,6 @@ impl ItemAttributes {
143143

144144
let mut errors = Error::accumulator();
145145

146-
// TODO (@Techassi): Make the field or variant 'note' optional, because
147-
// in the future, the macro will generate parts of the deprecation note
148-
// automatically. The user-provided note will then be appended to the
149-
// auto-generated one.
150-
151-
if let Some(deprecated) = &self.deprecated {
152-
if deprecated.note.is_empty() {
153-
errors.push(
154-
Error::custom("deprecation note must not be empty")
155-
.with_span(&deprecated.note.span()),
156-
);
157-
}
158-
}
159-
160146
// Semantic validation
161147
errors.handle(self.validate_action_combinations(item_ident, item_type));
162148
errors.handle(self.validate_action_order(item_ident, item_type));
@@ -348,9 +334,10 @@ pub(crate) struct ChangedAttributes {
348334
/// For the deprecated() action
349335
///
350336
/// Example usage:
337+
/// - `deprecated(since = "...")`
351338
/// - `deprecated(since = "...", note = "...")`
352339
#[derive(Clone, Debug, FromMeta)]
353340
pub(crate) struct DeprecatedAttributes {
354341
pub(crate) since: SpannedValue<Version>,
355-
pub(crate) note: SpannedValue<String>,
342+
pub(crate) note: Option<SpannedValue<String>>,
356343
}

crates/stackable-versioned-macros/src/codegen/common/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ where
148148
ItemStatus::Deprecation {
149149
previous_ident: ident.clone(),
150150
ident: deprecated_ident.clone(),
151-
note: deprecated.note.to_string(),
151+
note: deprecated.note.as_deref().cloned(),
152152
},
153153
);
154154

@@ -363,8 +363,8 @@ pub(crate) enum ItemStatus {
363363
},
364364
Deprecation {
365365
previous_ident: Ident,
366+
note: Option<String>,
366367
ident: Ident,
367-
note: String,
368368
},
369369
NoChange(Ident),
370370
NotPresent,

crates/stackable-versioned-macros/src/codegen/vstruct/field.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,27 @@ impl VersionedField {
135135
ident: field_ident,
136136
note,
137137
..
138-
} => Some(quote! {
139-
#(#original_attributes)*
140-
#[deprecated = #note]
141-
pub #field_ident: #field_type,
142-
}),
138+
} => {
139+
// FIXME (@Techassi): Emitting the deprecated attribute
140+
// should cary over even when the item status is
141+
// 'NoChange'.
142+
// TODO (@Techassi): Make the generation of deprecated
143+
// items customizable. When a container is used as a K8s
144+
// CRD, the item must continue to exist, even when
145+
// deprecated. For other versioning use-cases, that
146+
// might not be the case.
147+
let deprecated_attr = if let Some(note) = note {
148+
quote! {#[deprecated = #note]}
149+
} else {
150+
quote! {#[deprecated]}
151+
};
152+
153+
Some(quote! {
154+
#(#original_attributes)*
155+
#deprecated_attr
156+
pub #field_ident: #field_type,
157+
})
158+
}
143159
ItemStatus::NotPresent => None,
144160
ItemStatus::NoChange(field_ident) => Some(quote! {
145161
#(#original_attributes)*

0 commit comments

Comments
 (0)