Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump syn from 1.0 to 2.0 #92

Merged
merged 1 commit into from
Jun 16, 2023
Merged
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ proc-macro = true
[dependencies]
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "1.0", features = ["full", "visit", "visit-mut"] }
syn = { version = "2.0", features = ["full", "visit", "visit-mut"] }
proc-macro-error = "1.0.0"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ some common smart pointers and closures.

# Usage

This library requires Rust 1.37.0 or newer. This library doesn't leave any public API in your code.
This library requires Rust 1.56.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:

Expand Down
19 changes: 7 additions & 12 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use proc_macro_error::{abort, emit_error};
use syn::{
spanned::Spanned,
visit_mut::{visit_item_trait_mut, VisitMut},
Attribute, TraitItem,
Attribute, Meta, TraitItem,
};

use crate::proxy::{parse_types, ProxyType};
Expand All @@ -19,7 +19,7 @@ pub(crate) fn remove_our_attrs(trait_def: &mut syn::ItemTrait) {
fn visit_trait_item_mut(&mut self, item: &mut TraitItem) {
let item_span = item.span();
let (attrs, is_method) = match item {
TraitItem::Method(m) => (&mut m.attrs, true),
TraitItem::Fn(m) => (&mut m.attrs, true),
TraitItem::Const(c) => (&mut c.attrs, false),
TraitItem::Type(t) => (&mut t.attrs, false),
TraitItem::Macro(m) => (&mut m.attrs, false),
Expand Down Expand Up @@ -48,7 +48,7 @@ pub(crate) fn remove_our_attrs(trait_def: &mut syn::ItemTrait) {
/// Checks if the given attribute is "our" attribute. That means that it's path
/// is `auto_impl`.
pub(crate) fn is_our_attr(attr: &Attribute) -> bool {
attr.path.is_ident("auto_impl")
attr.path().is_ident("auto_impl")
}

/// Tries to parse the given attribute as one of our own `auto_impl`
Expand All @@ -61,15 +61,10 @@ pub(crate) fn parse_our_attr(attr: &Attribute) -> Result<OurAttr, ()> {
// Get the body of the attribute (which has to be a ground, because we
// required the syntax `auto_impl(...)` and forbid stuff like
// `auto_impl = ...`).
let tokens = attr.tokens.clone().into_iter().collect::<Vec<_>>();
let body = match &*tokens {
[TokenTree::Group(g)] => g.stream(),
let body = match &attr.meta {
Meta::List(list) => list.tokens.clone(),
_ => {
emit_error!(
attr.tokens.span(),
"expected single group delimited by `()`, found '{:?}'",
tokens,
);
emit_error!(attr.span(), "expected single group delimited by `()`");
return Err(());
}
};
Expand All @@ -84,7 +79,7 @@ pub(crate) fn parse_our_attr(attr: &Attribute) -> Result<OurAttr, ()> {
return Err(());
}
None => {
emit_error!(attr.tokens.span(), "expected ident, found nothing");
emit_error!(attr.span(), "expected ident, found nothing");
return Err(());
}
};
Expand Down
19 changes: 9 additions & 10 deletions src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use quote::{ToTokens, TokenStreamExt};
use syn::{
punctuated::Punctuated, spanned::Spanned, Attribute, FnArg, GenericParam, Ident, ItemTrait,
Lifetime, Pat, PatIdent, PatType, ReturnType, Signature, Token, TraitBound, TraitBoundModifier,
TraitItem, TraitItemConst, TraitItemMethod, TraitItemType, Type, TypeParamBound,
WherePredicate,
TraitItem, TraitItemConst, TraitItemFn, TraitItemType, Type, TypeParamBound, WherePredicate,
};

use crate::{
Expand Down Expand Up @@ -78,7 +77,7 @@ fn gen_header(
.iter()
// Only interested in methods
.filter_map(|item| {
if let TraitItem::Method(m) = item {
if let TraitItem::Fn(m) = item {
Some(m)
} else {
None
Expand Down Expand Up @@ -163,7 +162,7 @@ fn gen_header(
.iter()
// Only interested in methods
.filter_map(|item| {
if let TraitItem::Method(m) = item {
if let TraitItem::Fn(m) = item {
Some(m)
} else {
None
Expand Down Expand Up @@ -204,7 +203,7 @@ fn gen_header(
// `self.field` is always `: 'a` if `Self: 'a`.
match b {
TypeParamBound::Trait(t) => Some(t),
TypeParamBound::Lifetime(_) => None,
_ => None,
}
})
});
Expand Down Expand Up @@ -296,7 +295,7 @@ fn gen_fn_type_for_trait(proxy_type: &ProxyType, trait_def: &ItemTrait) -> Token
// Only traits with exactly one method can be implemented for Fn-traits.
// Associated types and consts are also not allowed.
let method = trait_def.items.get(0).and_then(|item| {
if let TraitItem::Method(m) = item {
if let TraitItem::Fn(m) = item {
Some(m)
} else {
None
Expand Down Expand Up @@ -475,7 +474,7 @@ fn gen_items(
TraitItem::Const(c) => {
gen_const_item(proxy_type, c, trait_def, proxy_ty_param).ok()
}
TraitItem::Method(method) => {
TraitItem::Fn(method) => {
gen_method_item(proxy_type, method, trait_def, proxy_ty_param).ok()
}
TraitItem::Type(ty) => {
Expand Down Expand Up @@ -591,7 +590,7 @@ fn gen_type_item(
/// immediately emitted and `Err(())` is returned.
fn gen_method_item(
proxy_type: &ProxyType,
item: &TraitItemMethod,
item: &TraitItemFn,
trait_def: &ItemTrait,
proxy_ty_param: &Ident,
) -> Result<TokenStream2, ()> {
Expand Down Expand Up @@ -874,7 +873,7 @@ fn get_arg_list<'a>(

/// Checks if the given method has the attribute `#[auto_impl(keep_default_for(...))]`
/// and if it contains the given proxy type.
fn should_keep_default_for(m: &TraitItemMethod, proxy_type: &ProxyType) -> bool {
fn should_keep_default_for(m: &TraitItemFn, proxy_type: &ProxyType) -> bool {
// Get an iterator of just the attribute we are interested in.
let mut it = m
.attrs
Expand Down Expand Up @@ -908,7 +907,7 @@ fn should_keep_default_for(m: &TraitItemMethod, proxy_type: &ProxyType) -> bool
fn filter_attrs(attrs: &[Attribute]) -> Vec<Attribute> {
attrs
.iter()
.filter(|attr| attr.path.is_ident("cfg"))
.filter(|attr| attr.path().is_ident("cfg"))
.cloned()
.collect()
}