Skip to content

Commit

Permalink
Do not report errors if we fail to parse a #[doc] attribute
Browse files Browse the repository at this point in the history
Fixes #139
  • Loading branch information
shepmaster committed Aug 7, 2019
1 parent 22d4168 commit 27fabe7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion snafu-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,12 @@ fn attributes_from_syn(attrs: Vec<syn::Attribute>) -> MultiSynResult<Vec<SnafuAt
if attr.path.is_ident("snafu") {
Some(parse2::<SnafuAttributeBody>(attr.tts).map(|body| body.0))
} else if attr.path.is_ident("doc") {
Some(parse2::<DocComment>(attr.tts).map(|comment| vec![comment.0]))
// Ignore any errors that occur while parsing the doc
// comment. This isn't our attribute so we shouldn't
// assume that we know what values are acceptable.
parse2::<DocComment>(attr.tts)
.ok()
.map(|comment| Ok(vec![comment.0]))
} else {
None
}
Expand Down
4 changes: 4 additions & 0 deletions tests/doc_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ enum Error {
///
/// Here is a more detailed description.
MissingUser,

/// This is just a doc comment.
#[snafu(display("This is {}", stronger))]
Stronger { stronger: &'static str },

#[doc(hidden)]
Hidden,
}

#[test]
Expand Down

0 comments on commit 27fabe7

Please sign in to comment.