From fb8b81f20b352b9adf47639a9af1dbcbdcc13d81 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 13 Mar 2023 11:15:43 -0700 Subject: [PATCH] Update to syn 2 --- .clippy.toml | 2 +- .github/workflows/ci.yml | 13 ------------- Cargo.toml | 2 +- README.md | 2 +- impl/Cargo.toml | 4 ++-- impl/src/attr.rs | 38 ++++++++++++++++++++++++-------------- impl/src/expand.rs | 3 +-- 7 files changed, 30 insertions(+), 34 deletions(-) diff --git a/.clippy.toml b/.clippy.toml index 3d30690..0d369b5 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -1 +1 @@ -msrv = "1.31.0" +msrv = "1.56.0" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 845bf6c..2c00fde 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,19 +40,6 @@ jobs: if: matrix.rust == 'nightly' - run: cargo test --all - msrv: - name: Rust 1.31.0 - needs: pre_ci - if: needs.pre_ci.outputs.continue - runs-on: ubuntu-latest - timeout-minutes: 45 - steps: - - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@1.31.0 - with: - components: rust-src - - run: cargo check - clippy: name: Clippy runs-on: ubuntu-latest diff --git a/Cargo.toml b/Cargo.toml index e39e3ed..8c9f917 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ edition = "2018" keywords = ["error", "error-handling", "derive"] license = "MIT OR Apache-2.0" repository = "https://github.com/dtolnay/thiserror" -rust-version = "1.31" +rust-version = "1.56" [dependencies] thiserror-impl = { version = "=1.0.39", path = "impl" } diff --git a/README.md b/README.md index 3ba375f..9de063c 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ This library provides a convenient derive macro for the standard library's thiserror = "1.0" ``` -*Compiler support: requires rustc 1.31+* +*Compiler support: requires rustc 1.56+*
diff --git a/impl/Cargo.toml b/impl/Cargo.toml index d6dc48e..e7766a1 100644 --- a/impl/Cargo.toml +++ b/impl/Cargo.toml @@ -6,7 +6,7 @@ description = "Implementation detail of the `thiserror` crate" edition = "2018" license = "MIT OR Apache-2.0" repository = "https://github.com/dtolnay/thiserror" -rust-version = "1.31" +rust-version = "1.56" [lib] proc-macro = true @@ -14,7 +14,7 @@ proc-macro = true [dependencies] proc-macro2 = "1.0" quote = "1.0" -syn = "1.0.45" +syn = "2.0" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/impl/src/attr.rs b/impl/src/attr.rs index 9963fd6..0b1b89d 100644 --- a/impl/src/attr.rs +++ b/impl/src/attr.rs @@ -2,9 +2,9 @@ use proc_macro2::{Delimiter, Group, Span, TokenStream, TokenTree}; use quote::{format_ident, quote, ToTokens}; use std::collections::BTreeSet as Set; use std::iter::FromIterator; -use syn::parse::{Nothing, ParseStream}; +use syn::parse::ParseStream; use syn::{ - braced, bracketed, parenthesized, token, Attribute, Error, Ident, Index, LitInt, LitStr, + braced, bracketed, parenthesized, token, Attribute, Error, Ident, Index, LitInt, LitStr, Meta, Result, Token, }; @@ -54,24 +54,27 @@ pub fn get(input: &[Attribute]) -> Result { }; for attr in input { - if attr.path.is_ident("error") { + if attr.path().is_ident("error") { parse_error_attribute(&mut attrs, attr)?; - } else if attr.path.is_ident("source") { + } else if attr.path().is_ident("source") { require_empty_attribute(attr)?; 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") { + } else if attr.path().is_ident("backtrace") { require_empty_attribute(attr)?; if attrs.backtrace.is_some() { return Err(Error::new_spanned(attr, "duplicate #[backtrace] attribute")); } attrs.backtrace = Some(attr); - } else if attr.path.is_ident("from") { - if !attr.tokens.is_empty() { - // Assume this is meant for derive_more crate or something. - continue; + } else if attr.path().is_ident("from") { + match attr.meta { + Meta::Path(_) => {} + Meta::List(_) | Meta::NameValue(_) => { + // Assume this is meant for derive_more crate or something. + continue; + } } if attrs.from.is_some() { return Err(Error::new_spanned(attr, "duplicate #[from] attribute")); @@ -166,21 +169,21 @@ fn parse_token_expr(input: ParseStream, mut begin_expr: bool) -> Result Result Result<()> { - syn::parse2::(attr.tokens.clone())?; - Ok(()) + 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<'_> { diff --git a/impl/src/expand.rs b/impl/src/expand.rs index 293cb56..ef8eaf3 100644 --- a/impl/src/expand.rs +++ b/impl/src/expand.rs @@ -528,8 +528,7 @@ fn type_parameter_of_option(ty: &Type) -> Option<&Type> { fn spanned_error_trait(input: &DeriveInput) -> TokenStream { let vis_span = match &input.vis { - Visibility::Public(vis) => Some(vis.pub_token.span), - Visibility::Crate(vis) => Some(vis.crate_token.span), + Visibility::Public(vis) => Some(vis.span), Visibility::Restricted(vis) => Some(vis.pub_token.span), Visibility::Inherited => None, };