diff options
| author | John Turner <jturner.usa@gmail.com> | 2023-04-20 02:42:20 -0400 |
|---|---|---|
| committer | John Turner <jturner.usa@gmail.com> | 2023-04-20 02:42:20 -0400 |
| commit | 27ad0e1b5ab6adf5536eb65583c515f46a65b1e5 (patch) | |
| tree | a75fbf9d5dcc124a3da79f96e70da142fde08d32 | |
| parent | 5ba52d4806c51e80f241df8a00712451726ab81b (diff) | |
| download | get-27ad0e1b5ab6adf5536eb65583c515f46a65b1e5.tar.gz | |
improved error messages for attribute-less tuple struct fields
| -rw-r--r-- | src/lib.rs | 12 | ||||
| -rw-r--r-- | tests/trybuild/tuple-struct-without-attribute.stderr | 2 |
2 files changed, 12 insertions, 2 deletions
@@ -96,8 +96,18 @@ mod get { Some(Ok(get_attr)) if get_attr.method.is_some() => { format_ident!("{}", get_attr.method.unwrap().as_str()) } + // Currently unreachable because an empty GetAttrubute is an error, and there is only + // one field that can be set right now. + Some(Ok(_)) => { + return Err(concat!( + r#"expected name value pair on tuple struct field"#, + " ", + r#"(e.g #[get("method" = method_name)])"# + ) + .into()) + } Some(Err(e)) => return Err(e), - _ => return Err(r#"tuple fields are required to have an attribute"#.into()), + None => return Err(r#"expected attribute on tuple struct field"#.into()), }; let getter = expand_getter( field, diff --git a/tests/trybuild/tuple-struct-without-attribute.stderr b/tests/trybuild/tuple-struct-without-attribute.stderr index 7ddd8c6..33791f4 100644 --- a/tests/trybuild/tuple-struct-without-attribute.stderr +++ b/tests/trybuild/tuple-struct-without-attribute.stderr @@ -4,4 +4,4 @@ error: proc-macro derive panicked 3 | #[derive(Get)] | ^^^ | - = help: message: called `Result::unwrap()` on an `Err` value: "tuple fields are required to have an attribute" + = help: message: called `Result::unwrap()` on an `Err` value: "expected attribute on tuple struct field" |
