From 25c73d7cdf8029dedfa366b40e5a67f978fbba5b Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 3 Nov 2020 16:32:05 -0800 Subject: [PATCH 1/3] Add test of keyword fmt argument Presently crashes with: error: proc-macro derive panicked --> tests/test_display.rs:269:14 | 269 | #[derive(Error, Debug)] | ^^^^^ | = help: message: called `Result::unwrap()` on an `Err` value: Error("expected identifier") --- tests/test_display.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_display.rs b/tests/test_display.rs index 769da5c..949d9ed 100644 --- a/tests/test_display.rs +++ b/tests/test_display.rs @@ -263,3 +263,12 @@ fn test_raw_conflict() { assert("braced raw error: T, U", Error::Braced { r#func: "T" }); } + +#[test] +fn test_keyword() { + #[derive(Error, Debug)] + #[error("error: {type}", type = 1)] + struct Error; + + assert("error: 1", Error); +} From 2722f8e2c3b98c76902da3d10aa7938b9cc6168d Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 3 Nov 2020 16:38:35 -0800 Subject: [PATCH 2/3] Fix first place that keyword fmt argument is failing --- impl/src/fmt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/impl/src/fmt.rs b/impl/src/fmt.rs index d435a80..7e04c1e 100644 --- a/impl/src/fmt.rs +++ b/impl/src/fmt.rs @@ -102,7 +102,7 @@ fn explicit_named_args(input: ParseStream) -> Result> { while !input.is_empty() { if input.peek(Token![,]) && input.peek2(Ident::peek_any) && input.peek3(Token![=]) { input.parse::()?; - let ident: Ident = input.parse()?; + let ident = input.call(Ident::parse_any)?; input.parse::()?; named_args.insert(ident); } else { From aafcf0a1b6946b407740fce08c783db5a96cdb20 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 3 Nov 2020 16:41:37 -0800 Subject: [PATCH 3/3] Fix second place that keyword fmt argument is failing --- impl/src/fmt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/impl/src/fmt.rs b/impl/src/fmt.rs index 7e04c1e..e12e94b 100644 --- a/impl/src/fmt.rs +++ b/impl/src/fmt.rs @@ -143,5 +143,5 @@ fn take_ident(read: &mut &str) -> Ident { } } } - syn::parse_str(&ident).unwrap() + Ident::parse_any.parse_str(&ident).unwrap() }