`parse_nested_meta` docs: mention that error will be returned if closure doesn't parse non-path parts
- Dominant language
- Rust
- Stars
- 3.4k
- Forks
- 374
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 2
Description
I tried using `parse_nested_meta` for something very similar to the `repr`-parsing example given in the docs, except that I didn't need all the information. I was confused why `parse_nested_meta` returned an error sometimes, even though the closure I passed in did not return an error, and the `repr` being parsed was valid. I eventually realized that this is because I wasn't parsing the `(N)` part of `align(N)`. Simplified example:
```rust
use anyhow::Result;
use syn::{parenthesized, parse_quote, ItemStruct, LitInt};
fn main() -> Result<()> {
let input: ItemStruct = parse_quote! {
#[repr(C, align(4))]
pub struct MyStruct(u16, u32);
};
let mut repr_align = false;
for attr in &input.attrs {
if attr.path().is_ident("repr") {
attr.parse_nested_meta(|meta| {
if meta.path.is_ident("align") {
// With this uncommented, no error occurs:
// let content;
// parenthesized!(content in meta.input);
// let lit: LitInt = content.parse()?;
repr_align = true;
return Ok(());
}
Ok(())
})
.unwrap();
}
}
Ok(())
}
```
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 avoid `parse_nested_meta` returning an error.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.