11use super :: respan:: respan;
22use proc_macro2:: Span ;
33use std:: mem;
4- use syn:: {
5- parse_quote,
6- punctuated:: Punctuated ,
7- visit_mut:: { self , VisitMut } ,
8- DeriveInput , ExprPath , Path , PathArguments , QSelf , Type , TypePath ,
9- } ;
4+ use syn:: punctuated:: Punctuated ;
5+ use syn:: visit_mut:: { self , VisitMut } ;
6+ use syn:: { parse_quote, DeriveInput , ExprPath , Path , PathArguments , QSelf , Type , TypePath } ;
107
118pub fn replace_receiver ( input : & mut DeriveInput ) {
129 let self_ty = {
@@ -27,18 +24,10 @@ impl ReplaceReceiver<'_> {
2724 }
2825
2926 fn self_to_qself ( & self , qself : & mut Option < QSelf > , path : & mut Path ) {
30- if path. leading_colon . is_some ( ) {
27+ if path. leading_colon . is_some ( ) || path . segments [ 0 ] . ident != "Self" {
3128 return ;
3229 }
3330
34- // Make borrow checker happy
35- {
36- let first = & path. segments [ 0 ] ;
37- if first. ident != "Self" || !first. arguments . is_empty ( ) {
38- return ;
39- }
40- }
41-
4231 if path. segments . len ( ) == 1 {
4332 self . self_to_expr_path ( path) ;
4433 return ;
@@ -47,7 +36,7 @@ impl ReplaceReceiver<'_> {
4736 let span = path. segments [ 0 ] . ident . span ( ) ;
4837 * qself = Some ( QSelf {
4938 lt_token : Token ! [ <] ( span) ,
50- ty : Box :: new ( self . self_ty ( span) . into ( ) ) ,
39+ ty : Box :: new ( Type :: Path ( self . self_ty ( span) ) ) ,
5140 position : 0 ,
5241 as_token : None ,
5342 gt_token : Token ! [ >] ( span) ,
@@ -60,18 +49,6 @@ impl ReplaceReceiver<'_> {
6049 }
6150
6251 fn self_to_expr_path ( & self , path : & mut Path ) {
63- if path. leading_colon . is_some ( ) {
64- return ;
65- }
66-
67- // Make borrow checker happy
68- {
69- let first = & path. segments [ 0 ] ;
70- if first. ident != "Self" || !first. arguments . is_empty ( ) {
71- return ;
72- }
73- }
74-
7552 let self_ty = self . self_ty ( path. segments [ 0 ] . ident . span ( ) ) ;
7653 let variant = mem:: replace ( path, self_ty. path ) ;
7754 for segment in & mut path. segments {
0 commit comments