Make event_enum! error message more helpful

This commit is contained in:
Devin R 2020-06-10 06:22:23 -04:00 committed by Jonas Platte
parent 86ca6bb39d
commit aea827a199
2 changed files with 9 additions and 2 deletions

View File

@ -192,11 +192,18 @@ fn to_event_content_path(name: &LitStr) -> TokenStream {
pub(crate) fn to_camel_case(name: &LitStr) -> Ident { pub(crate) fn to_camel_case(name: &LitStr) -> Ident {
let span = name.span(); let span = name.span();
let name = name.value(); let name = name.value();
assert_eq!(&name[..2], "m.");
assert_eq!(
&name[..2],
"m.",
"well-known matrix events have to start with `m.`"
);
let s = name[2..] let s = name[2..]
.split(&['.', '_'] as &[char]) .split(&['.', '_'] as &[char])
.map(|s| s.chars().next().unwrap().to_uppercase().to_string() + &s[1..]) .map(|s| s.chars().next().unwrap().to_uppercase().to_string() + &s[1..])
.collect::<String>(); .collect::<String>();
Ident::new(&s, span) Ident::new(&s, span)
} }

View File

@ -11,7 +11,7 @@ error: proc macro panicked
| |
= help: message: assertion failed: `(left == right)` = help: message: assertion failed: `(left == right)`
left: `"no"`, left: `"no"`,
right: `"m."` right: `"m."`: well-known matrix events have to start with `m.`
error[E0433]: failed to resolve: could not find `not` in `ruma_events` error[E0433]: failed to resolve: could not find `not` in `ruma_events`
--> $DIR/08-enum-invalid-path.rs:6:9 --> $DIR/08-enum-invalid-path.rs:6:9