Keep items that have attr parse errors
diff --git a/syntax/attrs.rs b/syntax/attrs.rs
index edb403d..1cb0657 100644
--- a/syntax/attrs.rs
+++ b/syntax/attrs.rs
@@ -1,3 +1,4 @@
+use crate::syntax::report::Errors;
use crate::syntax::{Derive, Doc};
use proc_macro2::Ident;
use syn::parse::{ParseStream, Parser as _};
@@ -9,35 +10,44 @@
pub derives: Option<&'a mut Vec<Derive>>,
}
-pub(super) fn parse_doc(attrs: &[Attribute]) -> Result<Doc> {
+pub(super) fn parse_doc(cx: &mut Errors, attrs: &[Attribute]) -> Doc {
let mut doc = Doc::new();
parse(
+ cx,
attrs,
Parser {
doc: Some(&mut doc),
..Parser::default()
},
- )?;
- Ok(doc)
+ );
+ doc
}
-pub(super) fn parse(attrs: &[Attribute], mut parser: Parser) -> Result<()> {
+pub(super) fn parse(cx: &mut Errors, attrs: &[Attribute], mut parser: Parser) {
for attr in attrs {
if attr.path.is_ident("doc") {
- if let Some(doc) = &mut parser.doc {
- let lit = parse_doc_attribute.parse2(attr.tokens.clone())?;
- doc.push(lit);
- continue;
+ match parse_doc_attribute.parse2(attr.tokens.clone()) {
+ Ok(lit) => {
+ if let Some(doc) = &mut parser.doc {
+ doc.push(lit);
+ continue;
+ }
+ }
+ Err(err) => return cx.push(err),
}
} else if attr.path.is_ident("derive") {
- if let Some(derives) = &mut parser.derives {
- derives.extend(attr.parse_args_with(parse_derive_attribute)?);
- continue;
+ match attr.parse_args_with(parse_derive_attribute) {
+ Ok(attr) => {
+ if let Some(derives) = &mut parser.derives {
+ derives.extend(attr);
+ continue;
+ }
+ }
+ Err(err) => return cx.push(err),
}
}
- return Err(Error::new_spanned(attr, "unsupported attribute"));
+ return cx.error(attr, "unsupported attribute");
}
- Ok(())
}
fn parse_doc_attribute(input: ParseStream) -> Result<LitStr> {