-
-
Notifications
You must be signed in to change notification settings - Fork 315
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
parse_nested_meta
docs: mention that error will be returned if closure doesn't parse non-path parts
#1426
Comments
Will also be nice to improve error message: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=143d258548b205268c85cd1e38dedae9 |
I ran into this issue just now and I can say this is a big pain. Here are some reasons :
|
I also suffered some from let mut checked = false;
if let Err(error) = repr_attr.parse_nested_meta(|meta| {
if checked || meta.path.is_ident("C") || meta.path.is_ident("transparent") {
checked = true;
Ok(())
} else {
Err(Error::new(
input.ident.span(),
"`IoType` on structs requires `#[repr(C)]` or `#[repr(transparent)]",
))
}
}) {
return error.to_compile_error().into();
} However, failure to parse all possible cases results in confusing error, like this:
Even though as described above my handler didn't return any errors. I have not found more ergonomic ways to parse it either. |
I tried using
parse_nested_meta
for something very similar to therepr
-parsing example given in the docs, except that I didn't need all the information. I was confused whyparse_nested_meta
returned an error sometimes, even though the closure I passed in did not return an error, and therepr
being parsed was valid. I eventually realized that this is because I wasn't parsing the(N)
part ofalign(N)
. Simplified example:Assuming that this is the intended behavior of
parse_nested_meta
, it would be helpful to describe in the docs exactly what the closure needs to handle itself in order to avoidparse_nested_meta
returning an error.The text was updated successfully, but these errors were encountered: