Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
rust:
- 1.68.0
- 1.71.0
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ambassador/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions ambassador/src/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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}
Expand Down
29 changes: 13 additions & 16 deletions ambassador/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),*)))};
Expand Down Expand Up @@ -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<ReceiverType> {
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"),
}
}
Loading