Skip to content

Commit d6c6f7b

Browse files
committed
feat(stackable-versioned): Add new changed() validation
This throws an error if both from_name and from_type are unset which suggests this action is not needed.
1 parent 04a5be3 commit d6c6f7b

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,14 @@ impl CommonItemAttributes {
221221
fn validate_changed_action(&self, item_ident: &impl ItemIdentExt) -> Result<()> {
222222
let mut errors = Error::accumulator();
223223

224-
// This ensures that `from_name` doesn't include the deprecation prefix.
225224
for change in &self.changes {
225+
if change.from_name.is_none() && change.from_type.is_none() {
226+
errors.push(Error::custom(
227+
"both `from_name` and `from_type` are unset. Is this `changed()` action needed?"
228+
).with_span(&change.since.span()));
229+
}
230+
231+
// This ensures that `from_name` doesn't include the deprecation prefix.
226232
if let Some(from_name) = change.from_name.as_ref() {
227233
if from_name.starts_with(item_ident.deprecated_prefix()) {
228234
errors.push(
@@ -447,10 +453,6 @@ fn default_default_fn() -> SpannedValue<Path> {
447453
)
448454
}
449455

450-
// TODO (@Techassi): Add validation for when from_name AND from_type are both
451-
// none => is this action needed in the first place?
452-
// TODO (@Techassi): Add validation that the from_name mustn't include the
453-
// deprecated prefix.
454456
/// For the changed() action
455457
///
456458
/// Example usage:

crates/stackable-versioned-macros/tests/inputs/default/fail/changed.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ fn main() {
44
#[versioned(
55
version(name = "v1alpha1"),
66
version(name = "v1beta1"),
7-
version(name = "v1")
7+
version(name = "v1"),
8+
version(name = "v2")
89
)]
910
struct Foo {
1011
#[versioned(
1112
changed(since = "v1beta1", from_name = "deprecated_bar"),
12-
changed(since = "v1", from_name = "deprecated_baz")
13+
changed(since = "v1", from_name = "deprecated_baz"),
14+
changed(since = "v2")
1315
)]
1416
bar: usize,
1517
}

crates/stackable-versioned-macros/tests/inputs/default/fail/changed.stderr

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)