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

Add 'async_trait lifetime bound to ImplTrait argument #197

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/expand.rs
Expand Up @@ -10,7 +10,7 @@ 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, TypeParamBound, TypePath, WhereClause,
TraitItem, Type, TypeImplTrait, TypeParamBound, TypePath, WhereClause,
};

impl ToTokens for Item {
Expand Down Expand Up @@ -275,6 +275,13 @@ fn transform_sig(
}) => {}
FnArg::Receiver(arg) => arg.mutability = None,
FnArg::Typed(arg) => {
if let Type::ImplTrait(TypeImplTrait { ref mut bounds, .. }) = *arg.ty {
use syn::spanned::Spanned;
let span = bounds.span();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure which span to use. Is this good choice?

let lifetime = Lifetime::new("'async_trait", span);
bounds.push(TypeParamBound::Lifetime(lifetime));
}

if let Pat::Ident(ident) = &mut *arg.pat {
ident.by_ref = None;
ident.mutability = None;
Expand Down
10 changes: 10 additions & 0 deletions tests/test.rs
Expand Up @@ -1374,6 +1374,16 @@ pub mod issue169 {
pub fn test(_t: &dyn Trait) {}
}

// https://github.com/dtolnay/async-trait/issues/177
pub mod issue177 {
use async_trait::async_trait;

#[async_trait]
trait Foo {
async fn foo(&self, _callback: impl FnMut(&str) + Send) {}
}
}

// https://github.com/dtolnay/async-trait/issues/183
pub mod issue183 {
#![deny(clippy::shadow_same)]
Expand Down