11use crate :: { Method , query:: OptionHandling } ;
22use Method :: { Get , GetMut , Set , With , Without } ;
3- use proc_macro2:: TokenStream as TokenStream2 ;
4- use quote:: quote;
3+ use proc_macro2:: { Span , TokenStream as TokenStream2 } ;
4+ use quote:: { quote, quote_spanned } ;
55use std:: borrow:: Cow ;
66use syn:: { Expr , Ident , Member , Type , Visibility } ;
77
88#[ cfg_attr( feature = "debug" , derive( Debug ) ) ]
99pub ( crate ) struct Resolved < ' a > {
10- pub ( crate ) method : Method ,
11- pub ( crate ) vis : Cow < ' a , Visibility > ,
12- pub ( crate ) fn_ident : Cow < ' a , Ident > ,
13- pub ( crate ) variable_ident : & ' a Member ,
1410 pub ( crate ) argument_ident_and_ty : Option < ( Cow < ' a , Ident > , Cow < ' a , Type > ) > ,
15- pub ( crate ) ty : & ' a Type ,
16- pub ( crate ) doc : Option < Cow < ' a , str > > ,
17- pub ( crate ) get_copy : bool ,
11+ pub ( crate ) assigned_value : Expr ,
1812 pub ( crate ) chainable_set : bool ,
1913 pub ( crate ) deref_type : Option < Cow < ' a , Type > > ,
14+ pub ( crate ) doc : Option < Cow < ' a , str > > ,
15+ pub ( crate ) fn_ident : Cow < ' a , Ident > ,
16+ pub ( crate ) get_copy : bool ,
17+ pub ( crate ) method : Method ,
2018 pub ( crate ) option_borrow_inner : Option < OptionHandling < ' a > > ,
21- pub ( crate ) assigned_value : Expr ,
19+ pub ( crate ) span : Span ,
20+ pub ( crate ) ty : & ' a Type ,
21+ pub ( crate ) variable_ident : & ' a Member ,
22+ pub ( crate ) vis : Cow < ' a , Visibility > ,
2223}
2324
2425impl Resolved < ' _ > {
@@ -32,41 +33,42 @@ impl Resolved<'_> {
3233 get_copy,
3334 deref_type,
3435 option_borrow_inner,
36+ span,
3537 ..
3638 } = self ;
3739 let doc = doc. as_deref ( ) . map ( |d| quote ! ( #[ doc = #d] ) ) ;
3840
3941 if * get_copy {
40- quote ! {
42+ quote_spanned ! { * span=>
4143 #doc
4244 #vis fn #fn_ident( & self ) -> #ty {
4345 self . #variable_ident
4446 }
4547 }
4648 } else if let Some ( oh) = option_borrow_inner {
4749 match oh {
48- OptionHandling :: Deref ( ty) => quote ! {
50+ OptionHandling :: Deref ( ty) => quote_spanned ! { * span=>
4951 #doc
5052 #vis fn #fn_ident( & self ) -> Option <& #ty> {
5153 self . #variable_ident. as_deref( )
5254 }
5355 } ,
54- OptionHandling :: Ref ( ty) => quote ! {
56+ OptionHandling :: Ref ( ty) => quote_spanned ! { * span=>
5557 #doc
5658 #vis fn #fn_ident( & self ) -> Option <& #ty> {
5759 self . #variable_ident. as_ref( )
5860 }
5961 } ,
6062 }
6163 } else if let Some ( deref) = deref_type {
62- quote ! {
64+ quote_spanned ! { * span=>
6365 #doc
6466 #vis fn #fn_ident( & self ) -> & #deref {
6567 & * self . #variable_ident
6668 }
6769 }
6870 } else {
69- quote ! {
71+ quote_spanned ! { * span=>
7072 #doc
7173 #vis fn #fn_ident( & self ) -> & #ty {
7274 & self . #variable_ident
@@ -84,6 +86,7 @@ impl Resolved<'_> {
8486 chainable_set,
8587 assigned_value,
8688 argument_ident_and_ty,
89+ span,
8790 ..
8891 } = self ;
8992
@@ -94,15 +97,15 @@ impl Resolved<'_> {
9497 let doc = doc. as_deref ( ) . map ( |d| quote ! ( #[ doc = #d] ) ) ;
9598
9699 if * chainable_set {
97- quote ! {
100+ quote_spanned ! { * span=>
98101 #doc
99102 #vis fn #fn_ident( & mut self , #argument_ident: #argument_ty) -> & mut Self {
100103 self . #variable_ident = #assigned_value;
101104 self
102105 }
103106 }
104107 } else {
105- quote ! {
108+ quote_spanned ! { * span=>
106109 #doc
107110 #vis fn #fn_ident( & mut self , #argument_ident: #argument_ty) {
108111 self . #variable_ident = #assigned_value;
@@ -120,34 +123,35 @@ impl Resolved<'_> {
120123 doc,
121124 deref_type,
122125 option_borrow_inner,
126+ span,
123127 ..
124128 } = self ;
125129 let doc = doc. as_deref ( ) . map ( |d| quote ! ( #[ doc = #d] ) ) ;
126130
127131 if let Some ( oh) = option_borrow_inner {
128132 match oh {
129- OptionHandling :: Deref ( ty) => quote ! {
133+ OptionHandling :: Deref ( ty) => quote_spanned ! { * span=>
130134 #doc
131135 #vis fn #fn_ident( & mut self ) -> Option <& mut #ty> {
132136 self . #variable_ident. as_deref_mut( )
133137 }
134138 } ,
135- OptionHandling :: Ref ( ty) => quote ! {
139+ OptionHandling :: Ref ( ty) => quote_spanned ! { * span=>
136140 #doc
137141 #vis fn #fn_ident( & mut self ) -> Option <& mut #ty> {
138142 self . #variable_ident. as_mut( )
139143 }
140144 } ,
141145 }
142146 } else if let Some ( deref) = deref_type {
143- quote ! {
147+ quote_spanned ! { * span=>
144148 #doc
145149 #vis fn #fn_ident( & mut self ) -> & mut #deref {
146150 & mut * self . #variable_ident
147151 }
148152 }
149153 } else {
150- quote ! {
154+ quote_spanned ! { * span=>
151155 #doc
152156 #vis fn #fn_ident( & mut self ) -> & mut #ty {
153157 & mut self . #variable_ident
@@ -164,11 +168,12 @@ impl Resolved<'_> {
164168 argument_ident_and_ty,
165169 doc,
166170 assigned_value,
171+ span,
167172 ..
168173 } = self ;
169174 let doc = doc. as_deref ( ) . map ( |d| quote ! ( #[ doc = #d] ) ) ;
170175 if let Some ( ( argument_ident, argument_ty) ) = argument_ident_and_ty {
171- quote ! {
176+ quote_spanned ! { * span=>
172177 #doc
173178 #[ must_use]
174179 #vis fn #fn_ident( mut self , #argument_ident: #argument_ty) -> Self {
@@ -177,7 +182,7 @@ impl Resolved<'_> {
177182 }
178183 }
179184 } else {
180- quote ! {
185+ quote_spanned ! { * span=>
181186 #doc
182187 #[ must_use]
183188 #vis fn #fn_ident( mut self ) -> Self {
@@ -205,11 +210,12 @@ impl Resolved<'_> {
205210 variable_ident,
206211 doc,
207212 assigned_value,
213+ span,
208214 ..
209215 } = self ;
210216 let doc = doc. as_deref ( ) . map ( |d| quote ! ( #[ doc = #d] ) ) ;
211217
212- quote ! {
218+ quote_spanned ! { * span=>
213219 #doc
214220 #[ must_use]
215221 #vis fn #fn_ident( mut self ) -> Self {
0 commit comments