Skip to content

Commit

Permalink
Match specifically Arc<Self>, not any other Arc
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Nov 29, 2022
1 parent d1a4a23 commit 066f06e
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use std::mem;
use syn::punctuated::Punctuated;
use syn::visit_mut::{self, VisitMut};
use syn::{
parse_quote, parse_quote_spanned, Attribute, Block, FnArg, GenericParam, Generics, Ident,
ImplItem, Lifetime, LifetimeDef, Pat, PatIdent, Receiver, ReturnType, Signature, Stmt, Token,
TraitItem, Type, TypePath, WhereClause,
parse_quote, parse_quote_spanned, Attribute, Block, FnArg, GenericArgument, GenericParam,
Generics, Ident, ImplItem, Lifetime, LifetimeDef, Pat, PatIdent, PathArguments, Receiver,
ReturnType, Signature, Stmt, Token, TraitItem, Type, TypePath, WhereClause,
};

impl ToTokens for Item {
Expand Down Expand Up @@ -242,8 +242,27 @@ fn transform_sig(
} =>
{
match arg.ty.as_ref() {
// self: &Self
Type::Reference(ty) if ty.mutability.is_none() => &[InferredBound::Sync],
Type::Path(ty) if ty.path.segments.last().unwrap().ident == "Arc" => {
// self: Arc<Self>
Type::Path(ty)
if {
let segment = ty.path.segments.last().unwrap();
segment.ident == "Arc"
&& match &segment.arguments {
PathArguments::AngleBracketed(arguments) => {
arguments.args.len() == 1
&& match &arguments.args[0] {
GenericArgument::Type(Type::Path(arg)) => {
arg.path.is_ident("Self")
}
_ => false,
}
}
_ => false,
}
} =>
{
&[InferredBound::Sync, InferredBound::Send]
}
_ => &[InferredBound::Send],
Expand Down

0 comments on commit 066f06e

Please sign in to comment.