Skip to content

Commit

Permalink
Fix location of rename_all errors (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
escritorio-gustavo authored Apr 9, 2024
1 parent 8cfc3d7 commit b9a4cca
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
40 changes: 21 additions & 19 deletions macros/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,27 @@ fn parse_concrete(input: ParseStream) -> Result<HashMap<syn::Ident, syn::Type>>
}

fn parse_assign_inflection(input: ParseStream) -> Result<Inflection> {
let span = input.span();
let str = parse_assign_str(input)?;

Ok(match &*str {
"lowercase" => Inflection::Lower,
"UPPERCASE" => Inflection::Upper,
"camelCase" => Inflection::Camel,
"snake_case" => Inflection::Snake,
"PascalCase" => Inflection::Pascal,
"SCREAMING_SNAKE_CASE" => Inflection::ScreamingSnake,
"kebab-case" => Inflection::Kebab,
"SCREAMING-KEBAB-CASE" => Inflection::ScreamingKebab,
other => {
syn_err!(
span;
r#"Value "{other}" is not valid for "rename_all". Accepted values are: "lowercase", "UPPERCASE", "camelCase", "snake_case", "PascalCase", "SCREAMING_SNAKE_CASE", "kebab-case" and "SCREAMING-KEBAB-CASE""#
)
}
})
input.parse::<Token![=]>()?;

match Lit::parse(input)? {
Lit::Str(string) => Ok(match &*string.value() {
"lowercase" => Inflection::Lower,
"UPPERCASE" => Inflection::Upper,
"camelCase" => Inflection::Camel,
"snake_case" => Inflection::Snake,
"PascalCase" => Inflection::Pascal,
"SCREAMING_SNAKE_CASE" => Inflection::ScreamingSnake,
"kebab-case" => Inflection::Kebab,
"SCREAMING-KEBAB-CASE" => Inflection::ScreamingKebab,
other => {
syn_err!(
string.span();
r#"Value "{other}" is not valid for "rename_all". Accepted values are: "lowercase", "UPPERCASE", "camelCase", "snake_case", "PascalCase", "SCREAMING_SNAKE_CASE", "kebab-case" and "SCREAMING-KEBAB-CASE""#
)
}
}),
other => Err(Error::new(other.span(), "expected string")),
}
}

fn parse_assign_from_str<T>(input: ParseStream) -> Result<T>
Expand Down
2 changes: 1 addition & 1 deletion macros/src/types/named.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn format_field(
docs,

#[cfg(feature = "serde-compat")]
using_serde_with: _,
using_serde_with: _,
} = field_attr;

if skip {
Expand Down
2 changes: 1 addition & 1 deletion macros/src/types/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn format_field(
docs: _,

#[cfg(feature = "serde-compat")]
using_serde_with: _,
using_serde_with: _,
} = field_attr;

if skip {
Expand Down

0 comments on commit b9a4cca

Please sign in to comment.