Skip to content

Commit

Permalink
Use error reporting provided by Meta
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Mar 18, 2023
1 parent 07c66e7 commit 39aaeb0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
2 changes: 1 addition & 1 deletion impl/Cargo.toml
Expand Up @@ -14,7 +14,7 @@ proc-macro = true
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
syn = "2.0"
syn = "2.0.1"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
16 changes: 2 additions & 14 deletions impl/src/attr.rs
Expand Up @@ -57,13 +57,13 @@ pub fn get(input: &[Attribute]) -> Result<Attrs> {
if attr.path().is_ident("error") {
parse_error_attribute(&mut attrs, attr)?;
} else if attr.path().is_ident("source") {
require_empty_attribute(attr)?;
attr.meta.require_path_only()?;
if attrs.source.is_some() {
return Err(Error::new_spanned(attr, "duplicate #[source] attribute"));
}
attrs.source = Some(attr);
} else if attr.path().is_ident("backtrace") {
require_empty_attribute(attr)?;
attr.meta.require_path_only()?;
if attrs.backtrace.is_some() {
return Err(Error::new_spanned(attr, "duplicate #[backtrace] attribute"));
}
Expand Down Expand Up @@ -193,18 +193,6 @@ fn parse_token_expr(input: ParseStream, mut begin_expr: bool) -> Result<TokenStr
Ok(TokenStream::from_iter(tokens))
}

fn require_empty_attribute(attr: &Attribute) -> Result<()> {
let error_span = match &attr.meta {
Meta::Path(_) => return Ok(()),
Meta::List(meta) => meta.delimiter.span().open(),
Meta::NameValue(meta) => meta.eq_token.span,
};
Err(Error::new(
error_span,
"unexpected token in thiserror attribute",
))
}

impl ToTokens for Display<'_> {
fn to_tokens(&self, tokens: &mut TokenStream) {
let fmt = &self.fmt;
Expand Down

0 comments on commit 39aaeb0

Please sign in to comment.