aboutsummaryrefslogtreecommitdiff
path: root/src/receiver.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/receiver.rs')
-rw-r--r--src/receiver.rs23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/receiver.rs b/src/receiver.rs
index 64ab65e..f6ea327 100644
--- a/src/receiver.rs
+++ b/src/receiver.rs
@@ -2,7 +2,7 @@ use proc_macro2::{Group, Span, TokenStream, TokenTree};
use std::iter::FromIterator;
use syn::visit_mut::{self, VisitMut};
use syn::{
- Block, ExprPath, Ident, Item, Macro, Pat, PatIdent, PatPath, Receiver, Signature, Token,
+ Block, ExprPath, Ident, Item, Macro, Pat, PatIdent, PatPath, Path, Receiver, Signature, Token,
TypePath,
};
@@ -139,11 +139,28 @@ impl VisitMut for ReplaceSelf {
self.prepend_underscore_to_self(i);
}
+ fn visit_path_mut(&mut self, p: &mut Path) {
+ if p.segments.len() == 1 {
+ // Replace `self`, but not `self::function`.
+ self.visit_ident_mut(&mut p.segments[0].ident);
+ }
+ for segment in &mut p.segments {
+ self.visit_path_arguments_mut(&mut segment.arguments);
+ }
+ }
+
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)
}
}