Skip to content

Commit

Permalink
Merge pull request #162 from dtolnay/select
Browse files Browse the repository at this point in the history
Compatibility with tokio::select
  • Loading branch information
dtolnay authored Apr 17, 2021
2 parents fa92d1f + 4db8933 commit 979ecce
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ quote = "1.0"
syn = { version = "1.0.61", features = ["full", "visit-mut"] }

[dev-dependencies]
futures = "0.3"
rustversion = "1.0"
tracing = "0.1.14"
tracing-attributes = "0.1.14"
Expand Down
11 changes: 9 additions & 2 deletions src/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,16 @@ impl VisitMut for ReplaceSelf {

fn visit_item_mut(&mut self, i: &mut Item) {
// Visit `macro_rules!` because locally defined macros can refer to
// `self`. Otherwise, do not recurse into nested items.
// `self`.
//
// Visit `futures::select` and similar select macros, which commonly
// appear syntactically like an item despite expanding to an expression.
//
// Otherwise, do not recurse into nested items.
if let Item::Macro(i) = i {
if i.mac.path.is_ident("macro_rules") {
if i.mac.path.is_ident("macro_rules")
|| i.mac.path.segments.last().unwrap().ident == "select"
{
self.visit_macro_mut(&mut i.mac)
}
}
Expand Down
26 changes: 26 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1335,3 +1335,29 @@ pub mod issue158 {
}
}
}

// https://github.com/dtolnay/async-trait/issues/161
#[allow(clippy::mut_mut)]
pub mod issue161 {
use async_trait::async_trait;
use futures::future::FutureExt;
use std::sync::Arc;

#[async_trait]
pub trait Trait {
async fn f(self: Arc<Self>);
}

pub struct MyStruct(bool);

#[async_trait]
impl Trait for MyStruct {
async fn f(self: Arc<Self>) {
futures::select! {
_ = async {
println!("{}", self.0);
}.fuse() => {}
}
}
}
}

0 comments on commit 979ecce

Please sign in to comment.