diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9daceba..13801c5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: rust: - - 1.68.0 + - 1.71.0 steps: - uses: actions/checkout@v1 - uses: actions-rs/toolchain@v1 @@ -34,7 +34,7 @@ jobs: matrix: rust: - 1.79.0 - # It's useful to test applications of these macros to newer features so using 1.68 for tests doesn't work + # It's useful to test applications of these macros to newer features so using 1.71 for tests doesn't work # This needs to be locked to a specific version of Rust since the exact error messages may change # When switching this Rust version make sure to also update tests to use newer error messages if applicable steps: diff --git a/README.md b/README.md index 31256d7..1e2c866 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Delegating the implementation of traits to enum variants or fields of a struct n code. Ambassador is an attempt to eliminate that boilerplate by deriving the delegating trait implementation via procedural macros. -**The minimum supported Rust version is 1.68.0.** +**The minimum supported Rust version is 1.71.0.** ## Installation diff --git a/ambassador/Cargo.toml b/ambassador/Cargo.toml index 3bb25d5..4ebb01d 100644 --- a/ambassador/Cargo.toml +++ b/ambassador/Cargo.toml @@ -13,7 +13,7 @@ readme = "README.md" proc-macro = true [dependencies] -syn = { version = "2", features = ["full", "extra-traits"] } +syn = { version = "3", features = ["full", "extra-traits"] } quote = "1.0.2" proc-macro2 = "1.0.6" itertools = "0.10.3" diff --git a/ambassador/src/register.rs b/ambassador/src/register.rs index 071c0e6..11a7120 100644 --- a/ambassador/src/register.rs +++ b/ambassador/src/register.rs @@ -5,7 +5,7 @@ use proc_macro2::{Ident, TokenStream, TokenTree}; use quote::{quote, ToTokens, TokenStreamExt}; use syn::spanned::Spanned; use syn::{ - AttrStyle, Attribute, ConstParam, GenericParam, ItemTrait, LifetimeParam, ReturnType, + AttrStyle, Attribute, ConstParam, GenericParam, ItemTrait, LifetimeParam, ReturnType, Safety, TraitItem, TraitItemConst, TraitItemType, TypeParam, Visibility, }; @@ -411,7 +411,7 @@ fn build_method_invocation( } else { quote! { $ret #field.#method_ident::<#(#generics,)*>(#argument_list) #post } }; - if original_method.sig.unsafety.is_some() { + if matches!(original_method.sig.safety, Safety::Unsafe(_)) { method_invocation = quote! ( // SAFETY: All safety obligation are passed along unsafe {#method_invocation} diff --git a/ambassador/src/util.rs b/ambassador/src/util.rs index 74c3400..8af3793 100644 --- a/ambassador/src/util.rs +++ b/ambassador/src/util.rs @@ -3,7 +3,7 @@ use quote::ToTokens; use std::fmt::{Display, Formatter}; use syn::punctuated::Punctuated; use syn::spanned::Spanned; -use syn::{Receiver, Result}; +use syn::{ReceiverKind, Result, Token}; macro_rules! error { ($span:expr, $($rest:expr),*) => {Err(syn::parse::Error::new($span, format_args!($($rest),*)))}; @@ -110,23 +110,20 @@ impl Display for ReceiverType { } } -fn receiver_type_inner(r: &Receiver) -> ReceiverType { - if r.reference.is_none() { - ReceiverType::Owned - } else if r.mutability.is_none() { - ReceiverType::Ref - } else { - ReceiverType::MutRef - } -} - pub(crate) fn receiver_type(sig: &syn::Signature) -> Result { - match sig.receiver() { - Some(r) if r.colon_token.is_none() => Ok(receiver_type_inner(r)), - Some(r) => error!( - r.span(), + let Some(receiver) = sig.receiver() else { + return error!(sig.paren_token.span.open(), "method must have a receiver"); + }; + match receiver.kind { + ReceiverKind::Value => Ok(ReceiverType::Owned), + ReceiverKind::Reference(_, _, None) => Ok(ReceiverType::Ref), + ReceiverKind::Reference(_, _, Some(x)) => { + let _: Token![mut] = x; + Ok(ReceiverType::MutRef) + } + _ => error!( + receiver.span(), "method's receiver type is not supported (must one of self, &self, or &mut self)" ), - None => error!(sig.paren_token.span.open(), "method must have a receiver"), } }