From f4de08cf3589d5c2de6e3c14c766adb7a352e345 Mon Sep 17 00:00:00 2001 From: Robert Usher <266585+dcchut@users.noreply.github.com> Date: Fri, 24 Mar 2023 19:50:06 +1100 Subject: [PATCH 1/3] Upgrade to syn v2 --- Cargo.toml | 2 +- src/attr.rs | 19 +++++++++++-------- src/expand.rs | 14 +++++++------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b621412..21cc5a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ default = ["std"] std = [] [dependencies] -syn = "1.0" +syn = "2.0" quote = "1.0" proc-macro2 = "1.0" diff --git a/src/attr.rs b/src/attr.rs index 23f1ef6..afda4b9 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -42,10 +42,10 @@ impl AttrsHelper { pub(crate) fn new(attrs: &[Attribute]) -> Self { let ignore_extra_doc_attributes = attrs .iter() - .any(|attr| attr.path.is_ident("ignore_extra_doc_attributes")); + .any(|attr| attr.path().is_ident("ignore_extra_doc_attributes")); let prefix_enum_doc_attributes = attrs .iter() - .any(|attr| attr.path.is_ident("prefix_enum_doc_attributes")); + .any(|attr| attr.path().is_ident("prefix_enum_doc_attributes")); Self { ignore_extra_doc_attributes, @@ -54,7 +54,7 @@ impl AttrsHelper { } pub(crate) fn display(&self, attrs: &[Attribute]) -> Result> { - let displaydoc_attr = attrs.iter().find(|attr| attr.path.is_ident("displaydoc")); + let displaydoc_attr = attrs.iter().find(|attr| attr.path().is_ident("displaydoc")); if let Some(displaydoc_attr) = displaydoc_attr { let lit = displaydoc_attr @@ -71,7 +71,7 @@ impl AttrsHelper { let num_doc_attrs = attrs .iter() - .filter(|attr| attr.path.is_ident("doc")) + .filter(|attr| attr.path().is_ident("doc")) .count(); if !self.ignore_extra_doc_attributes && num_doc_attrs > 1 { @@ -79,11 +79,14 @@ impl AttrsHelper { } for attr in attrs { - if attr.path.is_ident("doc") { - let meta = attr.parse_meta()?; - let lit = match meta { + if attr.path().is_ident("doc") { + let lit = match &attr.meta { Meta::NameValue(syn::MetaNameValue { - lit: syn::Lit::Str(lit), + value: + syn::Expr::Lit(syn::ExprLit { + lit: syn::Lit::Str(lit), + .. + }), .. }) => lit, _ => unimplemented!(), diff --git a/src/expand.rs b/src/expand.rs index 9e4b8d2..e448ab8 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -3,7 +3,7 @@ use proc_macro2::{Span, TokenStream}; use quote::{format_ident, quote}; use syn::{ punctuated::Punctuated, - token::{Add, Colon, Colon2, Comma, Where}, + token::{Colon, Comma, PathSep, Plus, Where}, Data, DataEnum, DataStruct, DeriveInput, Error, Fields, Generics, Ident, Path, PathArguments, PathSegment, PredicateType, Result, TraitBound, TraitBoundModifier, Type, TypeParam, TypeParamBound, TypePath, WhereClause, WherePredicate, @@ -110,7 +110,7 @@ fn impl_struct(input: &DeriveInput, data: &DataStruct) -> Result { /// Create a `where` predicate for `ident`, without any [bound][TypeParamBound]s yet. fn new_empty_where_type_predicate(ident: Ident) -> PredicateType { - let mut path_segments = Punctuated::::new(); + let mut path_segments = Punctuated::::new(); path_segments.push_value(PathSegment { ident, arguments: PathArguments::None, @@ -127,7 +127,7 @@ fn new_empty_where_type_predicate(ident: Ident) -> PredicateType { colon_token: Colon { spans: [Span::call_site()], }, - bounds: Punctuated::::new(), + bounds: Punctuated::::new(), } } @@ -149,14 +149,14 @@ enum UseGlobalPrefix { /// Create a path with segments composed of [Idents] *without* any [PathArguments]. fn join_paths(name_segments: &[&str], use_global_prefix: UseGlobalPrefix) -> Path { - let mut segments = Punctuated::::new(); + let mut segments = Punctuated::::new(); assert!(!name_segments.is_empty()); segments.push_value(PathSegment { ident: Ident::new(name_segments[0], Span::call_site()), arguments: PathArguments::None, }); for name in name_segments[1..].iter() { - segments.push_punct(Colon2 { + segments.push_punct(PathSep { spans: [Span::call_site(), Span::mixed_site()], }); segments.push_value(PathSegment { @@ -166,7 +166,7 @@ fn join_paths(name_segments: &[&str], use_global_prefix: UseGlobalPrefix) -> Pat } Path { leading_colon: match use_global_prefix { - UseGlobalPrefix::LeadingColon => Some(Colon2 { + UseGlobalPrefix::LeadingColon => Some(PathSep { spans: [Span::call_site(), Span::mixed_site()], }), UseGlobalPrefix::NoLeadingColon => None, @@ -205,7 +205,7 @@ fn add_display_constraint_to_type_predicate( path: display_path, }); if !predicate_that_needs_a_display_impl.bounds.is_empty() { - predicate_that_needs_a_display_impl.bounds.push_punct(Add { + predicate_that_needs_a_display_impl.bounds.push_punct(Plus { spans: [Span::call_site()], }); } From c6688d9e0b84fdc0ab437141ed045f87d2d5bc33 Mon Sep 17 00:00:00 2001 From: Robert Usher <266585+dcchut@users.noreply.github.com> Date: Fri, 24 Mar 2023 19:50:17 +1100 Subject: [PATCH 2/3] Bump MSRV to 1.56 --- .github/workflows/ci.yml | 6 +++--- README.md | 2 +- src/lib.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fd6ecab..1713afd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: matrix: rust: - stable - - 1.45.0 + - 1.56.0 steps: - uses: actions/checkout@v1 - uses: actions-rs/toolchain@v1 @@ -64,7 +64,7 @@ jobs: strategy: matrix: rust: - - 1.45.0 + - 1.56.0 steps: - uses: actions/checkout@v1 - uses: actions-rs/toolchain@v1 @@ -87,7 +87,7 @@ jobs: matrix: rust: - stable - - 1.45.0 + - 1.56.0 steps: - uses: actions/checkout@v1 - uses: actions-rs/toolchain@v1 diff --git a/README.md b/README.md index 984f3b4..c2bb5ef 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This library provides a convenient derive macro for the standard library's displaydoc = "0.2" ``` -*Compiler support: requires rustc 1.45+* +*Compiler support: requires rustc 1.56+*
diff --git a/src/lib.rs b/src/lib.rs index dd843c9..24c0cfb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ //! displaydoc = "0.2" //! ``` //! -//! *Compiler support: requires rustc 1.45+* +//! *Compiler support: requires rustc 1.56+* //! //!
//! From 82929c1965fd312e3020d5da1c972aaede3ea4b1 Mon Sep 17 00:00:00 2001 From: Robert Usher <266585+dcchut@users.noreply.github.com> Date: Fri, 24 Mar 2023 19:59:03 +1100 Subject: [PATCH 3/3] const_err now a hard error, remove warning --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 24c0cfb..0d97d27 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -98,7 +98,6 @@ rust_2018_idioms, unreachable_pub, bad_style, - const_err, dead_code, improper_ctypes, non_shorthand_field_patterns,