@@ -8,7 +8,6 @@ use syn::{fold::Fold, punctuated::Punctuated, spanned::Spanned, *};
8
8
// All conversions we support. Check references to this type for an idea how to add more.
9
9
enum Conversion < ' a > {
10
10
Into ( & ' a Type ) ,
11
- TryInto ( & ' a Type ) ,
12
11
AsRef ( & ' a Type ) ,
13
12
AsMut ( & ' a Type ) ,
14
13
}
@@ -17,7 +16,6 @@ impl<'a> Conversion<'a> {
17
16
fn target_type ( & self ) -> Type {
18
17
match * self {
19
18
Conversion :: Into ( ty) => ty. clone ( ) ,
20
- Conversion :: TryInto ( ty) => ty. clone ( ) ,
21
19
Conversion :: AsRef ( ty) => parse_quote ! ( & #ty) ,
22
20
Conversion :: AsMut ( ty) => parse_quote ! ( & mut #ty) ,
23
21
}
@@ -26,7 +24,6 @@ impl<'a> Conversion<'a> {
26
24
fn conversion_expr ( & self , i : Ident ) -> Expr {
27
25
match * self {
28
26
Conversion :: Into ( _) => parse_quote ! ( #i. into( ) ) ,
29
- Conversion :: TryInto ( _) => parse_quote ! ( #i. try_into( ) ?) ,
30
27
Conversion :: AsRef ( _) => parse_quote ! ( #i. as_ref( ) ) ,
31
28
Conversion :: AsMut ( _) => parse_quote ! ( #i. as_mut( ) ) ,
32
29
}
@@ -52,8 +49,6 @@ fn parse_bounds(bounds: &Punctuated<TypeParamBound, Token![+]>) -> Option<Conver
52
49
if let GenericArgument :: Type ( ref arg_ty) = gen_args. args . first ( ) . unwrap ( ) {
53
50
if seg. ident == "Into" {
54
51
return Some ( Conversion :: Into ( arg_ty) ) ;
55
- } else if seg. ident == "TryInto" {
56
- return Some ( Conversion :: TryInto ( arg_ty) ) ;
57
52
} else if seg. ident == "AsRef" {
58
53
return Some ( Conversion :: AsRef ( arg_ty) ) ;
59
54
} else if seg. ident == "AsMut" {
@@ -145,7 +140,6 @@ fn convert<'a>(
145
140
let mut argtypes = Punctuated :: new ( ) ;
146
141
let mut conversions = Conversions {
147
142
intos : Vec :: new ( ) ,
148
- try_intos : Vec :: new ( ) ,
149
143
as_refs : Vec :: new ( ) ,
150
144
as_muts : Vec :: new ( ) ,
151
145
} ;
@@ -205,7 +199,6 @@ fn convert<'a>(
205
199
206
200
struct Conversions {
207
201
intos : Vec < Ident > ,
208
- try_intos : Vec < Ident > ,
209
202
as_refs : Vec < Ident > ,
210
203
as_muts : Vec < Ident > ,
211
204
}
@@ -214,7 +207,6 @@ impl Conversions {
214
207
fn add ( & mut self , ident : Ident , conv : Conversion ) {
215
208
match conv {
216
209
Conversion :: Into ( _) => self . intos . push ( ident) ,
217
- Conversion :: TryInto ( _) => self . try_intos . push ( ident) ,
218
210
Conversion :: AsRef ( _) => self . as_refs . push ( ident) ,
219
211
Conversion :: AsMut ( _) => self . as_muts . push ( ident) ,
220
212
}
@@ -238,7 +230,6 @@ impl Fold for Conversions {
238
230
match expr {
239
231
Expr :: MethodCall ( mc) if mc. args . is_empty ( ) => match & * mc. method . to_string ( ) {
240
232
"into" if has_conversion ( & self . intos , & mc. receiver ) => * mc. receiver ,
241
- "try_into" if has_conversion ( & self . try_intos , & mc. receiver ) => * mc. receiver ,
242
233
243
234
"as_ref" if has_conversion ( & self . as_refs , & mc. receiver ) => * mc. receiver ,
244
235
"as_mut" if has_conversion ( & self . as_muts , & mc. receiver ) => * mc. receiver ,
@@ -251,7 +242,6 @@ impl Fold for Conversions {
251
242
..
252
243
} ) if segments. len ( ) == 2 => match ( & * segments[ 0 ] . ident . to_string ( ) , & * segments[ 1 ] . ident . to_string ( ) ) {
253
244
( "Into" , "into" ) if has_conversion ( & self . intos , & call. args [ 0 ] ) => call. args [ 0 ] . clone ( ) ,
254
- ( "TryInto" , "try_into" ) if has_conversion ( & self . try_intos , & call. args [ 0 ] ) => call. args [ 0 ] . clone ( ) ,
255
245
256
246
( "AsRef" , "as_ref" ) if matches ! ( & call. args[ 0 ] , Expr :: Reference ( ExprReference { expr, mutability: None , .. } ) if has_conversion( & self . as_refs, expr) ) => {
257
247
if let Expr :: Reference ( ExprReference { expr, .. } ) = & call. args [ 0 ] {
@@ -272,29 +262,6 @@ impl Fold for Conversions {
272
262
} ,
273
263
_ => syn:: fold:: fold_expr ( self , Expr :: Call ( call) ) ,
274
264
} ,
275
- Expr :: Try ( expr_try) => match & * expr_try. expr {
276
- Expr :: MethodCall ( mc)
277
- if mc. args . is_empty ( )
278
- && mc. method == "try_into"
279
- && has_conversion ( & self . try_intos , & mc. receiver ) =>
280
- {
281
- ( * mc. receiver ) . clone ( )
282
- }
283
- Expr :: Call ( call) if call. args . len ( ) == 1 => match & * call. func {
284
- Expr :: Path ( ExprPath {
285
- path : Path { segments, .. } ,
286
- ..
287
- } ) if segments. len ( ) == 2
288
- && segments[ 0 ] . ident == "TryInto"
289
- && segments[ 1 ] . ident == "try_into"
290
- && has_conversion ( & self . try_intos , & call. args [ 0 ] ) =>
291
- {
292
- call. args [ 0 ] . clone ( )
293
- }
294
- _ => syn:: fold:: fold_expr ( self , Expr :: Try ( expr_try) ) ,
295
- } ,
296
- _ => syn:: fold:: fold_expr ( self , Expr :: Try ( expr_try) ) ,
297
- } ,
298
265
_ => syn:: fold:: fold_expr ( self , expr) ,
299
266
}
300
267
}
0 commit comments