Skip to content

Commit

Permalink
Refactor check() function
Browse files Browse the repository at this point in the history
  • Loading branch information
dpytaylo committed Jan 5, 2024
1 parent 7de6504 commit c39923d
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions garde_derive/src/check_deprecated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ pub fn check(input: &model::Input) -> DeprecatedWarningSpans {
let mut spans = Vec::new();
match kind {
model::InputKind::Struct(variant) => {
spans.append(&mut check_variant(variant));
check_variant(variant, &mut spans);
}
model::InputKind::Enum(list) => {
for (_, variant) in list {
if let Some(variant) = variant {
spans.append(&mut check_variant(variant));
check_variant(variant, &mut spans);
}
}
}
Expand All @@ -33,38 +33,31 @@ pub fn check(input: &model::Input) -> DeprecatedWarningSpans {
}
}

fn check_variant(variant: &model::Variant) -> Vec<Span> {
let mut spans = Vec::new();

fn check_variant(variant: &model::Variant, spans: &mut Vec<Span>) {
match variant {
model::Variant::Struct(map) => {
for field in map.values() {
spans.append(&mut check_field(field));
check_field(field, spans);
}
}
model::Variant::Tuple(list) => {
for field in list {
spans.append(&mut check_field(field));
check_field(field, spans);
}
}
};

spans
}
}

fn check_field(field: &model::Field) -> Vec<Span> {
fn check_field(field: &model::Field, spans: &mut Vec<Span>) {
let model::Field {
rules: raw_rules, ..
} = field;

let mut spans = Vec::new();
for RawRule { span, kind } in raw_rules {
if let model::RawRuleKind::ByteLength(_) = kind {
spans.push(*span);
}
}

spans
}

impl ToTokens for DeprecatedWarningSpans {
Expand Down

0 comments on commit c39923d

Please sign in to comment.