Skip to content

Commit 6029cbf

Browse files
committed
Preserve self as segment of path
1 parent bb62922 commit 6029cbf

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/receiver.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use proc_macro2::{Group, Span, TokenStream, TokenTree};
22
use std::iter::FromIterator;
33
use syn::visit_mut::{self, VisitMut};
44
use syn::{
5-
Block, ExprPath, Ident, Item, Macro, Pat, PatIdent, PatPath, Receiver, Signature, Token,
5+
Block, ExprPath, Ident, Item, Macro, Pat, PatIdent, PatPath, Path, Receiver, Signature, Token,
66
TypePath,
77
};
88

@@ -139,6 +139,16 @@ impl VisitMut for ReplaceSelf {
139139
self.prepend_underscore_to_self(i);
140140
}
141141

142+
fn visit_path_mut(&mut self, p: &mut Path) {
143+
if p.segments.len() == 1 {
144+
// Replace `self`, but not `self::function`.
145+
self.visit_ident_mut(&mut p.segments[0].ident);
146+
}
147+
for segment in &mut p.segments {
148+
self.visit_path_arguments_mut(&mut segment.arguments);
149+
}
150+
}
151+
142152
fn visit_item_mut(&mut self, i: &mut Item) {
143153
// Visit `macro_rules!` because locally defined macros can refer to
144154
// `self`. Otherwise, do not recurse into nested items.

0 commit comments

Comments
 (0)