Skip to content

Commit

Permalink
Merge pull request #24 from taiki-e/mutability
Browse files Browse the repository at this point in the history
Propagate mutability of `mut self` argument
  • Loading branch information
dtolnay committed Aug 17, 2019
2 parents 2fe612f + d620fe5 commit 371ab62
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,21 +307,25 @@ fn transform_block(
}
}
Some(arg @ FnArg::Receiver(_)) => {
let self_token = match arg {
FnArg::Receiver(Receiver { self_token, .. }) => self_token,
let (self_token, mutability) = match arg {
FnArg::Receiver(Receiver {
self_token,
mutability,
..
}) => (self_token, mutability),
_ => unreachable!(),
};
let under_self = Ident::new("_self", self_token.span);
match context {
Context::Trait { .. } => {
self_bound = Some(parse_quote!(core::marker::Send));
*arg = parse_quote! {
#under_self: AsyncTrait
#mutability #under_self: AsyncTrait
};
}
Context::Impl { receiver, .. } => {
*arg = parse_quote! {
#under_self: #receiver
#mutability #under_self: #receiver
};
}
}
Expand Down
28 changes: 28 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,31 @@ mod issue17 {
}
}
}

// https://github.com/dtolnay/async-trait/issues/23
mod issue23 {
use async_trait::async_trait;

#[async_trait]
pub trait Issue23 {
async fn f(self);

async fn g(mut self)
where
Self: Sized,
{
do_something(&mut self);
}
}

struct S {}

#[async_trait]
impl Issue23 for S {
async fn f(mut self) {
do_something(&mut self);
}
}

fn do_something<T>(_: &mut T) {}
}

0 comments on commit 371ab62

Please sign in to comment.