diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a5af16..638ad70 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - rust-version: ['stable', 'beta', 'nightly', '1.56'] + rust-version: ['stable', 'beta', 'nightly', '1.71'] steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master diff --git a/Cargo.toml b/Cargo.toml index 0586050..d83b1f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ categories = ["development-tools", "rust-patterns"] readme = "README.md" autotests = true edition = "2021" -rust-version = "1.56" +rust-version = "1.71" [workspace] members = [ @@ -27,7 +27,7 @@ proc-macro = true [dependencies] proc-macro2 = "1.0" quote = "1.0" -syn = { version = "2.0", features = ["full", "visit", "visit-mut"] } +syn = { version = "3.0", features = ["full", "visit", "visit-mut"] } [dev-dependencies] trybuild = "1" diff --git a/README.md b/README.md index 492b3d0..fbf7e24 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ some common smart pointers and closures. # Usage -This library requires Rust 1.56.0 or newer. This library doesn't leave any public API in your code. +This library requires Rust 1.71.0 or newer. This library doesn't leave any public API in your code. Add `auto_impl` to your `Cargo.toml` and just use it in your crate: @@ -36,13 +36,13 @@ requires_foo(&0i32); // works: through the generated impl requires_foo(Box::new(0i32)); // works: through the generated impl ``` -For more explanations, please see [**the documentation**](https://docs.rs/auto_impl) and for more examples, see +For more explanations, please see [**the documentation**](https://docs.rs/auto_impl) and for more examples, see [the examples folder](https://github.com/auto-impl-rs/auto_impl/tree/master/examples). # Alternatives -This library implements a fraction of a very broad and complex usecase. It's mostly useful for applications that -define traits for components, and want to be able to abstract over the storage for those traits. If it doesn't offer +This library implements a fraction of a very broad and complex usecase. It's mostly useful for applications that +define traits for components, and want to be able to abstract over the storage for those traits. If it doesn't offer some functionality you need, check out the [`impl-tools`](https://github.com/kas-gui/impl-tools/) project. --- diff --git a/src/gen.rs b/src/gen.rs index 99c776d..62f54af 100644 --- a/src/gen.rs +++ b/src/gen.rs @@ -2,8 +2,8 @@ use proc_macro2::{Span as Span2, TokenStream as TokenStream2, TokenTree as Token use quote::{ToTokens, TokenStreamExt}; use syn::{ punctuated::Punctuated, spanned::Spanned, Attribute, Error, FnArg, GenericParam, Ident, - ItemTrait, Lifetime, Pat, PatIdent, PatType, ReturnType, Signature, Token, TraitBound, - TraitBoundModifier, TraitItem, TraitItemConst, TraitItemFn, TraitItemType, Type, + ItemTrait, Lifetime, Pat, PatIdent, PatType, Receiver, ReceiverKind, ReturnType, Safety, + Signature, Token, TraitBound, TraitItem, TraitItemConst, TraitItemFn, TraitItemType, Type, TypeParamBound, WherePredicate, }; @@ -114,10 +114,8 @@ fn gen_header( // Check if the bound contains `Sized` pred.bounds.iter().any(|b| match b { TypeParamBound::Trait(TraitBound { - modifier: TraitBoundModifier::None, - path, - .. - }) => path.is_ident("Sized"), + modifiers, path, .. + }) if modifiers.require_empty().is_ok() => path.is_ident("Sized"), _ => false, }) } @@ -127,10 +125,13 @@ fn gen_header( // Check if the first parameter is `self` by value. In that // case, we might require `Self` to be `Sized`. - let self_value_param = match m.sig.inputs.first() { - Some(FnArg::Receiver(receiver)) => receiver.reference.is_none(), - _ => false, - }; + let self_value_param = matches!( + m.sig.inputs.first(), + Some(FnArg::Receiver(Receiver { + kind: ReceiverKind::Value, + .. + })) + ); // Check if return type is `Self` let self_value_return = match &m.sig.output { @@ -357,7 +358,7 @@ fn gen_fn_type_for_trait( )); } - if let Some(unsafe_token) = &sig.unsafety { + if let Safety::Unsafe(unsafe_token) = &sig.safety { return Err(Error::new( unsafe_token.span(), format_args!( @@ -662,7 +663,7 @@ fn gen_method_item( let sig = Signature { constness: item.sig.constness, asyncness: item.sig.asyncness, - unsafety: item.sig.unsafety, + safety: item.sig.safety.clone(), abi: item.sig.abi.clone(), fn_token: item.sig.fn_token, ident: item.sig.ident.clone(), @@ -763,15 +764,18 @@ enum SelfType { impl SelfType { fn from_sig(sig: &Signature) -> Self { match sig.inputs.iter().next() { - Some(FnArg::Receiver(r)) => { - if r.reference.is_none() { - SelfType::Value - } else if r.mutability.is_none() { - SelfType::Ref - } else { - SelfType::Mut - } - } + Some(FnArg::Receiver(Receiver { + kind: ReceiverKind::Value, + .. + })) => SelfType::Value, + Some(FnArg::Receiver(Receiver { + kind: ReceiverKind::Reference(_, _, None), + .. + })) => SelfType::Ref, + Some(FnArg::Receiver(Receiver { + kind: ReceiverKind::Reference(_, _, Some(_)), + .. + })) => SelfType::Mut, _ => SelfType::None, } }