diff --git a/Cargo.toml b/Cargo.toml index 3f6d20b..6e92721 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/README.md b/README.md index 1695883..492b3d0 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/src/attr.rs b/src/attr.rs index 0c6bc53..4be0eec 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -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}; @@ -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), @@ -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` @@ -61,15 +61,10 @@ pub(crate) fn parse_our_attr(attr: &Attribute) -> Result { // 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::>(); - 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(()); } }; @@ -84,7 +79,7 @@ pub(crate) fn parse_our_attr(attr: &Attribute) -> Result { return Err(()); } None => { - emit_error!(attr.tokens.span(), "expected ident, found nothing"); + emit_error!(attr.span(), "expected ident, found nothing"); return Err(()); } }; diff --git a/src/gen.rs b/src/gen.rs index e382f64..fef0721 100644 --- a/src/gen.rs +++ b/src/gen.rs @@ -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::{ @@ -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 @@ -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 @@ -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, } }) }); @@ -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 @@ -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) => { @@ -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 { @@ -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 @@ -908,7 +907,7 @@ fn should_keep_default_for(m: &TraitItemMethod, proxy_type: &ProxyType) -> bool fn filter_attrs(attrs: &[Attribute]) -> Vec { attrs .iter() - .filter(|attr| attr.path.is_ident("cfg")) + .filter(|attr| attr.path().is_ident("cfg")) .cloned() .collect() }