Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide list of recognized rename rules on parse error #1961

Merged
merged 2 commits into from Jan 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions serde_derive/src/internals/case.rs
Expand Up @@ -5,7 +5,7 @@
#[allow(deprecated, unused_imports)]
use std::ascii::AsciiExt;

use std::fmt::{self, Display};
use std::fmt::{self, Debug, Display};

use self::RenameRule::*;

Expand Down Expand Up @@ -120,11 +120,16 @@ pub struct ParseError<'a> {

impl<'a> Display for ParseError<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"unknown rename rule for #[serde(rename_all = {:?})]",
self.unknown,
)
f.write_str("unknown rename rule `rename_all = ")?;
Debug::fmt(self.unknown, f)?;
f.write_str("`, expected one of ")?;
for (i, (name, _rule)) in RENAME_RULES.iter().enumerate() {
if i > 0 {
f.write_str(", ")?;
}
Debug::fmt(name, f)?;
}
Ok(())
}
}

Expand Down
@@ -1,4 +1,4 @@
error: unknown rename rule for #[serde(rename_all = "abc")]
error: unknown rename rule `rename_all = "abc"`, expected one of "lowercase", "UPPERCASE", "PascalCase", "camelCase", "snake_case", "SCREAMING_SNAKE_CASE", "kebab-case", "SCREAMING-KEBAB-CASE"
--> $DIR/container_unknown_rename_rule.rs:4:22
|
4 | #[serde(rename_all = "abc")]
Expand Down
@@ -1,4 +1,4 @@
error: unknown rename rule for #[serde(rename_all = "abc")]
error: unknown rename rule `rename_all = "abc"`, expected one of "lowercase", "UPPERCASE", "PascalCase", "camelCase", "snake_case", "SCREAMING_SNAKE_CASE", "kebab-case", "SCREAMING-KEBAB-CASE"
--> $DIR/variant_unknown_rename_rule.rs:5:26
|
5 | #[serde(rename_all = "abc")]
Expand Down